Skip to content

Commit 605019c

Browse files
committed
benchmark: Make the 1000 a constant, so we can change it.
1 parent 9476c08 commit 605019c

File tree

1 file changed

+13
-16
lines changed

1 file changed

+13
-16
lines changed

tests/benchmark.cc

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#include <sigc++/functors/mem_fun.h>
88
#include <glibmm/timeval.h>
99

10+
const int COUNT = 1000;
11+
1012
struct foo : public sigc::trackable
1113
{
1214
int bar(int a);
@@ -29,16 +31,11 @@ void test_slot_call()
2931

3032
sigc::slot<int,int> slot = sigc::mem_fun(&foobar1, &foo::bar);
3133

32-
Glib::TimeVal t1, t2;
33-
t1.assign_current_time();
34+
std::cout << "elapsed time for calling a slot " << COUNT << " times:" << std::endl;.
35+
boost::timer::auto_cpu_timer timer;
3436

35-
for (int i=0; i < 5000; ++i)
37+
for (int i=0; i < COUNT; ++i)
3638
slot(i);
37-
38-
t2.assign_current_time();
39-
t2.subtract(t1);
40-
41-
std::cout << "elapsed time for calling a slot 5000 times: " << t2.tv_sec << "s " << t2.tv_usec << "us" << std::endl;
4239
}
4340

4441
void test_signal_emit()
@@ -48,13 +45,13 @@ void test_signal_emit()
4845
Glib::TimeVal t1, t2;
4946
t1.assign_current_time();
5047

51-
for (int i=0; i < 1000; ++i)
48+
for (int i=0; i < COUNT; ++i)
5249
emitter(i);
5350

5451
t2.assign_current_time();
5552
t2.subtract(t1);
5653

57-
std::cout << "elapsed time for 1000 emissions (0 slots): " << t2.tv_sec << "s " << t2.tv_usec << "us" << std::endl;
54+
std::cout << "elapsed time for " << COUNT << " emissions (0 slots): " << t2.tv_sec << "s " << t2.tv_usec << "us" << std::endl;
5855
}
5956

6057
void test_connected_signal_emit()
@@ -66,13 +63,13 @@ void test_connected_signal_emit()
6663
Glib::TimeVal t1, t2;
6764
t1.assign_current_time();
6865

69-
for (int i=0; i < 1000; ++i)
66+
for (int i=0; i < COUNT; ++i)
7067
emitter(i);
7168

7269
t2.assign_current_time();
7370
t2.subtract(t1);
7471

75-
std::cout << "elapsed time for 1000 emissions (1 slot): " << t2.tv_sec << "s " << t2.tv_usec << "us" << std::endl;
72+
std::cout << "elapsed time for " << COUNT << " emissions (1 slot): " << t2.tv_sec << "s " << t2.tv_usec << "us" << std::endl;
7673
}
7774

7875
void test_connected_multiple_signal_emit()
@@ -88,13 +85,13 @@ void test_connected_multiple_signal_emit()
8885
Glib::TimeVal t1, t2;
8986
t1.assign_current_time();
9087

91-
for (int i=0; i < 1000; ++i)
88+
for (int i=0; i < COUNT; ++i)
9289
emitter(i);
9390

9491
t2.assign_current_time();
9592
t2.subtract(t1);
9693

97-
std::cout << "elapsed time for 1000 emissions (5 slots): " << t2.tv_sec << "s " << t2.tv_usec << "us" << std::endl;
94+
std::cout << "elapsed time for " << COUNT << " emissions (5 slots): " << t2.tv_sec << "s " << t2.tv_usec << "us" << std::endl;
9895
}
9996

10097
void test_connect_disconnect()
@@ -106,7 +103,7 @@ void test_connect_disconnect()
106103
Glib::TimeVal t1, t2;
107104
t1.assign_current_time();
108105

109-
for (int i=0; i < 1000; ++i)
106+
for (int i=0; i < COUNT; ++i)
110107
{
111108
it = emitter.connect(mem_fun(&foobar1, &foo::bar));
112109
it->disconnect();
@@ -115,7 +112,7 @@ void test_connect_disconnect()
115112
t2.assign_current_time();
116113
t2.subtract(t1);
117114

118-
std::cout << "elapsed time for 1000 connections/disconnections: " << t2.tv_sec << "s " << t2.tv_usec << "us" << std::endl;
115+
std::cout << "elapsed time for " << COUNT << " connections/disconnections: " << t2.tv_sec << "s " << t2.tv_usec << "us" << std::endl;
119116
}
120117

121118
int main()

0 commit comments

Comments
 (0)