Skip to content

Commit 9476c08

Browse files
committed
benchmark: Rearrange.
1 parent 6e34e42 commit 9476c08

File tree

1 file changed

+45
-19
lines changed

1 file changed

+45
-19
lines changed

tests/benchmark.cc

Lines changed: 45 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,16 @@ int foo::bar(int a)
2020
return b;
2121
}
2222

23-
int main()
23+
void test_slot_call()
2424
{
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;
3026
sigc::signal<int,int>::iterator it;
3127

32-
3328
// slot benchmark ...
3429

35-
slot = sigc::mem_fun(&foobar1, &foo::bar);
30+
sigc::slot<int,int> slot = sigc::mem_fun(&foobar1, &foo::bar);
3631

32+
Glib::TimeVal t1, t2;
3733
t1.assign_current_time();
3834

3935
for (int i=0; i < 5000; ++i)
@@ -43,10 +39,13 @@ int main()
4339
t2.subtract(t1);
4440

4541
std::cout << "elapsed time for calling a slot 5000 times: " << t2.tv_sec << "s " << t2.tv_usec << "us" << std::endl;
42+
}
4643

44+
void test_signal_emit()
45+
{
46+
sigc::signal<int,int> emitter;
4747

48-
// emission benchmark (zero slots) ...
49-
48+
Glib::TimeVal t1, t2;
5049
t1.assign_current_time();
5150

5251
for (int i=0; i < 1000; ++i)
@@ -56,12 +55,15 @@ int main()
5655
t2.subtract(t1);
5756

5857
std::cout << "elapsed time for 1000 emissions (0 slots): " << t2.tv_sec << "s " << t2.tv_usec << "us" << std::endl;
58+
}
5959

60-
61-
// emission benchmark (one slot) ...
62-
60+
void test_connected_signal_emit()
61+
{
62+
foo foobar1;
63+
sigc::signal<int,int> emitter;
6364
emitter.connect(mem_fun(&foobar1, &foo::bar));
6465

66+
Glib::TimeVal t1, t2;
6567
t1.assign_current_time();
6668

6769
for (int i=0; i < 1000; ++i)
@@ -71,15 +73,19 @@ int main()
7173
t2.subtract(t1);
7274

7375
std::cout << "elapsed time for 1000 emissions (1 slot): " << t2.tv_sec << "s " << t2.tv_usec << "us" << std::endl;
76+
}
7477

78+
void test_connected_multiple_signal_emit()
79+
{
80+
foo foobar1, foobar2, foobar3, foobar4, foobar5;
7581

76-
// emission benchmark (five slot) ...
77-
82+
sigc::signal<int,int> emitter;
7883
emitter.connect(mem_fun(&foobar2, &foo::bar));
7984
emitter.connect(mem_fun(&foobar3, &foo::bar));
8085
emitter.connect(mem_fun(&foobar4, &foo::bar));
8186
emitter.connect(mem_fun(&foobar5, &foo::bar));
8287

88+
Glib::TimeVal t1, t2;
8389
t1.assign_current_time();
8490

8591
for (int i=0; i < 1000; ++i)
@@ -89,12 +95,15 @@ int main()
8995
t2.subtract(t1);
9096

9197
std::cout << "elapsed time for 1000 emissions (5 slots): " << t2.tv_sec << "s " << t2.tv_usec << "us" << std::endl;
98+
}
9299

100+
void test_connect_disconnect()
101+
{
102+
foo foobar1;
103+
sigc::signal<int, int> emitter;
104+
sigc::signal<int, int>::iterator it;
93105

94-
// connection / disconnection benchmark ...
95-
96-
emitter.clear();
97-
106+
Glib::TimeVal t1, t2;
98107
t1.assign_current_time();
99108

100109
for (int i=0; i < 1000; ++i)
@@ -107,5 +116,22 @@ int main()
107116
t2.subtract(t1);
108117

109118
std::cout << "elapsed time for 1000 connections/disconnections: " << t2.tv_sec << "s " << t2.tv_usec << "us" << std::endl;
119+
}
110120

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();
111137
}

0 commit comments

Comments
 (0)