[libsigcplusplus] benchmark: Rearrange.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libsigcplusplus] benchmark: Rearrange.
- Date: Wed, 20 Apr 2016 09:47:40 +0000 (UTC)
commit ac25f0955a41d471de7cea1f98b552455a236a42
Author: Murray Cumming <murrayc murrayc com>
Date: Wed Apr 20 10:06:55 2016 +0200
benchmark: Rearrange.
tests/benchmark.cc | 64 ++++++++++++++++++++++++++++++++++++---------------
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();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]