3 //=============================================================================
7 * TAO optimizes octet sequences, this test verifies that the
8 * optimizations do not break any code and that they effectively
11 * @author Carlos O'Ryan
13 //=============================================================================
15 #include "ace/Get_Opt.h"
16 #include "ace/High_Res_Timer.h"
21 #include "ace/OS_NS_string.h"
24 test_write_octet (TAO_OutputCDR
&cdr
,
28 #if (TAO_NO_COPY_OCTET_SEQUENCES == 1)
29 ACE_Message_Block
mb (/* buf, */ bufsize
);
31 Test::OctetSeq
os (bufsize
, &mb
);
33 Test::OctetSeq
os (bufsize
);
35 #endif /* TAO_NO_COPY_OCTET_SEQUENCES == 1 */
44 test_read_octet (TAO_InputCDR
&cdr
,
56 test_write_char (TAO_OutputCDR
&cdr
,
60 Test::CharSeq
cs (bufsize
, bufsize
, buf
);
68 test_read_char (TAO_InputCDR
&cdr
,
80 int (*Writer
)(TAO_OutputCDR
& cdr
,
81 char* buf
, size_t bufsize
);
83 int (*Reader
)(TAO_InputCDR
& cdr
,
84 char* buf
, size_t bufsize
);
87 run (char* buf
, size_t bufsize
,
88 size_t n
, size_t lo
, size_t s
,
90 const ACE_TCHAR
* name
,
91 Writer writer
, Reader reader
)
97 for (size_t x
= lo
; x
<= bufsize
; x
+= s
)
99 ACE_High_Res_Timer writing
;
100 ACE_High_Res_Timer reading
;
102 for (size_t i
= 0; i
< n
; ++i
)
104 writing
.start_incr ();
105 TAO_OutputCDR output
;
107 if (writer (output
, buf
, x
) != 0)
109 writing
.stop_incr ();
111 TAO_InputCDR
input (output
);
112 reading
.start_incr ();
113 if (reader (input
, buf
, x
) != 0)
115 reading
.stop_incr ();
121 writing
.elapsed_time_incr (wtv
);
122 ACE_hrtime_t wusecs
= wtv
.sec ();
123 wusecs
*= static_cast<ACE_UINT32
> (ACE_ONE_SECOND_IN_USECS
);
124 wusecs
+= wtv
.usec ();
127 reading
.elapsed_time_incr (rtv
);
128 ACE_hrtime_t rusecs
= rtv
.sec ();
129 rusecs
*= static_cast<ACE_UINT32
> (ACE_ONE_SECOND_IN_USECS
);
130 rusecs
+= rtv
.usec ();
132 double write_average
= ACE_HRTIME_CONVERSION(wusecs
) / m
;
133 double read_average
= ACE_HRTIME_CONVERSION(rusecs
) / m
;
136 sum_read
+= read_average
;
137 sum_write
+= write_average
;
140 ACE_DEBUG ((LM_DEBUG
,
141 "%s: %d %.3f %.3f\n",
142 name
, x
, write_average
, read_average
));
148 ACE_DEBUG ((LM_DEBUG
,
149 "%s total: %.3f %.3f\n",
150 name
, sum_write
/ count
, sum_read
/ count
));
156 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
160 CORBA::ORB_var orb
= CORBA::ORB_init (argc
, argv
);
169 ACE_Get_Opt
get_opt (argc
, argv
, ACE_TEXT("qn:l:h:s:"));
172 while ((opt
= get_opt ()) != EOF
)
177 n
= ACE_OS::atoi (get_opt
.opt_arg ());
180 lo
= ACE_OS::atoi (get_opt
.opt_arg ());
183 hi
= ACE_OS::atoi (get_opt
.opt_arg ());
186 s
= ACE_OS::atoi (get_opt
.opt_arg ());
194 ACE_DEBUG ((LM_DEBUG
,
201 "Writes and then reads octet sequences to a CDR stream "
202 "starting from <low> up to <high> incrementing "
203 "by <step>, at each step run <n> iterations to "
211 ACE_DEBUG ((LM_DEBUG
, "Running:\n"
218 // Create a "big" buffer and fill it up.
219 char* buf
= new char[hi
];
220 CORBA::Long l
= 0xdeadbeef;
221 for (int i
= 0; i
< hi
/ (int) sizeof (l
); ++i
)
223 ACE_OS::memcpy (buf
+ sizeof (l
) * i
, &l
, sizeof (l
));
228 ACE_TEXT ("OCTET"), test_write_octet
, test_read_octet
) != 0)
233 ACE_TEXT ("CHAR"), test_write_char
, test_read_char
) != 0)
237 catch (const CORBA::Exception
& ex
)
239 ex
._tao_print_exception ("OctetSeq");