summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMurray Cumming <murrayc@murrayc.com>2016-04-20 10:06:55 +0200
committerMurray Cumming <murrayc@murrayc.com>2016-04-20 11:51:47 +0200
commit9476c08d447048054e9d2335b0d224c6d091268d (patch)
tree265fd3f4a9c734dd4fd6134702cfc250ec6080cd
parent6e34e4270a7b6390b1c04f1571bd7f77f81ea412 (diff)
downloadsigc++-9476c08d447048054e9d2335b0d224c6d091268d.tar.gz
benchmark: Rearrange.
-rw-r--r--tests/benchmark.cc64
1 files changed, 45 insertions, 19 deletions
diff --git a/tests/benchmark.cc b/tests/benchmark.cc
index e4adb3c..d9ef614 100644
--- a/tests/benchmark.cc
+++ b/tests/benchmark.cc
@@ -20,20 +20,16 @@ int foo::bar(int a)
return b;
}
-int main()
+void test_slot_call()
{
- Glib::TimeVal t1, t2;
-
- foo foobar1, foobar2, foobar3, foobar4, foobar5;
- sigc::slot<int,int> slot;
- sigc::signal<int,int> emitter;
+ foo foobar1;
sigc::signal<int,int>::iterator it;
-
// slot benchmark ...
- slot = sigc::mem_fun(&foobar1, &foo::bar);
+ sigc::slot<int,int> slot = sigc::mem_fun(&foobar1, &foo::bar);
+ Glib::TimeVal t1, t2;
t1.assign_current_time();
for (int i=0; i < 5000; ++i)
@@ -43,10 +39,13 @@ int main()
t2.subtract(t1);
std::cout << "elapsed time for calling a slot 5000 times: " << t2.tv_sec << "s " << t2.tv_usec << "us" << std::endl;
+}
+void test_signal_emit()
+{
+ sigc::signal<int,int> emitter;
- // emission benchmark (zero slots) ...
-
+ Glib::TimeVal t1, t2;
t1.assign_current_time();
for (int i=0; i < 1000; ++i)
@@ -56,12 +55,15 @@ int main()
t2.subtract(t1);
std::cout << "elapsed time for 1000 emissions (0 slots): " << t2.tv_sec << "s " << t2.tv_usec << "us" << std::endl;
+}
-
- // emission benchmark (one slot) ...
-
+void test_connected_signal_emit()
+{
+ foo foobar1;
+ sigc::signal<int,int> emitter;
emitter.connect(mem_fun(&foobar1, &foo::bar));
+ Glib::TimeVal t1, t2;
t1.assign_current_time();
for (int i=0; i < 1000; ++i)
@@ -71,15 +73,19 @@ int main()
t2.subtract(t1);
std::cout << "elapsed time for 1000 emissions (1 slot): " << t2.tv_sec << "s " << t2.tv_usec << "us" << std::endl;
+}
+void test_connected_multiple_signal_emit()
+{
+ foo foobar1, foobar2, foobar3, foobar4, foobar5;
- // emission benchmark (five slot) ...
-
+ sigc::signal<int,int> emitter;
emitter.connect(mem_fun(&foobar2, &foo::bar));
emitter.connect(mem_fun(&foobar3, &foo::bar));
emitter.connect(mem_fun(&foobar4, &foo::bar));
emitter.connect(mem_fun(&foobar5, &foo::bar));
+ Glib::TimeVal t1, t2;
t1.assign_current_time();
for (int i=0; i < 1000; ++i)
@@ -89,12 +95,15 @@ int main()
t2.subtract(t1);
std::cout << "elapsed time for 1000 emissions (5 slots): " << t2.tv_sec << "s " << t2.tv_usec << "us" << std::endl;
+}
+void test_connect_disconnect()
+{
+ foo foobar1;
+ sigc::signal<int, int> emitter;
+ sigc::signal<int, int>::iterator it;
- // connection / disconnection benchmark ...
-
- emitter.clear();
-
+ Glib::TimeVal t1, t2;
t1.assign_current_time();
for (int i=0; i < 1000; ++i)
@@ -107,5 +116,22 @@ int main()
t2.subtract(t1);
std::cout << "elapsed time for 1000 connections/disconnections: " << t2.tv_sec << "s " << t2.tv_usec << "us" << std::endl;
+}
+int main()
+{
+ // slot benchmark ...
+ test_slot_call();
+
+ // emission benchmark (zero slots) ...
+ test_signal_emit();
+
+ // emission benchmark (one slot) ...
+ test_connected_signal_emit();
+
+ // emission benchmark (five slot) ...
+ test_connected_multiple_signal_emit();
+
+ // connection / disconnection benchmark ...
+ test_connect_disconnect();
}