@@ -20,20 +20,16 @@ int foo::bar(int a)
20
20
return b;
21
21
}
22
22
23
- int main ()
23
+ void test_slot_call ()
24
24
{
25
- Glib::TimeVal t1, t2;
26
-
27
- foo foobar1, foobar2, foobar3, foobar4, foobar5;
28
- sigc::slot<int ,int > slot;
29
- sigc::signal<int ,int > emitter;
25
+ foo foobar1;
30
26
sigc::signal<int ,int >::iterator it;
31
27
32
-
33
28
// slot benchmark ...
34
29
35
- slot = sigc::mem_fun (&foobar1, &foo::bar);
30
+ sigc::slot< int , int > slot = sigc::mem_fun (&foobar1, &foo::bar);
36
31
32
+ Glib::TimeVal t1, t2;
37
33
t1.assign_current_time ();
38
34
39
35
for (int i=0 ; i < 5000 ; ++i)
@@ -43,10 +39,13 @@ int main()
43
39
t2.subtract (t1);
44
40
45
41
std::cout << " elapsed time for calling a slot 5000 times: " << t2.tv_sec << " s " << t2.tv_usec << " us" << std::endl;
42
+ }
46
43
44
+ void test_signal_emit ()
45
+ {
46
+ sigc::signal<int ,int > emitter;
47
47
48
- // emission benchmark (zero slots) ...
49
-
48
+ Glib::TimeVal t1, t2;
50
49
t1.assign_current_time ();
51
50
52
51
for (int i=0 ; i < 1000 ; ++i)
@@ -56,12 +55,15 @@ int main()
56
55
t2.subtract (t1);
57
56
58
57
std::cout << " elapsed time for 1000 emissions (0 slots): " << t2.tv_sec << " s " << t2.tv_usec << " us" << std::endl;
58
+ }
59
59
60
-
61
- // emission benchmark (one slot) ...
62
-
60
+ void test_connected_signal_emit ()
61
+ {
62
+ foo foobar1;
63
+ sigc::signal<int ,int > emitter;
63
64
emitter.connect (mem_fun (&foobar1, &foo::bar));
64
65
66
+ Glib::TimeVal t1, t2;
65
67
t1.assign_current_time ();
66
68
67
69
for (int i=0 ; i < 1000 ; ++i)
@@ -71,15 +73,19 @@ int main()
71
73
t2.subtract (t1);
72
74
73
75
std::cout << " elapsed time for 1000 emissions (1 slot): " << t2.tv_sec << " s " << t2.tv_usec << " us" << std::endl;
76
+ }
74
77
78
+ void test_connected_multiple_signal_emit ()
79
+ {
80
+ foo foobar1, foobar2, foobar3, foobar4, foobar5;
75
81
76
- // emission benchmark (five slot) ...
77
-
82
+ sigc::signal<int ,int > emitter;
78
83
emitter.connect (mem_fun (&foobar2, &foo::bar));
79
84
emitter.connect (mem_fun (&foobar3, &foo::bar));
80
85
emitter.connect (mem_fun (&foobar4, &foo::bar));
81
86
emitter.connect (mem_fun (&foobar5, &foo::bar));
82
87
88
+ Glib::TimeVal t1, t2;
83
89
t1.assign_current_time ();
84
90
85
91
for (int i=0 ; i < 1000 ; ++i)
@@ -89,12 +95,15 @@ int main()
89
95
t2.subtract (t1);
90
96
91
97
std::cout << " elapsed time for 1000 emissions (5 slots): " << t2.tv_sec << " s " << t2.tv_usec << " us" << std::endl;
98
+ }
92
99
100
+ void test_connect_disconnect ()
101
+ {
102
+ foo foobar1;
103
+ sigc::signal<int , int > emitter;
104
+ sigc::signal<int , int >::iterator it;
93
105
94
- // connection / disconnection benchmark ...
95
-
96
- emitter.clear ();
97
-
106
+ Glib::TimeVal t1, t2;
98
107
t1.assign_current_time ();
99
108
100
109
for (int i=0 ; i < 1000 ; ++i)
@@ -107,5 +116,22 @@ int main()
107
116
t2.subtract (t1);
108
117
109
118
std::cout << " elapsed time for 1000 connections/disconnections: " << t2.tv_sec << " s " << t2.tv_usec << " us" << std::endl;
119
+ }
110
120
121
+ int main ()
122
+ {
123
+ // slot benchmark ...
124
+ test_slot_call ();
125
+
126
+ // emission benchmark (zero slots) ...
127
+ test_signal_emit ();
128
+
129
+ // emission benchmark (one slot) ...
130
+ test_connected_signal_emit ();
131
+
132
+ // emission benchmark (five slot) ...
133
+ test_connected_multiple_signal_emit ();
134
+
135
+ // connection / disconnection benchmark ...
136
+ test_connect_disconnect ();
111
137
}
0 commit comments