summaryrefslogtreecommitdiff
path: root/performance-tests/Misc
diff options
context:
space:
mode:
Diffstat (limited to 'performance-tests/Misc')
-rw-r--r--performance-tests/Misc/Makefile145
-rw-r--r--performance-tests/Misc/test_mutex.cpp230
-rw-r--r--performance-tests/Misc/test_naming.cpp169
-rw-r--r--performance-tests/Misc/test_singleton.cpp183
4 files changed, 0 insertions, 727 deletions
diff --git a/performance-tests/Misc/Makefile b/performance-tests/Misc/Makefile
deleted file mode 100644
index 829d15c1455..00000000000
--- a/performance-tests/Misc/Makefile
+++ /dev/null
@@ -1,145 +0,0 @@
-#----------------------------------------------------------------------------
-# @(#)Makefile 1.1 10/18/96
-#
-# Makefile for tests of the miscellaneous ACE performance tests
-#----------------------------------------------------------------------------
-
-#----------------------------------------------------------------------------
-# Local macros
-#----------------------------------------------------------------------------
-
-BIN = test_mutex \
- test_singleton \
- test_naming
-
-LSRC = $(addsuffix .cpp,$(BIN))
-VLDLIBS = $(LDLIBS:%=%$(VAR))
-
-BUILD = $(VBIN)
-
-#----------------------------------------------------------------------------
-# Include macros and targets
-#----------------------------------------------------------------------------
-
-include $(WRAPPER_ROOT)/include/makeinclude/wrapper_macros.GNU
-include $(WRAPPER_ROOT)/include/makeinclude/macros.GNU
-include $(WRAPPER_ROOT)/include/makeinclude/rules.common.GNU
-include $(WRAPPER_ROOT)/include/makeinclude/rules.nonested.GNU
-include $(WRAPPER_ROOT)/include/makeinclude/rules.bin.GNU
-include $(WRAPPER_ROOT)/include/makeinclude/rules.local.GNU
-
-#----------------------------------------------------------------------------
-# Local targets
-#----------------------------------------------------------------------------
-
-#----------------------------------------------------------------------------
-# Dependencies
-#----------------------------------------------------------------------------
-
-# DO NOT DELETE THIS LINE -- g++dep uses it.
-# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY.
-
-.obj/test_mutex.o .shobj/test_mutex.so: test_mutex.cpp \
- $(WRAPPER_ROOT)/ace/Log_Msg.h \
- $(WRAPPER_ROOT)/ace/Log_Record.h \
- $(WRAPPER_ROOT)/ace/ACE.h \
- $(WRAPPER_ROOT)/ace/OS.h \
- $(WRAPPER_ROOT)/ace/Time_Value.h \
- $(WRAPPER_ROOT)/ace/config.h \
- $(WRAPPER_ROOT)/ace/Trace.h \
- $(WRAPPER_ROOT)/ace/ACE.i \
- $(WRAPPER_ROOT)/ace/Log_Priority.h \
- $(WRAPPER_ROOT)/ace/Log_Record.i \
- $(WRAPPER_ROOT)/ace/Profile_Timer.h
-.obj/test_singleton.o .shobj/test_singleton.so: test_singleton.cpp \
- $(WRAPPER_ROOT)/ace/Profile_Timer.h \
- $(WRAPPER_ROOT)/ace/ACE.h \
- $(WRAPPER_ROOT)/ace/OS.h \
- $(WRAPPER_ROOT)/ace/Time_Value.h \
- $(WRAPPER_ROOT)/ace/config.h \
- $(WRAPPER_ROOT)/ace/Trace.h \
- $(WRAPPER_ROOT)/ace/ACE.i \
- $(WRAPPER_ROOT)/ace/Log_Msg.h \
- $(WRAPPER_ROOT)/ace/Log_Record.h \
- $(WRAPPER_ROOT)/ace/Log_Priority.h \
- $(WRAPPER_ROOT)/ace/Log_Record.i \
- $(WRAPPER_ROOT)/ace/Singleton.h \
- $(WRAPPER_ROOT)/ace/Singleton.cpp \
- $(WRAPPER_ROOT)/ace/Synch_T.h \
- $(WRAPPER_ROOT)/ace/Synch.h \
- $(WRAPPER_ROOT)/ace/SV_Semaphore_Complex.h \
- $(WRAPPER_ROOT)/ace/SV_Semaphore_Simple.h \
- $(WRAPPER_ROOT)/ace/SV_Semaphore_Simple.i \
- $(WRAPPER_ROOT)/ace/SV_Semaphore_Complex.i \
- $(WRAPPER_ROOT)/ace/Synch_T.cpp \
- $(WRAPPER_ROOT)/ace/Thread.h \
- $(WRAPPER_ROOT)/ace/Synch_T.i \
- $(WRAPPER_ROOT)/ace/Singleton.i
-.obj/test_naming.o .shobj/test_naming.so: test_naming.cpp \
- $(WRAPPER_ROOT)/ace/SString.h \
- $(WRAPPER_ROOT)/ace/ACE.h \
- $(WRAPPER_ROOT)/ace/OS.h \
- $(WRAPPER_ROOT)/ace/Time_Value.h \
- $(WRAPPER_ROOT)/ace/config.h \
- $(WRAPPER_ROOT)/ace/Trace.h \
- $(WRAPPER_ROOT)/ace/ACE.i \
- $(WRAPPER_ROOT)/ace/Log_Msg.h \
- $(WRAPPER_ROOT)/ace/Log_Record.h \
- $(WRAPPER_ROOT)/ace/Log_Priority.h \
- $(WRAPPER_ROOT)/ace/Log_Record.i \
- $(WRAPPER_ROOT)/ace/Naming_Context.h \
- $(WRAPPER_ROOT)/ace/Set.h \
- $(WRAPPER_ROOT)/ace/Set.cpp \
- $(WRAPPER_ROOT)/ace/Set.i \
- $(WRAPPER_ROOT)/ace/Service_Object.h \
- $(WRAPPER_ROOT)/ace/Shared_Object.h \
- $(WRAPPER_ROOT)/ace/Event_Handler.h \
- $(WRAPPER_ROOT)/ace/Name_Proxy.h \
- $(WRAPPER_ROOT)/ace/INET_Addr.h \
- $(WRAPPER_ROOT)/ace/Addr.h \
- $(WRAPPER_ROOT)/ace/SOCK_Connector.h \
- $(WRAPPER_ROOT)/ace/SOCK_Stream.h \
- $(WRAPPER_ROOT)/ace/SOCK_IO.h \
- $(WRAPPER_ROOT)/ace/SOCK.h \
- $(WRAPPER_ROOT)/ace/IPC_SAP.h \
- $(WRAPPER_ROOT)/ace/IPC_SAP.i \
- $(WRAPPER_ROOT)/ace/SOCK.i \
- $(WRAPPER_ROOT)/ace/SOCK_IO.i \
- $(WRAPPER_ROOT)/ace/SOCK_Stream.i \
- $(WRAPPER_ROOT)/ace/SOCK_Connector.i \
- $(WRAPPER_ROOT)/ace/Service_Config.h \
- $(WRAPPER_ROOT)/ace/Thread_Manager.h \
- $(WRAPPER_ROOT)/ace/Thread.h \
- $(WRAPPER_ROOT)/ace/Synch.h \
- $(WRAPPER_ROOT)/ace/SV_Semaphore_Complex.h \
- $(WRAPPER_ROOT)/ace/SV_Semaphore_Simple.h \
- $(WRAPPER_ROOT)/ace/SV_Semaphore_Simple.i \
- $(WRAPPER_ROOT)/ace/SV_Semaphore_Complex.i \
- $(WRAPPER_ROOT)/ace/Synch_T.h \
- $(WRAPPER_ROOT)/ace/Synch_T.cpp \
- $(WRAPPER_ROOT)/ace/Synch_T.i \
- $(WRAPPER_ROOT)/ace/Proactor.h \
- $(WRAPPER_ROOT)/ace/Message_Block.h \
- $(WRAPPER_ROOT)/ace/Malloc.h \
- $(WRAPPER_ROOT)/ace/Malloc_T.h \
- $(WRAPPER_ROOT)/ace/Malloc_T.cpp \
- $(WRAPPER_ROOT)/ace/Malloc_T.i \
- $(WRAPPER_ROOT)/ace/Memory_Pool.h \
- $(WRAPPER_ROOT)/ace/Signal.h \
- $(WRAPPER_ROOT)/ace/Mem_Map.h \
- $(WRAPPER_ROOT)/ace/Timer_Queue.h \
- $(WRAPPER_ROOT)/ace/Timer_Queue.i \
- $(WRAPPER_ROOT)/ace/ReactorEx.h \
- $(WRAPPER_ROOT)/ace/Token.h \
- $(WRAPPER_ROOT)/ace/Reactor.h \
- $(WRAPPER_ROOT)/ace/Handle_Set.h \
- $(WRAPPER_ROOT)/ace/Pipe.h \
- $(WRAPPER_ROOT)/ace/Pipe.i \
- $(WRAPPER_ROOT)/ace/Reactor.i \
- $(WRAPPER_ROOT)/ace/Svc_Conf_Tokens.h \
- $(WRAPPER_ROOT)/ace/Synch_Options.h \
- $(WRAPPER_ROOT)/ace/Name_Request_Reply.h \
- $(WRAPPER_ROOT)/ace/Name_Space.h \
- $(WRAPPER_ROOT)/ace/Profile_Timer.h
-
-# IF YOU PUT ANYTHING HERE IT WILL GO AWAY
diff --git a/performance-tests/Misc/test_mutex.cpp b/performance-tests/Misc/test_mutex.cpp
deleted file mode 100644
index 0f5a6bb8d81..00000000000
--- a/performance-tests/Misc/test_mutex.cpp
+++ /dev/null
@@ -1,230 +0,0 @@
-// This test program illustrates the performance difference between
-// $Id$
-
-// three versions of wrappers for thread mutexes. These three
-// versions exercise various combinations of the following classes:
-//
-// Thread_Mutex --
-// This version is just like ACE_Thread_Mutex, which doesn't use
-// inheritance and dynamic binding.
-//
-// Mutex_Base --
-// This is an abstract base class that defines the
-// acquire()/release() interface.
-//
-// Thread_Mutex_Derived --
-// This derived from Mutex_Base and uses inheritance and
-// dynamic binding.
-//
-// The following are the results I got when running this on our
-// SPARCstation 20 model 712:
-//
-// ./test_mutex 1000000
-// iterations = 1000000
-// Thread_Mutex
-// real time = 1.727843 secs, user time = 1.729262 secs, system time = 0.000325 secs
-// time per call = 1.747843 usecs
-// Thread_Mutex_Derived
-// real time = 1.730225 secs, user time = 1.724744 secs, system time = 0.000096 secs
-// time per call = 1.730225 usecs
-// Mutex_Base
-// real time = 2.112831 secs, user time = 2.104245 secs, system time = 0.000095 secs
-// time per call = 2.112831 usecs
-//
-// My conclusions are as follows:
-//
-// 1. If your C++ compiler optimizes calls to virtual functions that
-// are made through instances of derived classes, then the
-// performance of the Thread_Mutex and Thread_Mutex_Derived are
-// essentially identical.
-//
-// 2. The overhead from using virtual functions is approximately
-// 20%. Naturally, as the amount of contention goes up, the
-// relative overhead of the virtual function calls will decrease.
-//
-// Keep in mind, however, that using virtual functions to implement
-// the Thread_Mutex will make it infeasible to put instances of
-// Thread_Mutex into shared memory since the vptrs won't point to the
-// correct vtables...
-
-#include "ace/Log_Msg.h"
-#include "ace/Profile_Timer.h"
-#include "ace/OS.h"
-
-#if defined (ACE_HAS_THREADS)
-
-static const int DEFAULT_ITERATIONS = 100000000;
-
-// A thread mutex that doesn't use virtual functions.
-class Thread_Mutex
-{
-public:
- Thread_Mutex (void);
- ~Thread_Mutex (void);
- int acquire (void);
- int release (void);
-
-private:
- ACE_mutex_t mutex_;
-};
-
-Thread_Mutex::Thread_Mutex (void)
-{
- ACE_OS::mutex_init (&this->mutex_);
-}
-
-Thread_Mutex::~Thread_Mutex (void)
-{
- ACE_OS::mutex_destroy (&this->mutex_);
-}
-
-inline int
-Thread_Mutex::acquire (void)
-{
- return ACE_OS::mutex_lock (&this->mutex_);
-}
-
-inline int
-Thread_Mutex::release (void)
-{
- return ACE_OS::mutex_unlock (&this->mutex_);
-}
-
-// Base class for mutex, declares pure virtual functions.
-class Mutex_Base
-{
-public:
- virtual int acquire (void) = 0;
- virtual int release (void) = 0;
-};
-
-// Subclass for threaded mutex, defines virtual functions.
-class Thread_Mutex_Derived : public Mutex_Base
-{
-public:
- Thread_Mutex_Derived (void);
- ~Thread_Mutex_Derived (void);
- virtual int acquire (void);
- virtual int release (void);
-
-private:
- ACE_mutex_t mutex_;
-};
-
-Thread_Mutex_Derived::Thread_Mutex_Derived (void)
-{
- ACE_OS::mutex_init (&this->mutex_);
-}
-
-Thread_Mutex_Derived::~Thread_Mutex_Derived (void)
-{
- ACE_OS::mutex_destroy (&this->mutex_);
-}
-
-inline int
-Thread_Mutex_Derived::acquire (void)
-{
- return ACE_OS::mutex_lock (&this->mutex_);
-}
-
-inline int
-Thread_Mutex_Derived::release (void)
-{
- return ACE_OS::mutex_unlock (&this->mutex_);
-}
-
-static Thread_Mutex thread_mutex;
-static Thread_Mutex_Derived thread_mutex_derived;
-static Mutex_Base *mutex_base = &thread_mutex_derived;
-
-int
-main (int argc, char *argv[])
-{
- ACE_Profile_Timer timer;
- int iterations = argc > 1 ? ACE_OS::atoi (argv[1]) : DEFAULT_ITERATIONS;
- int i;
-
- ACE_DEBUG ((LM_DEBUG, "iterations = %d\n", iterations));
-
- timer.start ();
-
- // Test the thread mutex (which doesn't use inheritance or dynamic
- // binding).
-
- for (i = 0; i < iterations; i++)
- {
- thread_mutex.acquire ();
- thread_mutex.release ();
- }
-
- timer.stop ();
-
- ACE_Profile_Timer::ACE_Elapsed_Time et;
-
- timer.elapsed_time (et);
-
- ACE_DEBUG ((LM_DEBUG, "Thread_Mutex\n"));
- ACE_DEBUG ((LM_DEBUG, "real time = %f secs, user time = %f secs, system time = %f secs\n",
- et.real_time, et.user_time, et.system_time));
-
- ACE_DEBUG ((LM_DEBUG, "time per call = %f usecs\n",
- (et.real_time / double (iterations)) * 1000000));
-
- // Test the thread mutex derived (which does use inheritance or
- // dynamic binding). Note that we call this via an instance of the
- // derived class, so good C++ compilers should optimize the virtual
- // function calls in this case.
-
- timer.start ();
-
- for (i = 0; i < iterations; i++)
- {
- thread_mutex_derived.acquire ();
- thread_mutex_derived.release ();
- }
-
- timer.stop ();
-
- timer.elapsed_time (et);
-
- ACE_DEBUG ((LM_DEBUG, "Thread_Mutex_Derived\n"));
- ACE_DEBUG ((LM_DEBUG, "real time = %f secs, user time = %f secs, system time = %f secs\n",
- et.real_time, et.user_time, et.system_time));
-
- ACE_DEBUG ((LM_DEBUG, "time per call = %f usecs\n",
- (et.real_time / double (iterations)) * 1000000));
-
- // Test the thread mutex derived (which does use inheritance or
- // dynamic binding). Note that we call this via a pointer to the
- // base class, which points to an instance of the derived class.
- // Thus, C++ compilers won't be able to optimize the virtual
- // function calls in this case.
-
- timer.start ();
-
- for (i = 0; i < iterations; i++)
- {
- mutex_base->acquire ();
- mutex_base->release ();
- }
-
- timer.stop ();
-
- timer.elapsed_time (et);
-
- ACE_DEBUG ((LM_DEBUG, "Mutex_Base\n"));
- ACE_DEBUG ((LM_DEBUG, "real time = %f secs, user time = %f secs, system time = %f secs\n",
- et.real_time, et.user_time, et.system_time));
-
- ACE_DEBUG ((LM_DEBUG, "time per call = %f usecs\n",
- (et.real_time / double (iterations)) * 1000000));
- return 0;
-}
-#else
-int
-main (int, char *[])
-{
- ACE_ERROR ((LM_ERROR, "threads not supported on this platform\n"));
- return 0;
-}
-#endif /* ACE_HAS_THREADS */
diff --git a/performance-tests/Misc/test_naming.cpp b/performance-tests/Misc/test_naming.cpp
deleted file mode 100644
index de4e6f2c789..00000000000
--- a/performance-tests/Misc/test_naming.cpp
+++ /dev/null
@@ -1,169 +0,0 @@
-// ============================================================================
-// $Id$
-
-//
-// = LIBRARY
-// performance_tests
-//
-// = FILENAME
-// test_naming.cpp
-//
-// = DESCRIPTION
-// This is an example to do performance testing of the Naming Service
-// using both the normal Memory Pool as well as the light Memory Pool.
-//
-// = AUTHOR
-// Prashant Jain
-//
-// ============================================================================
-
-#include "ace/SString.h"
-#include "ace/Naming_Context.h"
-#include "ace/Profile_Timer.h"
-#define ACE_NS_MAX_ENTRIES 4000
-
-static char name[BUFSIZ];
-static char value[BUFSIZ];
-static char type[BUFSIZ];
-
-void
-bind (ACE_Naming_Context *ns_context, int result)
-{
- // do the binds
- for (int i = 1; i <= ACE_NS_MAX_ENTRIES; i++)
- {
- if (i % 50 == 0)
- ACE_DEBUG ((LM_DEBUG, "."));
- sprintf (name, "%s%d", "name", i);
- ACE_WString w_name (name);
-
- sprintf (value, "%s%d", "value", i);
- ACE_WString w_value (value);
-
- sprintf (type, "%s%d", "type", i);
- ACE_ASSERT (ns_context->bind (w_name, w_value, type) == result);
- }
- ACE_DEBUG ((LM_DEBUG, "\n"));
-}
-
-void
-rebind (ACE_Naming_Context *ns_context, int result)
-{
- // do the rebinds
- for (int i = 1; i <= ACE_NS_MAX_ENTRIES; i++)
- {
- sprintf (name, "%s%d", "name", i);
- ACE_WString w_name (name);
- sprintf (value, "%s%d", "value", -i);
- ACE_WString w_value (value);
- sprintf (type, "%s%d", "type", -i);
- ACE_ASSERT (ns_context->rebind (w_name, w_value, type) == result);
- }
-}
-
-void
-unbind (ACE_Naming_Context *ns_context, int result)
-{
- // do the unbinds
- for (int i = 1; i <= ACE_NS_MAX_ENTRIES; i++)
- {
- sprintf (name, "%s%d", "name", i);
- ACE_WString w_name (name);
- ACE_ASSERT (ns_context->unbind (w_name) == result);
- }
-}
-
-void
-find (ACE_Naming_Context *ns_context, int sign, int result)
-{
- char temp_val[BUFSIZ];
- char temp_type[BUFSIZ];
-
- // do the finds
- for (int i = 1; i <= ACE_NS_MAX_ENTRIES; i++)
- {
- sprintf (name, "%s%d", "name", i);
- ACE_WString w_name (name);
-
- ACE_WString w_value;
- char *type_out;
-
- if (sign == 1)
- {
- sprintf (temp_val, "%s%d", "value", i);
- sprintf (temp_type, "%s%d", "type", i);
- }
- else
- {
- sprintf (temp_val, "%s%d", "value", -i);
- sprintf (temp_type, "%s%d", "type", -i);
- }
-
- ACE_WString val (temp_val);
-
- ACE_ASSERT (ns_context->resolve (w_name, w_value, type_out) == result);
- if (w_value.char_rep ())
- {
- ACE_ASSERT (w_value == val);
- cerr << "Name: " << name << "\tValue: " << w_value.char_rep () << "\tType: " << type_out << endl;
- if (type_out)
- {
- ACE_ASSERT (::strcmp (type_out, temp_type) == 0);
- delete[] type_out;
- }
- }
- }
-}
-
-void do_testing (int argc, char *argv[], int light)
-{
- ACE_Profile_Timer timer;
-
- ACE_Naming_Context ns_context;
- ACE_Name_Options *name_options = ns_context.name_options ();
- name_options->parse_args (argc, argv);
-
- if (light == 0) // Use SYNC
- {
- name_options->database (ACE::basename (name_options->process_name (),
- ACE_DIRECTORY_SEPARATOR_CHAR));
- ns_context.open (ACE_Naming_Context::PROC_LOCAL);
- }
- else // Use NO-SYNC
- {
- name_options->database (ACE_OS::strcat ("light", ACE::basename (name_options->process_name (),
- ACE_DIRECTORY_SEPARATOR_CHAR)));
- ns_context.open (ACE_Naming_Context::PROC_LOCAL, 1);
- }
-
- // Add bindings to the database
- ACE_DEBUG ((LM_DEBUG, "Binding\n"));
-
- timer.start ();
- bind (&ns_context, 0);
-
- ACE_DEBUG ((LM_DEBUG, "Unbinding\n"));
- unbind (&ns_context, 0);
- timer.stop ();
-
- ACE_Profile_Timer::ACE_Elapsed_Time et;
-
- timer.elapsed_time (et);
- ACE_DEBUG ((LM_DEBUG, "real time = %f secs, user time = %f secs, system time = %f secs\n",
- et.real_time, et.user_time, et.system_time));
-}
-
-int
-main (int argc, char *argv[])
-{
- // Do testing with SYNC on
- ACE_DEBUG ((LM_DEBUG, "SYNC is ON\n"));
- do_testing (argc, argv, 0);
-
- // Do testing with SYNC off
- ACE_DEBUG ((LM_DEBUG, "SYNC is OFF\n"));
- do_testing (argc, argv, 1);
-
- return 0;
-}
-
diff --git a/performance-tests/Misc/test_singleton.cpp b/performance-tests/Misc/test_singleton.cpp
deleted file mode 100644
index 4aab7492f8c..00000000000
--- a/performance-tests/Misc/test_singleton.cpp
+++ /dev/null
@@ -1,183 +0,0 @@
-// This example illustrates the performance impact of using the
-// $Id$
-
-// Double-Checked Locking pattern compared with using the "standard"
-// practice of acquiring and releasing a lock on every instance()
-// call. In addition, we compare the performance of using the
-// ACE_Singleton (which encapsulates the Double-Check Locking pattern)
-// vs. hand-coding the pattern.
-//
-// Here's the output from running this test on our SPARCstation 20, model 712s.
-//
-// ./test_singleton 1000000
-// iterations = 1000000
-// ACE_Singleton
-// real time = 0.193731 secs, user time = 0.190416 secs, system time = 0.000549 secs
-// time per call = 0.193731 usecs
-// DC_Singleton
-// real time = 0.176208 secs, user time = 0.176045 secs, system time = 0.000092 secs
-// time per call = 0.176208 usecs
-// Mutex_Singleton
-// real time = 3.160998 secs, user time = 3.121434 secs, system time = 0.000109 secs
-// time per call = 3.160998 usecs
-//
-// As you can see, both Double-Checked Locking implementations are about
-// 15 times faster than the standard mutex version. Moreover,
-// this test is run with only a single thread, so there's no contention
-// for the lock. If there were multiple threads contending for the lock,
-// the Mutex_Singleton performance would get increasing worse...
-
-#include "ace/Profile_Timer.h"
-#include "ace/Singleton.h"
-#include "ace/Synch.h"
-#include "ace/Log_Msg.h"
-
-#if defined (ACE_HAS_THREADS)
-
-static const int DEFAULT_ITERATIONS = 100000000;
-
-class Mutex_Singleton
-{
-public:
- Mutex_Singleton (void) {}
- void svc (void) {}
- static Mutex_Singleton *instance (void);
-
-private:
- static ACE_Thread_Mutex lock_;
- static Mutex_Singleton *instance_;
-};
-
-ACE_Thread_Mutex Mutex_Singleton::lock_;
-
-Mutex_Singleton *Mutex_Singleton::instance_;
-
-Mutex_Singleton *
-Mutex_Singleton::instance (void)
-{
- // Acquire the lock every time in.
- ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, Mutex_Singleton::lock_, 0);
-
- if (Mutex_Singleton::instance_ == 0)
- ACE_NEW_RETURN (Mutex_Singleton::instance_, Mutex_Singleton, 0);
-
- return Mutex_Singleton::instance_;
-}
-
-class DC_Singleton
-{
-public:
- DC_Singleton (void) {}
- void svc (void) {}
- static DC_Singleton *instance (void);
-
-private:
- static ACE_Thread_Mutex lock_;
- static DC_Singleton *instance_;
-};
-
-ACE_Thread_Mutex DC_Singleton::lock_;
-
-DC_Singleton *DC_Singleton::instance_;
-
-DC_Singleton *
-DC_Singleton::instance (void)
-{
- if (DC_Singleton::instance_ == 0)
- {
- // Only lock if instance_ isn't 0.
- ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, DC_Singleton::lock_, 0);
-
- // Perform the Double-Check.
- if (DC_Singleton::instance_ == 0)
- ACE_NEW_RETURN (DC_Singleton::instance_, DC_Singleton, 0);
- }
-
- return DC_Singleton::instance_;
-}
-
-typedef ACE_Singleton <DC_Singleton, ACE_Thread_Mutex> My_Singleton;
-
-int
-main (int argc, char *argv[])
-{
- ACE_Profile_Timer timer;
- int iterations = argc > 1 ? ACE_OS::atoi (argv[1]) : DEFAULT_ITERATIONS;
- int i;
-
- ACE_DEBUG ((LM_DEBUG, "iterations = %d\n", iterations));
-
- // Test the ACE_Singleton performance (which uses Double-Checked
- // Locking).
-
- timer.start ();
-
- for (i = 0; i < iterations; i++)
- My_Singleton::instance ()->svc ();
-
- timer.stop ();
-
- ACE_Profile_Timer::ACE_Elapsed_Time et;
-
- timer.elapsed_time (et);
-
- ACE_DEBUG ((LM_DEBUG, "ACE_Singleton\n"));
- ACE_DEBUG ((LM_DEBUG, "real time = %f secs, user time = %f secs, system time = %f secs\n",
- et.real_time, et.user_time, et.system_time));
-
- ACE_DEBUG ((LM_DEBUG, "time per call = %f usecs\n",
- (et.real_time / double (iterations)) * 1000000));
-
- // Test the hand-coded Singleton performance (which uses
- // Double-Checked Locking).
-
- timer.start ();
-
- for (i = 0; i < iterations; i++)
- DC_Singleton::instance ()->svc ();
-
- timer.stop ();
-
- timer.elapsed_time (et);
-
- ACE_DEBUG ((LM_DEBUG, "DC_Singleton\n"));
- ACE_DEBUG ((LM_DEBUG, "real time = %f secs, user time = %f secs, system time = %f secs\n",
- et.real_time, et.user_time, et.system_time));
-
- ACE_DEBUG ((LM_DEBUG, "time per call = %f usecs\n",
- (et.real_time / double (iterations)) * 1000000));
-
- // Test the Mutex_Singleton implementation (which does not use
- // Double-Checked Locking).
-
- timer.start ();
-
- for (i = 0; i < iterations; i++)
- Mutex_Singleton::instance ()->svc ();
-
- timer.stop ();
-
- timer.elapsed_time (et);
-
- ACE_DEBUG ((LM_DEBUG, "Mutex_Singleton\n"));
- ACE_DEBUG ((LM_DEBUG, "real time = %f secs, user time = %f secs, system time = %f secs\n",
- et.real_time, et.user_time, et.system_time));
-
- ACE_DEBUG ((LM_DEBUG, "time per call = %f usecs\n",
- (et.real_time / double (iterations)) * 1000000));
-
- return 0;
-}
-
-#if defined (ACE_TEMPLATES_REQUIRE_SPECIALIZATION)
-template class ACE_Singleton<DC_Singleton, ACE_Thread_Mutex>;
-#endif /* ACE_TEMPLATES_REQUIRE_SPECIALIZATION */
-
-#else
-int
-main (int, char *[])
-{
- ACE_ERROR ((LM_ERROR, "threads not supported on this platform\n"));
- return 0;
-}
-#endif /* ACE_HAS_THREADS */