
Hello, Have modified your example a bit and tried it out on my linux machine (fedora core 3) and the performance seems to be even worse. I use boost 1.32 (1.32.0-5.fc3) and gcc-Version 3.4.4 20050721 (Red Hat 3.4.4-2) on a Intel Pentium 4 CPU 3.00GHz with 2048 kb cache. # When I compile it with optimization I typically get these values:
g++ -O3 -o signal_test main.cc -lboost_signals ./signal_test
Iterations: 10000000 SIGNALS: sec.: 56 / usec.: 295077 BOOST::FUNCTION: sec.: 0 / usec.: 176564 FUNCTION POINTER: sec.: 0 / usec.: 41502 # Without optimization it looks like this:
g++ -o signal_test main.cc -lboost_signals
./signal_test Iterations: 10000000 SIGNALS: sec.: 70 / usec.: 26187 BOOST::FUNCTION: sec.: 0 / usec.: 244619 FUNCTION POINTER: sec.: 0 / usec.: 53574 And I always thought signals ought to be fast :-). Here is the code I used for the test: ------------------------------- snip ------------------------------- #include <boost/function.hpp> #include <boost/signals.hpp> #include <iostream> #include <sys/time.h> using namespace std; void do_nothing() { } int main() { unsigned int counter = 0; const unsigned int MAX_ITERATION = 10000000; struct timeval t_start; struct timeval t_end; boost::function<void (void)> f = do_nothing; void (*pf)(void) = &do_nothing; boost::signal<void (void)> s; s.connect(&do_nothing); cerr << "\nIterations: " << MAX_ITERATION << endl << endl; cerr << "SIGNALS: "; gettimeofday( &t_start, 0 ); for( counter = 0; counter < MAX_ITERATION; ++counter ) { s(); } gettimeofday( &t_end, 0 ); cerr << "sec.: " << ( t_end.tv_sec - t_start.tv_sec ) << " / usec.: " << ( t_end.tv_usec - t_start.tv_usec ) << endl; cerr << "BOOST::FUNCTION: "; gettimeofday( &t_start, 0 ); for( counter = 0; counter < MAX_ITERATION; ++counter ) { f(); } gettimeofday( &t_end, 0 ); cerr << "sec.: " << ( t_end.tv_sec - t_start.tv_sec ) << " / usec.: " << ( t_end.tv_usec - t_start.tv_usec ) << endl; cerr << "FUNCTION POINTER: "; gettimeofday( &t_start, 0 ); for( counter = 0; counter < MAX_ITERATION; ++counter ) { pf(); } gettimeofday( &t_end, 0 ); cerr << "sec.: " << ( t_end.tv_sec - t_start.tv_sec ) << " / usec.: " << ( t_end.tv_usec - t_start.tv_usec ) << endl; return 0; } ------------------------------- snip ------------------------------- regards, Arno