[libsigcplusplus/libsigc++-2-10] benchmark: Update for the newer libsigc++ API.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libsigcplusplus/libsigc++-2-10] benchmark: Update for the newer libsigc++ API.
- Date: Wed, 20 Apr 2016 09:58:53 +0000 (UTC)
commit 6535a7ab155b372e770b90a2a0202fb869c01b85
Author: Murray Cumming <murrayc murrayc com>
Date: Wed Apr 20 09:31:51 2016 +0200
benchmark: Update for the newer libsigc++ API.
tests/benchmark.cc | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 107 insertions(+), 0 deletions(-)
---
diff --git a/tests/benchmark.cc b/tests/benchmark.cc
new file mode 100644
index 0000000..f75b73c
--- /dev/null
+++ b/tests/benchmark.cc
@@ -0,0 +1,107 @@
+#include <iostream>
+#include <sigc++/signal.h>
+#include <sigc++/functors/mem_fun.h>
+#include <glibmm/timeval.h>
+
+struct foo : public sigc::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;
+ sigc::slot<int,int> slot;
+ sigc::signal<int,int> emitter;
+ sigc::signal<int,int>::iterator it;
+
+
+ // slot benchmark ...
+
+ slot = sigc::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);
+
+ std::cout << "elapsed time for calling a slot 5000 times: " << t2.tv_sec << "s " << t2.tv_usec << "us" <<
std::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);
+
+ std::cout << "elapsed time for 1000 emissions (0 slots): " << t2.tv_sec << "s " << t2.tv_usec << "us" <<
std::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);
+
+ std::cout << "elapsed time for 1000 emissions (1 slot): " << t2.tv_sec << "s " << t2.tv_usec << "us" <<
std::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);
+
+ std::cout << "elapsed time for 1000 emissions (5 slots): " << t2.tv_sec << "s " << t2.tv_usec << "us" <<
std::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);
+
+ std::cout << "elapsed time for 1000 connections/disconnections: " << t2.tv_sec << "s " << t2.tv_usec <<
"us" << std::endl;
+
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]