Boost logo

Boost Users :

Subject: [Boost-users] boost::signal performance in boost 1.36 and VS2005
From: Hansi (hansipet_at_[hidden])
Date: 2008-09-16 15:54:31


Hello,

I have made now a small test and I don't know if I make something wrong.
I have the following performance comparsion between a boost::function
and a boost::signal.
Okay, I know that boost::signal has a lot of more functionality and for
that it is for sure slower than boost::function. But 100times slower?

May be I do something wrong?
On my pc I have for boost::function a runtime of 728ms and for
boost::signals a runtime of 64128ms
There is one slot used for signals.

Can anyone give me some hint what I do wrong?

my test program was:

class TestBind
{
public:
        
        int counter;

        void OnEventReceived(char b)
        {
                counter++;
        }
};

class TestSignal
{
public:
        
        int counter;

        void OnEventReceived(char b)
        {
                counter++;
        }
};

int _tmain(int argc, _TCHAR* argv[])
{
        TestBind testBind;
        PerformanceCounter timer;
        boost::function<void (char)> f =
boost::bind(&TestBind::OnEventReceived,&testBind,_1);
        
        for(int i = 0; i < 100000000; i++)
        {
                f('a');
        }

        TestSignal testSignal;
        boost::signal<void (char)> sig;
        
        sig.connect(boost::bind(&TestSignal::OnEventReceived,&testSignal,_1));;

                for(int i = 0; i < 100000000; i++)
        {
                sig('a');
        }
        
}

Best regards
Hansjörg


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net