summaryrefslogtreecommitdiff
path: root/performance-tests
diff options
context:
space:
mode:
authorschmidt <douglascraigschmidt@users.noreply.github.com>1997-07-03 04:19:01 +0000
committerschmidt <douglascraigschmidt@users.noreply.github.com>1997-07-03 04:19:01 +0000
commitd942f38ab209b09c03a11715605e02a3387482b3 (patch)
tree0293890d13cb2c4bb75de1713d05ee44951806e8 /performance-tests
parentdacc4340bd79776830db8228f1736044df8a752f (diff)
downloadATCD-d942f38ab209b09c03a11715605e02a3387482b3.tar.gz
*** empty log message ***
Diffstat (limited to 'performance-tests')
-rw-r--r--performance-tests/Misc/childbirth_time.cpp312
1 files changed, 164 insertions, 148 deletions
diff --git a/performance-tests/Misc/childbirth_time.cpp b/performance-tests/Misc/childbirth_time.cpp
index a33a7e2ff02..a77e26c8df7 100644
--- a/performance-tests/Misc/childbirth_time.cpp
+++ b/performance-tests/Misc/childbirth_time.cpp
@@ -65,215 +65,231 @@
#define SUBPROGRAM "date"
#endif
-#define MULTIPLY_FACTOR 10
+const int MULTIPLY_FACTOR = 10;
typedef double (*Profiler)(int);
-int do_exec_after_fork = 0;
+static int do_exec_after_fork = 0;
-void *
+static void *
empty (void*) // do nothing thread function
{
return 0;
}
-double
+static double
prof_ace_process (int iteration)
{
- if (iteration != 0) {
- int c;
- ACE_Process_Options popt;
- ACE_Process aProcess;
- popt.command_line (SUBPROGRAM);
- iteration *= MULTIPLY_FACTOR;
+ if (iteration != 0)
+ {
+ ACE_Process_Options popt;
+ ACE_Process aProcess;
+
+ popt.command_line (SUBPROGRAM);
+
+ iteration *= MULTIPLY_FACTOR;
- if (do_exec_after_fork == 0)
- popt.creation_flags (ACE_Process_Options::NO_EXEC);
+ if (do_exec_after_fork == 0)
+ popt.creation_flags (ACE_Process_Options::NO_EXEC);
- ACE_Profile_Timer ptimer;
- ACE_Profile_Timer::ACE_Elapsed_Time et;
- double time = 0;
- pid_t result;
+ ACE_Profile_Timer ptimer;
+ ACE_Profile_Timer::ACE_Elapsed_Time et;
+ double time = 0;
+ pid_t result;
- for (c = 0; c < iteration; c++) {
- ptimer.start ();
- result = aProcess.spawn (popt);
- ptimer.stop ();
- if (result == -1) {
- ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "process.spawn"), -1);
- }
- else if (do_exec_after_fork == 0 && result == 0) {
- exit (0) ;
- }
- else {
- ptimer.elapsed_time (et);
- time += et.real_time;
- }
- }
+ for (size_t c = 0; c < iteration; c++)
+ {
+ ptimer.start ();
+ result = aProcess.spawn (popt);
+ ptimer.stop ();
+
+ if (result == -1)
+ ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "process.spawn"), -1);
+ else if (do_exec_after_fork == 0 && result == 0)
+ ACE_OS::exit (0) ;
+ else
+ {
+ ptimer.elapsed_time (et);
+ time += et.real_time;
+ }
+ }
- return time / iteration;
- }
+ return time / iteration;
+ }
else
- return -1.;
+ return -1.0;
}
-double
+static double
prof_fork (int iteration)
{
#if !defined (ACE_LACKS_EXEC)
- if (iteration != 0) {
- ACE_Profile_Timer ptimer;
- ACE_Profile_Timer::ACE_Elapsed_Time et;
- double time = 0;
- int i;
- iteration *= MULTIPLY_FACTOR;
+ if (iteration != 0)
+ {
+ ACE_Profile_Timer ptimer;
+ ACE_Profile_Timer::ACE_Elapsed_Time et;
+ double time = 0;
+
+ iteration *= MULTIPLY_FACTOR;
- for (i = 0; i < iteration; i++) {
- ptimer.start ();
- switch (ACE_OS::fork ()) {
- case -1:
- ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "process.spawn"), -1);
- break;
- case 0:
- exit (0);
- break;
- default:
- ptimer.stop ();
- ptimer.elapsed_time (et);
- time += et.real_time;
- }
+ for (size_t i = 0; i < iteration; i++)
+ {
+ ptimer.start ();
+ switch (ACE_OS::fork ())
+ {
+ case -1:
+ ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "process.spawn"), -1);
+ break;
+ case 0:
+ exit (0);
+ break;
+ default:
+ ptimer.stop ();
+ ptimer.elapsed_time (et);
+ time += et.real_time;
+ }
+ }
+ return time / iteration;
}
- return time / iteration;
- }
else
- return -1.;
+ return -1.0;
#else
ACE_ERROR_RETURN ((LM_ERROR, "fork () is not supported on this platform."), -1);
#endif
}
-double
+static double
prof_native_thread (int iteration)
{
#if defined (ACE_HAS_THREADS) && (defined (ACE_HAS_WTHREADS) || defined (ACE_HAS_STHREADS))
- if (iteration != 0) {
- ACE_Profile_Timer ptimer;
- ACE_Profile_Timer::ACE_Elapsed_Time et;
- double time = 0;
- int i, j;
+ if (iteration != 0)
+ {
+ ACE_Profile_Timer ptimer;
+ ACE_Profile_Timer::ACE_Elapsed_Time et;
+ double time = 0;
- for (i = 0; i < iteration; i++) {
- ptimer.start ();
- for (j = 0; j < MULTIPLY_FACTOR; j++) {
+ for (size_t i = 0; i < iteration; i++)
+ {
+ ptimer.start ();
+ for (size_T j = 0; j < MULTIPLY_FACTOR; j++)
+ {
#if defined (ACE_HAS_WTHREADS)
- if (::CreateThread (NULL,
- 0,
- LPTHREAD_START_ROUTINE (empty),
- 0,
- CREATE_SUSPENDED,
- 0) == NULL)
+ if (::CreateThread (NULL,
+ 0,
+ LPTHREAD_START_ROUTINE (empty),
+ 0,
+ CREATE_SUSPENDED,
+ 0) == NULL)
#elif defined (ACE_HAS_STHREADS)
- if (::thr_create (NULL,
- 0,
- empty,
- 0,
- THR_SUSPENDED,
- NULL) != 0)
+ if (::thr_create (NULL,
+ 0,
+ empty,
+ 0,
+ THR_SUSPENDED,
+ NULL) != 0)
#endif
- ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "CreateThread"), -1);
- }
- ptimer.stop ();
- ptimer.elapsed_time (et);
- time += et.real_time;
+ ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "CreateThread"), -1);
+ }
+ ptimer.stop ();
+ ptimer.elapsed_time (et);
+ time += et.real_time;
+ }
+ iteration *= MULTIPLY_FACTOR;
+ return time / iteration;
}
- iteration *= MULTIPLY_FACTOR;
- return time / iteration;
- }
else
- return -1.;
+ return -1.0;
#else
ACE_ERROR_RETURN ((LM_ERROR, "Testing of native threads is not supported on this platform."), -1);
#endif
}
-double
+static double
prof_ace_os_thread (int iteration)
{
#if defined (ACE_HAS_THREADS)
- if (iteration != 0) {
- ACE_Profile_Timer ptimer;
- ACE_Profile_Timer::ACE_Elapsed_Time et;
- double time = 0;
- int i, j;
-
- for (i = 0; i < iteration; i++) {
- ptimer.start ();
- for (j = 0; j < MULTIPLY_FACTOR; j++) {
- if (ACE_OS::thr_create (empty,
- 0,
- THR_SUSPENDED,
- NULL) == -1)
- ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "CreateThread"), -1);
- }
- ptimer.stop ();
- ptimer.elapsed_time (et);
- time += et.real_time;
+ if (iteration != 0)
+ {
+ ACE_Profile_Timer ptimer;
+ ACE_Profile_Timer::ACE_Elapsed_Time et;
+ double time = 0;
+
+ for (size_t i = 0; i < iteration; i++)
+ {
+ ptimer.start ();
+
+ for (size_t j == 0; j < MULTIPLY_FACTOR; j++)
+ if (ACE_OS::thr_create (empty,
+ 0,
+ THR_SUSPENDED,
+ NULL) == -1)
+ ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "CreateThread"), -1);
+
+ ptimer.stop ();
+ ptimer.elapsed_time (et);
+ time += et.real_time;
+ }
+ iteration *= MULTIPLY_FACTOR;
+ return time / iteration;
}
- iteration *= MULTIPLY_FACTOR;
- return time / iteration;
- }
else
- return -1.;
+ return -1.0;
#else
ACE_ERROR_RETURN ((LM_ERROR, "Threads are not supported on this platform."), -1);
#endif
}
-int main(int argc, char* argv[]) {
+int
+main (int argc, char* argv[])
+{
ACE_Get_Opt get_opt (argc, argv, "n:pftahe");
int c;
int iteration = 10;
Profiler profiler = 0;
char *profile_name = 0 ;
- while ((c=get_opt ()) != -1) {
- switch (c) {
- case 'n':
- iteration = ACE_OS::atoi (get_opt.optarg);
- break;
- case 'p': // *DON'T* test ACE_Process.spawn ()
- profiler = prof_ace_process;
- profile_name = "ACE_Process.spawn ()";
- break;
- case 'f': // test fork ()
- profiler = prof_fork;
- profile_name = "fork ()";
- break;
- case 't': // test native thread creation
- profiler = prof_native_thread;
- profile_name = "native threads";
- break;
- case 'a': // test ACE_OS::thr_create
- profiler = prof_ace_os_thread;
- profile_name = "ACE_OS::thr_create ()";
- break;
- case 'h': // use high resolution timer
- ACE_High_Res_Timer::get_env_global_scale_factor ();
- break;
- case 'e':
- do_exec_after_fork = 1;
- break;
- default:
- break;
+ while ((c=get_opt ()) != -1)
+ {
+ switch (c)
+ {
+ case 'n':
+ iteration = ACE_OS::atoi (get_opt.optarg);
+ break;
+ case 'p': // *DON'T* test ACE_Process.spawn ()
+ profiler = prof_ace_process;
+ profile_name = "ACE_Process.spawn ()";
+ break;
+ case 'f': // test fork ()
+ profiler = prof_fork;
+ profile_name = "fork ()";
+ break;
+ case 't': // test native thread creation
+ profiler = prof_native_thread;
+ profile_name = "native threads";
+ break;
+ case 'a': // test ACE_OS::thr_create
+ profiler = prof_ace_os_thread;
+ profile_name = "ACE_OS::thr_create ()";
+ break;
+ case 'h': // use high resolution timer
+ ACE_High_Res_Timer::get_env_global_scale_factor ();
+ break;
+ case 'e':
+ do_exec_after_fork = 1;
+ break;
+ default:
+ break;
+ }
}
- }
+
if (profiler == 0)
ACE_ERROR_RETURN ((LM_ERROR, "Usage: profile_childbirth {-p|-f|-t|-a} [-n ###] [-h] [-e]\n"), 1);
- else {
- double time = profiler (iteration);
- if (time > 0) {
- ACE_DEBUG ((LM_DEBUG, "Average performance of %d iterations of %s: %.0f usec\n",
- iteration * 10, profile_name, time * 1e6));
+ else
+ {
+ double time = profiler (iteration);
+ if (time > 0)
+ ACE_DEBUG ((LM_DEBUG,
+ "Average performance of %d iterations of %s: %.0f usec\n",
+ iteration * 10, profile_name, time * 1e6));
}
- }
return 0;
}