Merge pull request #2222 from jwillemsen/jwi-dllexportwarning
[ACE_TAO.git] / TAO / tests / CDR / growth.cpp
blobaeedbb20e12fabaa932a4ff58de10c2f3e4cc8ba
2 //=============================================================================
3 /**
4 * @file growth.cpp
6 * Helps in measuring how the growth strategy affects the
7 * performance of CDR streams.
9 * @author Carlos O'Ryan
11 //=============================================================================
14 #include "ace/Get_Opt.h"
15 #include "ace/High_Res_Timer.h"
16 #include "ace/Log_Msg.h"
18 #include "tao/ORB.h"
19 #include "tao/debug.h"
20 #include "tao/CDR.h"
21 #include "ace/OS_NS_stdio.h"
23 static int
24 test_write (TAO_OutputCDR &cdr, int n)
26 CORBA::Long l = 0xdeadbeef;
28 for (int i = 0; i < n; ++i)
30 if (cdr.write_long (l) == 0)
31 ACE_ERROR_RETURN ((LM_ERROR,
32 "write_long[%d] failed\n",
33 i),
34 1);
37 return 0;
40 static int
41 test_read (TAO_InputCDR &cdr, int n)
43 CORBA::Long xl;
45 for (int i = 0; i < n; ++i)
47 if (cdr.read_long (xl) == 0)
48 ACE_ERROR_RETURN ((LM_ERROR,
49 "read_long[%d] failed\n",
50 i),
51 1);
54 return 0;
57 int
58 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
60 int n = 100;
61 int low = 64;
62 int hi = 4096;
63 int s = 4;
64 int quiet = 0;
66 ACE_Get_Opt get_opt (argc, argv, ACE_TEXT("dn:l:h:s:q"));
67 int opt;
69 while ((opt = get_opt ()) != EOF)
71 switch (opt)
73 case 'd':
74 TAO_debug_level++;
75 break;
76 case 'n':
77 n = ACE_OS::atoi (get_opt.opt_arg ());
78 break;
79 case 'l':
80 low = ACE_OS::atoi (get_opt.opt_arg ());
81 break;
82 case 'h':
83 hi = ACE_OS::atoi (get_opt.opt_arg ());
84 break;
85 case 's':
86 s = ACE_OS::atoi (get_opt.opt_arg ());
87 break;
88 case 'q':
89 quiet = 1;
90 break;
91 case '?':
92 default:
93 ACE_DEBUG ((LM_DEBUG,
94 "Usage: %s "
95 "-d debug"
96 "-l low "
97 "-h high "
98 "-s step "
99 "-n n "
100 "\n"
101 "Writes and then reads longs to a CDR stream "
102 "starting from <low> up to <high> incrementing "
103 "by <step>, at each step run <n> iterations to "
104 "average."
105 "\n",
106 argv[0]));
107 return -1;
111 for (int x = low; x <= hi; x += s)
113 ACE_High_Res_Timer writing;
114 ACE_High_Res_Timer reading;
115 if (TAO_debug_level > 0)
116 ACE_DEBUG ((LM_DEBUG, "\nx= %d\n", x));
118 for (int i = 0; i < n; ++i)
120 writing.start_incr ();
121 TAO_OutputCDR output;
123 if (test_write (output, x) != 0)
125 return 1;
127 writing.stop_incr ();
129 reading.start_incr ();
130 TAO_InputCDR input (output);
131 if (test_read (input, x) != 0)
133 return 1;
135 reading.stop_incr ();
137 double m = n * x;
139 ACE_Time_Value wtv;
140 writing.elapsed_time_incr (wtv);
141 ACE_hrtime_t wusecs = wtv.sec ();
142 wusecs *= static_cast<ACE_UINT32> (ACE_ONE_SECOND_IN_USECS);
143 wusecs += wtv.usec ();
145 ACE_Time_Value rtv;
146 reading.elapsed_time_incr (rtv);
147 ACE_hrtime_t rusecs = rtv.sec ();
148 rusecs *= static_cast<ACE_UINT32> (ACE_ONE_SECOND_IN_USECS);
149 rusecs += rtv.usec ();
151 double write_average = ACE_HRTIME_CONVERSION(wusecs) / m;
152 double read_average = ACE_HRTIME_CONVERSION(rusecs) / m;
153 if (!quiet)
154 ACE_OS::printf ("AVE: %d %f %f\n",
155 x, write_average, read_average);
157 return 0;