#include //#include "FastDelegate.h" #include #include #include #include class Test { public: void func(int param) { int i=0; i=param+1; } }; //using namespace fastdelegate; template class smallbinder { public: smallbinder(F Class::*pm, Class* ptr) : pm(pm), ptr(ptr) { } template void operator()(T1& a1) const { (ptr->*pm)(a1); } private: F Class::*pm; Class* ptr; }; template inline smallbinder smallbind(F Class::*pm, Class* ptr) { return smallbinder(pm, ptr); } int main(void) { //typedef FastDelegate1 IntMyDelegate; Test test; #if 0 boost::timer t; for(int f=0;f<10000000;f++) { IntMyDelegate newdeleg; newdeleg = MakeDelegate(&test, &Test::func); newdeleg(f); } printf("Time elapsed for FastDelegate: %f (sec)\n",t.elapsed()); #endif 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 t; for(int f=0;f<100000000;f++) { boost::function func=smallbind(&Test::func,&test); func(f); } printf("Time elapsed for smallbind+function (size=%d): %f (sec)\n", sizeof(smallbind(&Test::func, &test)), t.elapsed()); } boost::timer t3; for(int f=0;f<100000000;f++) { boost::function func=boost::bind(&Test::func,&test,_1); func(f); } printf("Time elapsed for bind+function (size=%d): %f (sec)\n", sizeof(boost::bind(&Test::func,&test,_1)), t3.elapsed()); boost::timer t4; boost::function 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()); boost::timer t5; for(int f=0;f<100000000;f++) { boost::function > func=boost::bind(&Test::func,&test,_1); func(f); } printf("Time elapsed for bind+function+pool: %f (sec)\n",t5.elapsed()); boost::timer t6; for(int f=0;f<100000000;f++) { boost::function > func=boost::bind(&Test::func,&test,_1); func(f); } printf("Time elapsed for bind+function+fastpool: %f (sec)\n",t6.elapsed()); return 0; }