1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
|
// $Id$
// ============================================================================
//
// = LIBRARY
// TAO/tests/OctetSeq
//
// = FILENAME
// octetseq.cpp
//
// = DESCRIPTION
// TAO optimizes octet sequences, this test verifies that the
// optimizations do not break any code and that they effectively
// improve performance.
//
// = AUTHORS
// Carlos O'Ryan
//
// ============================================================================
#include "ace/Get_Opt.h"
#include "ace/High_Res_Timer.h"
#include "tao/ORB.h"
#include "tao/CDR.h"
#include "testC.h"
#include "ace/OS_NS_string.h"
ACE_RCSID(OctetSeq, OctetSeq, "$Id$")
static int
test_write_octet (TAO_OutputCDR &cdr,
char* /* buf */,
size_t bufsize)
{
#if (TAO_NO_COPY_OCTET_SEQUENCES == 1)
ACE_Message_Block mb (/* buf, */ bufsize);
mb.wr_ptr (bufsize);
Test::OctetSeq os (bufsize, &mb);
#else
Test::OctetSeq os (bufsize);
os.length (bufsize);
#endif /* TAO_NO_COPY_OCTET_SEQUENCES == 1 */
if ((cdr << os) == 0)
return -1;
return 0;
}
static int
test_read_octet (TAO_InputCDR &cdr,
char* /* buf */,
size_t /* bufsize */)
{
Test::OctetSeq os;
if ((cdr >> os) == 0)
return -1;
return 0;
}
static int
test_write_char (TAO_OutputCDR &cdr,
char* buf,
size_t bufsize)
{
Test::CharSeq cs (bufsize, bufsize, buf);
if ((cdr << cs) == 0)
return -1;
return 0;
}
static int
test_read_char (TAO_InputCDR &cdr,
char* /* buf */,
size_t /* bufsize */)
{
Test::CharSeq cs;
if ((cdr >> cs) == 0)
return -1;
return 0;
}
typedef
int (*Writer)(TAO_OutputCDR& cdr,
char* buf, size_t bufsize);
typedef
int (*Reader)(TAO_InputCDR& cdr,
char* buf, size_t bufsize);
int
run (char* buf, size_t bufsize,
size_t n, size_t lo, size_t s,
int quiet,
const char* name,
Writer writer, Reader reader)
{
size_t count = 0;
double sum_read = 0;
double sum_write = 0;
for (size_t x = lo; x <= bufsize; x += s)
{
ACE_High_Res_Timer writing;
ACE_High_Res_Timer reading;
for (size_t i = 0; i < n; ++i)
{
writing.start_incr ();
TAO_OutputCDR output;
if (writer (output, buf, x) != 0)
return -1;
writing.stop_incr ();
TAO_InputCDR input (output);
reading.start_incr ();
if (reader (input, buf, x) != 0)
return -1;
reading.stop_incr ();
}
double m = n;
ACE_Time_Value wtv;
writing.elapsed_time_incr (wtv);
ACE_hrtime_t wusecs = wtv.sec ();
wusecs *= static_cast<ACE_UINT32> (ACE_ONE_SECOND_IN_USECS);
wusecs += wtv.usec ();
ACE_Time_Value rtv;
reading.elapsed_time_incr (rtv);
ACE_hrtime_t rusecs = rtv.sec ();
rusecs *= static_cast<ACE_UINT32> (ACE_ONE_SECOND_IN_USECS);
rusecs += rtv.usec ();
double write_average = ACE_HRTIME_CONVERSION(wusecs) / m;
double read_average = ACE_HRTIME_CONVERSION(rusecs) / m;
count++;
sum_read += read_average;
sum_write += write_average;
if (quiet == 0)
{
ACE_DEBUG ((LM_DEBUG,
"%s: %d %.3f %.3f\n",
name, x, write_average, read_average));
}
}
if (count != 0)
{
ACE_DEBUG ((LM_DEBUG,
"%s total: %.3f %.3f\n",
name, sum_write / count, sum_read / count));
}
return 0;
}
int
main (int argc, char *argv[])
{
ACE_DECLARE_NEW_CORBA_ENV;
ACE_TRY
{
CORBA::ORB_var orb = CORBA::ORB_init (argc,
argv,
0
ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
int n = 64;
int lo = 128;
int hi = 65536;
int s = 32;
int quiet = 0;
ACE_Get_Opt get_opt (argc, argv, "qn:l:h:s:");
int opt;
while ((opt = get_opt ()) != EOF)
{
switch (opt)
{
case 'n':
n = ACE_OS::atoi (get_opt.opt_arg ());
break;
case 'l':
lo = ACE_OS::atoi (get_opt.opt_arg ());
break;
case 'h':
hi = ACE_OS::atoi (get_opt.opt_arg ());
break;
case 's':
s = ACE_OS::atoi (get_opt.opt_arg ());
break;
case 'q':
quiet = 1;
break;
case '?':
default:
ACE_DEBUG ((LM_DEBUG,
"Usage: %s "
"-l low "
"-h high "
"-s step "
"-n n "
"\n"
"Writes and then reads octet sequences to a CDR stream "
"starting from <low> up to <high> incrementing "
"by <step>, at each step run <n> iterations to "
"average."
"\n",
argv[0]));
return -1;
}
}
ACE_DEBUG ((LM_DEBUG, "Running:\n"
" low: %d\n"
" hi : %d\n"
" s : %d\n"
" n : %d\n",
lo, hi, s, n));
// Create a "big" buffer and fill it up.
char* buf = new char[hi];
CORBA::Long l = 0xdeadbeef;
for (int i = 0; i < hi / (int) sizeof (l); ++i)
{
ACE_OS::memcpy (buf + sizeof (l) * i, &l, sizeof (l));
}
if (run (buf, hi,
n, lo, s, quiet,
"OCTET", test_write_octet, test_read_octet) != 0)
return 1;
if (run (buf, hi,
n, lo, s, quiet,
"CHAR", test_write_char, test_read_char) != 0)
return 1;
delete[] buf;
}
ACE_CATCHANY
{
ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "OctetSeq");
}
ACE_ENDTRY;
return 0;
}
|