|
Boost : |
From: Alex Besogonov (cyberax_at_[hidden])
Date: 2005-12-28 04:15:26
Vladimir Prus wrote:
>> I don't have any problem with boost::function speed of invocations
>> (though FastDelegate is two times faster).
> I see. Still, would be nice to see specific numbers.
I've attached a test program (you need FastDelegate from
http://www.codeproject.com/cpp/FastDelegate.asp to compile it).
Results:
=========================
C:\temp\delegates>gcc -O3 -funroll-loops -fomit-frame-pointer test.cpp
-Ic:/tools/boost -lstdc++
C:\temp\delegates>a.exe
Time elapsed for FastDelegate: 1.191000 (sec)
Time elapsed for simple bind: 0.010000 (sec)
Time elapsed for bind+function: 33.118000 (sec)
Time elapsed for pure function invocation: 3.705000 (sec)
=========================
(GCC 4.1.0 was used)
You can see that boost::function + boost::bind is an order of magnitude
slower than FastDelegate. Even a mere invocation of a boost::function is
slower than complete bind+invoke for FastDelegate.
-- With respect, Alex Besogonov (cyberax_at_[hidden])
#include <stdio.h>
#include "FastDelegate.h"
#include <boost/timer.hpp>
#include <boost/bind.hpp>
#include <boost/function.hpp>
class Test
{
public:
void func(int param)
{
int i=0;
i=param+1;
}
};
using namespace fastdelegate;
int main(void)
{
typedef FastDelegate1<int> IntMyDelegate;
Test test;
boost::timer t;
for(int f=0;f<100000000;f++)
{
IntMyDelegate newdeleg;
newdeleg = MakeDelegate(&test, &Test::func);
newdeleg(f);
}
printf("Time elapsed for FastDelegate: %f (sec)\n",t.elapsed());
boost::timer t2;
for(int f=0;f<100000000;f++)
{
boost::bind(&Test::func,&test,_1)(f);
}
printf("Time elapsed for simple bind: %f (sec)\n",t2.elapsed());
boost::timer t3;
for(int f=0;f<100000000;f++)
{
boost::function<void(int)> func=boost::bind(&Test::func,&test,_1);
func(f);
}
printf("Time elapsed for bind+function: %f (sec)\n",t3.elapsed());
boost::timer t4;
boost::function<void(int)> func=boost::bind(&Test::func,&test,_1);
for(int f=0;f<100000000;f++)
{
func(f);
}
printf("Time elapsed for pure function invocation: %f (sec)\n",t4.elapsed());
return 0;
}
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk