Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r51635 - trunk/libs/signals2/test
From: fmhess_at_[hidden]
Date: 2009-03-06 11:12:48


Author: fmhess
Date: 2009-03-06 11:12:47 EST (Fri, 06 Mar 2009)
New Revision: 51635
URL: http://svn.boost.org/trac/boost/changeset/51635

Log:
Replaced tab indentation with spaces, added a missing copyright/license.

Text files modified:
   trunk/libs/signals2/test/invocation_benchmark.cpp | 71 ++++++-----
   trunk/libs/signals2/test/signals_vs_signals2_benchmark.cpp | 224 ++++++++++++++++++++--------------------
   2 files changed, 151 insertions(+), 144 deletions(-)

Modified: trunk/libs/signals2/test/invocation_benchmark.cpp
==============================================================================
--- trunk/libs/signals2/test/invocation_benchmark.cpp (original)
+++ trunk/libs/signals2/test/invocation_benchmark.cpp 2009-03-06 11:12:47 EST (Fri, 06 Mar 2009)
@@ -1,3 +1,10 @@
+/* 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.hpp>
@@ -8,44 +15,44 @@
 
 void myslot()
 {
-/* std::cout << __FUNCTION__ << std::endl;
- sleep(1);*/
+/* 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)();
- }
+ 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;
+ 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;
 }

Modified: trunk/libs/signals2/test/signals_vs_signals2_benchmark.cpp
==============================================================================
--- trunk/libs/signals2/test/signals_vs_signals2_benchmark.cpp (original)
+++ trunk/libs/signals2/test/signals_vs_signals2_benchmark.cpp 2009-03-06 11:12:47 EST (Fri, 06 Mar 2009)
@@ -13,158 +13,158 @@
 #include <boost/signals.hpp>
 
 typedef boost::signals2::signal<void (int),
- boost::signals2::optional_last_value<void>,
- int,
- std::less<int>,
- boost::function<void (int)>,
- boost::function<void (const boost::signals2::connection &, int)>,
- boost::signals2::dummy_mutex>
- new_signal_type;
+ boost::signals2::optional_last_value<void>,
+ int,
+ std::less<int>,
+ boost::function<void (int)>,
+ boost::function<void (const boost::signals2::connection &, int)>,
+ boost::signals2::dummy_mutex>
+ new_signal_type;
 typedef boost::signal<void (int)> old_signal_type;
 
 class myslot
 {
 public:
- void operator()(int) {};
+ void operator()(int) {};
 };
 
 class trackable_slot: public myslot, public boost::signals::trackable
 {};
 
 template<typename Signal>
- void benchmark_invocation(unsigned num_connections)
+ void benchmark_invocation(unsigned num_connections)
 {
- static const unsigned num_invocations = 1000000;
+ static const unsigned num_invocations = 1000000;
 
- Signal signal;
- std::cout << num_connections << " connections, invoking " << num_invocations << " times: ";
- unsigned n;
- for(n = 0; n < num_connections; ++n)
- {
- signal.connect(myslot());
- }
- {
- boost::progress_timer timer;
- unsigned i;
- for(i = 0; i < num_invocations; ++i)
- {
- signal(0);
- }
- }
+ Signal signal;
+ std::cout << num_connections << " connections, invoking " << num_invocations << " times: ";
+ unsigned n;
+ for(n = 0; n < num_connections; ++n)
+ {
+ signal.connect(myslot());
+ }
+ {
+ boost::progress_timer timer;
+ unsigned i;
+ for(i = 0; i < num_invocations; ++i)
+ {
+ signal(0);
+ }
+ }
 }
 
 void benchmark_old_tracked_invocation(unsigned num_connections)
 {
- static const unsigned num_invocations = 1000000;
+ static const unsigned num_invocations = 1000000;
 
- old_signal_type signal;
- std::cout << "boost::signal, " << num_connections << " connections, tracking enabled, invoking " << num_invocations << " times: ";
- unsigned n;
- trackable_slot tslot;
- for(n = 0; n < num_connections; ++n)
- {
- signal.connect(tslot);
- }
- {
- boost::progress_timer timer;
- unsigned i;
- for(i = 0; i < num_invocations; ++i)
- {
- signal(0);
- }
- }
+ old_signal_type signal;
+ std::cout << "boost::signal, " << num_connections << " connections, tracking enabled, invoking " << num_invocations << " times: ";
+ unsigned n;
+ trackable_slot tslot;
+ for(n = 0; n < num_connections; ++n)
+ {
+ signal.connect(tslot);
+ }
+ {
+ boost::progress_timer timer;
+ unsigned i;
+ for(i = 0; i < num_invocations; ++i)
+ {
+ signal(0);
+ }
+ }
 }
 
 void benchmark_new_tracked_invocation(unsigned num_connections)
 {
- static const unsigned num_invocations = 1000000;
+ static const unsigned num_invocations = 1000000;
 
- new_signal_type signal;
- std::cout << "boost::signals2::signal, " << num_connections << " connections, tracking enabled, invoking " << num_invocations << " times: ";
- boost::shared_ptr<int> trackable_ptr(new int(0));
- unsigned n;
- for(n = 0; n < num_connections; ++n)
- {
- new_signal_type::slot_type slot((myslot()));
- slot.track(trackable_ptr);
- signal.connect(slot);
- }
- {
- boost::progress_timer timer;
- unsigned i;
- for(i = 0; i < num_invocations; ++i)
- {
- signal(0);
- }
- }
+ new_signal_type signal;
+ std::cout << "boost::signals2::signal, " << num_connections << " connections, tracking enabled, invoking " << num_invocations << " times: ";
+ boost::shared_ptr<int> trackable_ptr(new int(0));
+ unsigned n;
+ for(n = 0; n < num_connections; ++n)
+ {
+ new_signal_type::slot_type slot((myslot()));
+ slot.track(trackable_ptr);
+ signal.connect(slot);
+ }
+ {
+ boost::progress_timer timer;
+ unsigned i;
+ for(i = 0; i < num_invocations; ++i)
+ {
+ signal(0);
+ }
+ }
 }
 
 template<typename Signal> class connection_type;
 template<> class connection_type<old_signal_type>
 {
 public:
- typedef boost::signals::connection type;
+ typedef boost::signals::connection type;
 };
 template<> class connection_type<new_signal_type>
 {
 public:
- typedef boost::signals2::connection type;
+ typedef boost::signals2::connection type;
 };
 
 template<typename Signal>
- void benchmark_connect_disconnect()
+ void benchmark_connect_disconnect()
 {
- static const unsigned num_connections = 1000000;
- std::vector<typename connection_type<Signal>::type> connections(num_connections);
+ static const unsigned num_connections = 1000000;
+ std::vector<typename connection_type<Signal>::type> connections(num_connections);
 
- Signal signal;
- std::cout << "connecting " << num_connections << " connections then disconnecting: ";
- unsigned n;
- {
- boost::progress_timer timer;
- for(n = 0; n < num_connections; ++n)
- {
- connections.at(n) = signal.connect(myslot());
- }
- for(n = 0; n < num_connections; ++n)
- {
- connections.at(n).disconnect();
- }
- }
+ Signal signal;
+ std::cout << "connecting " << num_connections << " connections then disconnecting: ";
+ unsigned n;
+ {
+ boost::progress_timer timer;
+ for(n = 0; n < num_connections; ++n)
+ {
+ connections.at(n) = signal.connect(myslot());
+ }
+ for(n = 0; n < num_connections; ++n)
+ {
+ connections.at(n).disconnect();
+ }
+ }
 }
 
 int main(int argc, const char **argv)
 {
- {
- std::cout << "boost::signals2::signal, ";
- benchmark_invocation<new_signal_type>(1);
- }
- {
- std::cout << "boost::signal, ";
- benchmark_invocation<old_signal_type>(1);
- }
-
- {
- std::cout << "boost::signals2::signal, ";
- benchmark_invocation<new_signal_type>(10);
- }
- {
- std::cout << "boost::signal, ";
- benchmark_invocation<old_signal_type>(10);
- }
-
- benchmark_new_tracked_invocation(1);
- benchmark_old_tracked_invocation(1);
-
- benchmark_new_tracked_invocation(10);
- benchmark_old_tracked_invocation(10);
-
- {
- std::cout << "boost::signals2::signal, ";
- benchmark_connect_disconnect<new_signal_type>();
- }
- {
- std::cout << "boost::signal, ";
- benchmark_connect_disconnect<old_signal_type>();
- }
+ {
+ std::cout << "boost::signals2::signal, ";
+ benchmark_invocation<new_signal_type>(1);
+ }
+ {
+ std::cout << "boost::signal, ";
+ benchmark_invocation<old_signal_type>(1);
+ }
+
+ {
+ std::cout << "boost::signals2::signal, ";
+ benchmark_invocation<new_signal_type>(10);
+ }
+ {
+ std::cout << "boost::signal, ";
+ benchmark_invocation<old_signal_type>(10);
+ }
+
+ benchmark_new_tracked_invocation(1);
+ benchmark_old_tracked_invocation(1);
+
+ benchmark_new_tracked_invocation(10);
+ benchmark_old_tracked_invocation(10);
+
+ {
+ std::cout << "boost::signals2::signal, ";
+ benchmark_connect_disconnect<new_signal_type>();
+ }
+ {
+ std::cout << "boost::signal, ";
+ benchmark_connect_disconnect<old_signal_type>();
+ }
 }


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk