2 //=============================================================================
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"
19 #include "tao/debug.h"
21 #include "ace/OS_NS_stdio.h"
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",
41 test_read (TAO_InputCDR
&cdr
, int n
)
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",
58 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
66 ACE_Get_Opt
get_opt (argc
, argv
, ACE_TEXT("dn:l:h:s:q"));
69 while ((opt
= get_opt ()) != EOF
)
77 n
= ACE_OS::atoi (get_opt
.opt_arg ());
80 low
= ACE_OS::atoi (get_opt
.opt_arg ());
83 hi
= ACE_OS::atoi (get_opt
.opt_arg ());
86 s
= ACE_OS::atoi (get_opt
.opt_arg ());
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 "
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)
127 writing
.stop_incr ();
129 reading
.start_incr ();
130 TAO_InputCDR
input (output
);
131 if (test_read (input
, x
) != 0)
135 reading
.stop_incr ();
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 ();
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
;
154 ACE_OS::printf ("AVE: %d %f %f\n",
155 x
, write_average
, read_average
);