benchmark.cpp
Go to the documentation of this file.
00001 
00002 #include <topic_tools/shape_shifter.h>
00003 #include <boost/algorithm/string.hpp>
00004 #include <boost/serialization/serialization.hpp>
00005 #include <boost/utility/string_ref.hpp>
00006 #include <geometry_msgs/Pose.h>
00007 #include <sensor_msgs/JointState.h>
00008 #include <sstream>
00009 #include <iostream>
00010 #include <chrono>
00011 #include <ros_type_introspection/renamer.hpp>
00012 #include <benchmark/benchmark.h>
00013 
00014 using namespace ros::message_traits;
00015 using namespace RosIntrospection;
00016 
00017 
00018 static std::vector<SubstitutionRule> Rules()
00019 {
00020   std::vector<SubstitutionRule> rules;
00021 
00022   /*
00023     rules.push_back( SubstitutionRule( "transforms.#.transform",
00024                                        "transforms.#.header.frame_id",
00025                                        "transforms.#" ));
00026 
00027     rules.push_back( SubstitutionRule( "transforms.#.header",
00028                                        "transforms.#.header.frame_id",
00029                                        "transforms.#.header" ));*/
00030 
00031   rules.push_back( SubstitutionRule( "position.#", "name.#", "@.position" ));
00032   rules.push_back( SubstitutionRule( "velocity.#", "name.#", "@.velocity" ));
00033   rules.push_back( SubstitutionRule( "effort.#",   "name.#", "@.effort"   ));
00034   return rules;
00035 }
00036 
00037 
00038 static void BM_Joint(benchmark::State& state) {
00039 
00040   ROSTypeList type_map =  buildROSTypeMapFromDefinition(
00041         DataType<sensor_msgs::JointState >::value(),
00042         Definition<sensor_msgs::JointState>::value() );
00043 
00044   sensor_msgs::JointState js_msg;
00045 
00046   js_msg.name.resize(6);
00047   js_msg.position.resize(6);
00048   js_msg.velocity.resize(6);
00049   js_msg.effort.resize(6);
00050 
00051   const char* suffix[6] = { "_A", "_B", "_C", "_D" , "_E", "_F"};
00052 
00053   for (int i=0; i< js_msg.name.size() ; i++)
00054   {
00055     js_msg.header.seq = 100+i;
00056     js_msg.header.stamp.sec = 1234;
00057     js_msg.header.frame_id = std::string("frame").append(suffix[i]);
00058 
00059     js_msg.name[i] = std::string("child").append(suffix[i]);
00060     js_msg.position[i]  = 10 +i;
00061     js_msg.velocity[i]  = 20 +i;
00062     js_msg.effort[i]    = 30 +i;
00063   }
00064 
00065   std::vector<uint8_t> buffer(64*1024);
00066   ros::serialization::OStream stream(buffer.data(), buffer.size());
00067   ros::serialization::Serializer<sensor_msgs::JointState>::write(stream, js_msg);
00068   ROSType main_type (DataType<sensor_msgs::JointState>::value());
00069 
00070   auto rules = Rules();
00071 
00072   ROSTypeFlat flat_container;
00073   RenamedValues renamed;
00074 
00075   while (state.KeepRunning())
00076   {
00077     buildRosFlatType(type_map, main_type, "joint_state", buffer.data(), &flat_container, 100);
00078     applyNameTransform( rules , flat_container, renamed );
00079   }
00080 }
00081 
00082 BENCHMARK(BM_Joint);
00083 
00084 BENCHMARK_MAIN();


ros_type_introspection
Author(s): Davide Faconti
autogenerated on Sun Oct 1 2017 02:54:53