2009/7/22 Frank Mori Hess <frank.hess@nist.gov>
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Wednesday 22 July 2009, Sajjan Kalle wrote:
> I did a search on the mailing list and found a
> discussion from 2005 on the performance of the library, results at that
> time showed a vector with boost::function being about 100 times faster than
> boost::signals.

You're going to have to provide a link.
 
Old one http://aspn.activestate.com/ASPN/Mail/Message/boost/2239573 .
Found a more recent http://archives.free.net.ph/message/20080916.195431.40753f57.fr.html .
 
I used the following:

void

foo( )

{

}

int

main()

{

Altus::Timer tim;

std::vector< boost::function< void ( void ) > > manualSignal;

boost::signal< void ( void ) > boostSignal;

for( unsigned int i = 0; i < 1000; ++i )

{

manualSignal.push_back( &foo );

boostSignal.connect( &foo );

}

double now = tim.GetTimeInMS();

for( unsigned int i = 0; i < 1000; ++i )

{

for( unsigned int j = 0; j < 1000; ++j )

manualSignal[ i ]( );

}

double diff = tim.GetTimeInMS() - now;

std::cout << "took " << diff << " ms" << std::endl;

now = tim.GetTimeInMS();

for( unsigned int i = 0; i < 1000; ++i )

{

boostSignal( );

}

diff = tim.GetTimeInMS() - now;

std::cout << "took " << diff << " ms" << std::endl;

}

Which gives me the results ~5.2 ms for the vector variant and ~411 ms for the boost::signals variant. However, disabling checked iterators gives me ~3.8 ms for the vector variant and ~180 ms for boost::signals, so it seems to make a world of difference for the overhead associated with slots.
 
We have more real world like scenario with our code base in which boost::signals seems to perform even worse, can't provide the entire code base however. I'd think this has to do with the fact that the slots becomes more fragmented in memory due to the underlying container when used in the wild. That's merely speculation however.