summaryrefslogtreecommitdiffstats
path: root/src/boost/libs/signals2/test/invocation_benchmark.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 18:45:59 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 18:45:59 +0000
commit19fcec84d8d7d21e796c7624e521b60d28ee21ed (patch)
tree42d26aa27d1e3f7c0b8bd3fd14e7d7082f5008dc /src/boost/libs/signals2/test/invocation_benchmark.cpp
parentInitial commit. (diff)
downloadceph-19fcec84d8d7d21e796c7624e521b60d28ee21ed.tar.xz
ceph-19fcec84d8d7d21e796c7624e521b60d28ee21ed.zip
Adding upstream version 16.2.11+ds.upstream/16.2.11+dsupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/boost/libs/signals2/test/invocation_benchmark.cpp')
-rw-r--r--src/boost/libs/signals2/test/invocation_benchmark.cpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/boost/libs/signals2/test/invocation_benchmark.cpp b/src/boost/libs/signals2/test/invocation_benchmark.cpp
new file mode 100644
index 000000000..6a464fc52
--- /dev/null
+++ b/src/boost/libs/signals2/test/invocation_benchmark.cpp
@@ -0,0 +1,60 @@
+/* multi-threaded signal invocation benchmark */
+
+// Copyright Frank Mori Hess 2007-2008.
+// Distributed under the Boost Software License, Version
+// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#include <cstdlib>
+#include <iostream>
+#include <boost/bind/bind.hpp>
+#include <boost/signals2.hpp>
+#include <boost/thread/thread.hpp>
+
+using namespace boost::placeholders;
+
+typedef boost::signals2::signal<void ()> signal_type;
+
+void myslot()
+{
+/* std::cout << __FUNCTION__ << std::endl;
+ sleep(1);*/
+}
+
+void thread_initial(signal_type *signal, unsigned num_invocations)
+{
+ unsigned i;
+ for(i = 0; i < num_invocations; ++i)
+ {
+ (*signal)();
+ }
+}
+
+int main(int argc, const char **argv)
+{
+ if(argc < 3)
+ {
+ std::cerr << "usage: " << argv[0] << " <num threads> <num connections>" << std::endl;
+ return -1;
+ }
+ static const unsigned num_threads = std::strtol(argv[1], 0, 0);
+ static const unsigned num_connections = std::strtol(argv[2], 0, 0);
+ boost::thread_group threads;
+ signal_type sig;
+
+ std::cout << "Connecting " << num_connections << " connections to signal.\n";
+ unsigned i;
+ for(i = 0; i < num_connections; ++i)
+ {
+ sig.connect(&myslot);
+ }
+ const unsigned num_slot_invocations = 1000000;
+ const unsigned signal_invocations_per_thread = num_slot_invocations / (num_threads * num_connections);
+ std::cout << "Launching " << num_threads << " thread(s) to invoke signal " << signal_invocations_per_thread << " times per thread.\n";
+ for(i = 0; i < num_threads; ++i)
+ {
+ threads.create_thread(boost::bind(&thread_initial, &sig, signal_invocations_per_thread));
+ }
+ threads.join_all();
+ return 0;
+}