[libsigcplusplus] Add original benchmark code.



commit c5aef224507358262f5a04c8bff6925d12f06822
Author: Murray Cumming <murrayc murrayc com>
Date:   Wed Apr 20 09:27:56 2016 +0200

    Add original benchmark code.
    
    From 2003 here:
    https://mail.gnome.org/archives/libsigc-list/2003-October/msg00005.html

 tests/benchmark.cc |  111 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 111 insertions(+), 0 deletions(-)
---
diff --git a/tests/benchmark.cc b/tests/benchmark.cc
new file mode 100644
index 0000000..b2117f5
--- /dev/null
+++ b/tests/benchmark.cc
@@ -0,0 +1,111 @@
+#include <iostream>
+#include <sigc++/signal.h>
+#include <sigc++/functors/mem_fun.h>
+#include <glibmm/timeval.h>
+
+using namespace std;
+using namespace sigc;
+using namespace sigc::functor;
+
+struct foo : public trackable
+{
+  int bar(int a);
+  int c;
+};
+
+int foo::bar(int a)
+{
+  int b = c;
+  c = a;
+  return b;
+}
+
+int main()
+{
+  Glib::TimeVal t1, t2;
+
+  foo foobar1, foobar2, foobar3, foobar4, foobar5;
+  closure<int,int> slot;
+  signal<int,int> emitter;
+  signal<int,int>::iterator it;
+
+
+  // slot benchmark ...
+
+  slot = mem_fun(&foobar1, &foo::bar);
+
+  t1.assign_current_time();
+
+  for (int i=0; i < 5000; ++i)
+    slot(i);
+
+  t2.assign_current_time();
+  t2.subtract(t1);
+
+  cout << "elapsed time for calling a slot 5000 times: " << t2.tv_sec << "s " << t2.tv_usec << "us" << endl;
+
+
+  // emission benchmark (zero slots) ...
+
+  t1.assign_current_time();
+
+  for (int i=0; i < 1000; ++i)
+    emitter(i);
+
+  t2.assign_current_time();
+  t2.subtract(t1);
+
+  cout << "elapsed time for 1000 emissions (0 slots): " << t2.tv_sec << "s " << t2.tv_usec << "us" << endl;
+
+
+  // emission benchmark (one slot) ...
+
+  emitter.connect(mem_fun(&foobar1, &foo::bar));
+
+  t1.assign_current_time();
+
+  for (int i=0; i < 1000; ++i)
+    emitter(i);
+
+  t2.assign_current_time();
+  t2.subtract(t1);
+
+  cout << "elapsed time for 1000 emissions (1 slot): " << t2.tv_sec << "s " << t2.tv_usec << "us" << endl;
+
+
+  // emission benchmark (five slot) ...
+
+  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));
+
+  t1.assign_current_time();
+
+  for (int i=0; i < 1000; ++i)
+    emitter(i);
+
+  t2.assign_current_time();
+  t2.subtract(t1);
+
+  cout << "elapsed time for 1000 emissions (5 slots): " << t2.tv_sec << "s " << t2.tv_usec << "us" << endl;
+
+
+  // connection / disconnection benchmark ...
+
+  emitter.clear();
+
+  t1.assign_current_time();
+
+  for (int i=0; i < 1000; ++i)
+    {
+      it = emitter.connect(mem_fun(&foobar1, &foo::bar));
+      it->disconnect();
+    }
+
+  t2.assign_current_time();
+  t2.subtract(t1);
+
+  cout << "elapsed time for 1000 connections/disconnections: " << t2.tv_sec << "s " << t2.tv_usec << "us" << 
endl;
+
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]