1 /* Copyright 2003 - 2016, The libsigc++ Development Team
2 * Assigned to public domain. Use as you wish without restriction.
6 #include <sigc++/signal.h>
7 #include <sigc++/functors/mem_fun.h>
8 #include <boost/timer/timer.hpp>
10 const int COUNT = 10000000;
12 struct foo : public sigc::trackable
28 sigc::signal<int(int)>::iterator it;
32 sigc::slot<int(int)> slot = sigc::mem_fun(foobar1, &foo::bar);
34 std::cout << "elapsed time for calling a slot " << COUNT << " times:" << std::endl;
35 boost::timer::auto_cpu_timer timer;
37 for (int i=0; i < COUNT; ++i)
41 void test_signal_emit()
43 sigc::signal<int(int)> emitter;
45 std::cout << "elapsed time for " << COUNT << " emissions (0 slots):" << std::endl;
46 boost::timer::auto_cpu_timer timer;
48 for (int i=0; i < COUNT; ++i)
52 void test_connected_signal_emit()
55 sigc::signal<int(int)> emitter;
56 emitter.connect(mem_fun(foobar1, &foo::bar));
58 std::cout << "elapsed time for " << COUNT << " emissions (1 slot):" << std::endl;
59 boost::timer::auto_cpu_timer timer;
61 for (int i=0; i < COUNT; ++i)
65 void test_connected_multiple_signal_emit()
67 foo foobar1, foobar2, foobar3, foobar4, foobar5;
69 sigc::signal<int(int)> emitter;
70 emitter.connect(mem_fun(foobar2, &foo::bar));
71 emitter.connect(mem_fun(foobar3, &foo::bar));
72 emitter.connect(mem_fun(foobar4, &foo::bar));
73 emitter.connect(mem_fun(foobar5, &foo::bar));
75 std::cout << "elapsed time for " << COUNT << " emissions (5 slots):" << std::endl;
76 boost::timer::auto_cpu_timer timer;;
78 for (int i=0; i < COUNT; ++i)
82 void test_connect_disconnect()
85 sigc::signal<int(int)> emitter;
86 sigc::signal<int(int)>::iterator it;
88 std::cout << "elapsed time for " << COUNT << " connections/disconnections:" << std::endl;
89 boost::timer::auto_cpu_timer timer;
91 for (int i=0; i < COUNT; ++i)
93 it = emitter.connect(mem_fun(foobar1, &foo::bar));
100 // slot benchmark ...
103 // emission benchmark (zero slots) ...
106 // emission benchmark (one slot) ...
107 test_connected_signal_emit();
109 // emission benchmark (five slot) ...
110 test_connected_multiple_signal_emit();
112 // connection / disconnection benchmark ...
113 test_connect_disconnect();