2 //=============================================================================
6 * Modified from anyop.cpp in Param_Test to benchmark Any insertion and
7 * extraction operators for various IDL types.
9 * @author Carlos O'Ryan Jeff Parsons
11 //=============================================================================
15 #include "tao/debug.h"
16 #include "tao/AnyTypeCode/Any.h"
18 #include "tao/Object_T.h"
19 #include "ace/Get_Opt.h"
20 #include "ace/High_Res_Timer.h"
21 #include "ace/Stats.h"
22 #include "ace/Throughput_Stats.h"
23 #include "ace/Sample_History.h"
24 #include "ace/Sched_Params.h"
27 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
30 (ACE_Sched_Params::priority_min (ACE_SCHED_FIFO
)
31 + ACE_Sched_Params::priority_max (ACE_SCHED_FIFO
)) / 2;
33 ACE_OS::sched_params (ACE_Sched_Params (ACE_SCHED_FIFO
,
42 CORBA::ORB_var orb
= CORBA::ORB_init (argc
, argv
);
44 ACE_Get_Opt
get_opt (argc
, argv
, ACE_TEXT("dien:"));
47 while ((opt
= get_opt ()) != EOF
)
61 n
= ACE_OS::atoi (get_opt
.opt_arg ());
75 CORBA::Boolean result
= 0;
79 CORBA::Object_var obj
=
80 orb
->string_to_object ("corbaloc:iiop:localhost:1234/Foo/Bar");
82 Param_Test_var param_test
=
83 TAO::Narrow_Utils
<Param_Test
>::unchecked_narrow (obj
.in ());
84 TAO_Stub
*stub
= param_test
->_stubobj ();
85 stub
->type_id
= CORBA::string_dup ("IDL:Param_Test:1.0");
87 ACE_Sample_History
history (n
);
88 ACE_hrtime_t test_start
= ACE_OS::gethrtime ();
90 for (j
= 0; j
!= n
; ++j
)
96 ACE_hrtime_t start
= ACE_OS::gethrtime ();
98 any
<<= param_test
.in ();
100 ACE_hrtime_t now
= ACE_OS::gethrtime ();
101 history
.sample (now
- start
);
109 any
<<= param_test
.in ();
113 ACE_hrtime_t start
= ACE_OS::gethrtime ();
117 ACE_hrtime_t now
= ACE_OS::gethrtime ();
118 history
.sample (now
- start
);
122 ACE_hrtime_t test_end
= ACE_OS::gethrtime ();
126 ACE_DEBUG ((LM_DEBUG
,
127 "Objref insertion test finished\n"));
131 ACE_DEBUG ((LM_DEBUG
,
132 "Objref extraction test finished\n"));
135 ACE_DEBUG ((LM_DEBUG
,
136 "High resolution timer calibration...."));
137 ACE_High_Res_Timer::global_scale_factor_type gsf
=
138 ACE_High_Res_Timer::global_scale_factor ();
139 ACE_DEBUG ((LM_DEBUG
,
142 ACE_Basic_Stats stats
;
143 history
.collect_basic_stats (stats
);
144 stats
.dump_results (ACE_TEXT("Total"), gsf
);
146 ACE_Throughput_Stats::dump_throughput (ACE_TEXT("Total"),
148 test_end
- test_start
,
149 stats
.samples_count ());
152 ACE_DEBUG ((LM_DEBUG
, "\n"));
155 ACE_Sample_History
history (n
);
156 ACE_hrtime_t test_start
= ACE_OS::gethrtime ();
158 for (j
= 0; j
!= n
; ++j
)
161 CORBA::Short i
= 123;
165 ACE_hrtime_t start
= ACE_OS::gethrtime ();
169 ACE_hrtime_t now
= ACE_OS::gethrtime ();
170 history
.sample (now
- start
);
182 ACE_hrtime_t start
= ACE_OS::gethrtime ();
186 ACE_hrtime_t now
= ACE_OS::gethrtime ();
187 history
.sample (now
- start
);
191 ACE_hrtime_t test_end
= ACE_OS::gethrtime ();
195 ACE_DEBUG ((LM_DEBUG
,
196 "Short insertion test finished\n"));
200 ACE_DEBUG ((LM_DEBUG
,
201 "Short extraction test finished\n"));
203 ACE_DEBUG ((LM_DEBUG
,
204 "High resolution timer calibration...."));
205 ACE_High_Res_Timer::global_scale_factor_type gsf
=
206 ACE_High_Res_Timer::global_scale_factor ();
207 ACE_DEBUG ((LM_DEBUG
,
210 ACE_Basic_Stats stats
;
211 history
.collect_basic_stats (stats
);
212 stats
.dump_results (ACE_TEXT("Total"), gsf
);
214 ACE_Throughput_Stats::dump_throughput (ACE_TEXT("Total"),
216 test_end
- test_start
,
217 stats
.samples_count ());
220 ACE_DEBUG ((LM_DEBUG
, "\n"));
223 ACE_Sample_History
history (n
);
224 ACE_hrtime_t test_start
= ACE_OS::gethrtime ();
226 for (j
= 0; j
!= n
; ++j
)
233 ACE_hrtime_t start
= ACE_OS::gethrtime ();
237 ACE_hrtime_t now
= ACE_OS::gethrtime ();
238 history
.sample (now
- start
);
250 ACE_hrtime_t start
= ACE_OS::gethrtime ();
254 ACE_hrtime_t now
= ACE_OS::gethrtime ();
255 history
.sample (now
- start
);
259 ACE_hrtime_t test_end
= ACE_OS::gethrtime ();
263 ACE_DEBUG ((LM_DEBUG
,
264 "Long insertion test finished\n"));
268 ACE_DEBUG ((LM_DEBUG
,
269 "Long extraction test finished\n"));
272 ACE_DEBUG ((LM_DEBUG
,
273 "High resolution timer calibration...."));
274 ACE_High_Res_Timer::global_scale_factor_type gsf
=
275 ACE_High_Res_Timer::global_scale_factor ();
276 ACE_DEBUG ((LM_DEBUG
,
279 ACE_Basic_Stats stats
;
280 history
.collect_basic_stats (stats
);
281 stats
.dump_results (ACE_TEXT("Total"), gsf
);
283 ACE_Throughput_Stats::dump_throughput (ACE_TEXT("Total"),
285 test_end
- test_start
,
286 stats
.samples_count ());
289 ACE_DEBUG ((LM_DEBUG
, "\n"));
292 ACE_Sample_History
history (n
);
293 ACE_hrtime_t test_start
= ACE_OS::gethrtime ();
295 for (j
= 0; j
!= n
; ++j
)
298 CORBA::Double i
= 123;
302 ACE_hrtime_t start
= ACE_OS::gethrtime ();
306 ACE_hrtime_t now
= ACE_OS::gethrtime ();
307 history
.sample (now
- start
);
319 ACE_hrtime_t start
= ACE_OS::gethrtime ();
323 ACE_hrtime_t now
= ACE_OS::gethrtime ();
324 history
.sample (now
- start
);
328 ACE_hrtime_t test_end
= ACE_OS::gethrtime ();
332 ACE_DEBUG ((LM_DEBUG
,
333 "Double insertion test finished\n"));
337 ACE_DEBUG ((LM_DEBUG
,
338 "Double extraction test finished\n"));
341 ACE_DEBUG ((LM_DEBUG
,
342 "High resolution timer calibration...."));
343 ACE_High_Res_Timer::global_scale_factor_type gsf
=
344 ACE_High_Res_Timer::global_scale_factor ();
345 ACE_DEBUG ((LM_DEBUG
,
348 ACE_Basic_Stats stats
;
349 history
.collect_basic_stats (stats
);
350 stats
.dump_results (ACE_TEXT("Total"), gsf
);
352 ACE_Throughput_Stats::dump_throughput (ACE_TEXT("Total"),
354 test_end
- test_start
,
355 stats
.samples_count ());
358 ACE_DEBUG ((LM_DEBUG
, "\n"));
361 Param_Test::Fixed_Struct i
;
370 ACE_Sample_History
history (n
);
371 ACE_hrtime_t test_start
= ACE_OS::gethrtime ();
373 for (j
= 0; j
!= n
; ++j
)
379 ACE_hrtime_t start
= ACE_OS::gethrtime ();
383 ACE_hrtime_t now
= ACE_OS::gethrtime ();
384 history
.sample (now
- start
);
386 const Param_Test::Fixed_Struct
*o
= 0;
394 const Param_Test::Fixed_Struct
*o
= 0;
396 ACE_hrtime_t start
= ACE_OS::gethrtime ();
400 ACE_hrtime_t now
= ACE_OS::gethrtime ();
401 history
.sample (now
- start
);
405 ACE_hrtime_t test_end
= ACE_OS::gethrtime ();
409 ACE_DEBUG ((LM_DEBUG
,
410 "Struct copying insertion test finished\n"));
414 ACE_DEBUG ((LM_DEBUG
,
415 "Struct extraction test finished\n"));
418 ACE_DEBUG ((LM_DEBUG
,
419 "High resolution timer calibration...."));
420 ACE_High_Res_Timer::global_scale_factor_type gsf
=
421 ACE_High_Res_Timer::global_scale_factor ();
422 ACE_DEBUG ((LM_DEBUG
,
425 ACE_Basic_Stats stats
;
426 history
.collect_basic_stats (stats
);
427 stats
.dump_results (ACE_TEXT("Total"), gsf
);
429 ACE_Throughput_Stats::dump_throughput (ACE_TEXT("Total"),
431 test_end
- test_start
,
432 stats
.samples_count ());
435 ACE_DEBUG ((LM_DEBUG
, "\n"));
438 ACE_Sample_History
history (n
);
439 ACE_hrtime_t test_start
= ACE_OS::gethrtime ();
440 for (j
= 0; j
!= n
; ++j
)
443 Param_Test::Fixed_Struct
*i
= 0;
445 Param_Test::Fixed_Struct
,
457 ACE_hrtime_t start
= ACE_OS::gethrtime ();
461 ACE_hrtime_t now
= ACE_OS::gethrtime ();
462 history
.sample (now
- start
);
464 const Param_Test::Fixed_Struct
*o
= 0;
472 const Param_Test::Fixed_Struct
*o
= 0;
474 ACE_hrtime_t start
= ACE_OS::gethrtime ();
478 ACE_hrtime_t now
= ACE_OS::gethrtime ();
479 history
.sample (now
- start
);
483 ACE_hrtime_t test_end
= ACE_OS::gethrtime ();
487 ACE_DEBUG ((LM_DEBUG
,
488 "Struct non-copying insertion test finished\n"));
492 ACE_DEBUG ((LM_DEBUG
,
493 "Struct extraction test finished\n"));
496 ACE_DEBUG ((LM_DEBUG
,
497 "High resolution timer calibration...."));
498 ACE_High_Res_Timer::global_scale_factor_type gsf
=
499 ACE_High_Res_Timer::global_scale_factor ();
500 ACE_DEBUG ((LM_DEBUG
,
503 ACE_Basic_Stats stats
;
504 history
.collect_basic_stats (stats
);
505 stats
.dump_results (ACE_TEXT("Total"), gsf
);
507 ACE_Throughput_Stats::dump_throughput (ACE_TEXT("Total"),
509 test_end
- test_start
,
510 stats
.samples_count ());
513 ACE_DEBUG ((LM_DEBUG
, "\n"));
516 CORBA::ULong len
= 1024;
517 Param_Test::Long_Seq
i (len
);
520 for (CORBA::ULong k
= 0; k
< len
; ++k
)
525 ACE_Sample_History
history (n
);
526 ACE_hrtime_t test_start
= ACE_OS::gethrtime ();
528 for (j
= 0; j
!= n
; ++j
)
534 ACE_hrtime_t start
= ACE_OS::gethrtime ();
538 ACE_hrtime_t now
= ACE_OS::gethrtime ();
539 history
.sample (now
- start
);
541 const Param_Test::Long_Seq
*o
= 0;
549 const Param_Test::Long_Seq
*o
= 0;
551 ACE_hrtime_t start
= ACE_OS::gethrtime ();
555 ACE_hrtime_t now
= ACE_OS::gethrtime ();
556 history
.sample (now
- start
);
560 ACE_hrtime_t test_end
= ACE_OS::gethrtime ();
564 ACE_DEBUG ((LM_DEBUG
,
565 "Sequence copying insertion test finished\n"));
569 ACE_DEBUG ((LM_DEBUG
,
570 "Sequence extraction test finished\n"));
573 ACE_DEBUG ((LM_DEBUG
,
574 "High resolution timer calibration...."));
575 ACE_High_Res_Timer::global_scale_factor_type gsf
=
576 ACE_High_Res_Timer::global_scale_factor ();
577 ACE_DEBUG ((LM_DEBUG
,
580 ACE_Basic_Stats stats
;
581 history
.collect_basic_stats (stats
);
582 stats
.dump_results (ACE_TEXT("Total"), gsf
);
584 ACE_Throughput_Stats::dump_throughput (ACE_TEXT("Total"),
586 test_end
- test_start
,
587 stats
.samples_count ());
590 ACE_DEBUG ((LM_DEBUG
, "\n"));
593 CORBA::ULong len
= 1024;
594 ACE_Sample_History
history (n
);
595 ACE_hrtime_t test_start
= ACE_OS::gethrtime ();
596 for (j
= 0; j
!= n
; ++j
)
599 Param_Test::Long_Seq
*i
= 0;
601 Param_Test::Long_Seq (len
),
605 for (CORBA::ULong k
= 0; k
< len
; ++k
)
612 ACE_hrtime_t start
= ACE_OS::gethrtime ();
616 ACE_hrtime_t now
= ACE_OS::gethrtime ();
617 history
.sample (now
- start
);
619 const Param_Test::Long_Seq
*o
= 0;
627 const Param_Test::Long_Seq
*o
= 0;
629 ACE_hrtime_t start
= ACE_OS::gethrtime ();
633 ACE_hrtime_t now
= ACE_OS::gethrtime ();
634 history
.sample (now
- start
);
638 ACE_hrtime_t test_end
= ACE_OS::gethrtime ();
642 ACE_DEBUG ((LM_DEBUG
,
643 "Sequence non-copying insertion test finished\n"));
647 ACE_DEBUG ((LM_DEBUG
,
648 "Sequence extraction test finished\n"));
651 ACE_DEBUG ((LM_DEBUG
,
652 "High resolution timer calibration...."));
653 ACE_High_Res_Timer::global_scale_factor_type gsf
=
654 ACE_High_Res_Timer::global_scale_factor ();
655 ACE_DEBUG ((LM_DEBUG
,
658 ACE_Basic_Stats stats
;
659 history
.collect_basic_stats (stats
);
660 stats
.dump_results (ACE_TEXT("Total"), gsf
);
662 ACE_Throughput_Stats::dump_throughput (ACE_TEXT("Total"),
664 test_end
- test_start
,
665 stats
.samples_count ());
668 ACE_DEBUG ((LM_DEBUG
, "\n"));
671 ACE_Sample_History
history (n
);
672 ACE_hrtime_t test_start
= ACE_OS::gethrtime ();
674 for (j
= 0; j
!= n
; ++j
)
678 i
<<= CORBA::Short (123);
682 ACE_hrtime_t start
= ACE_OS::gethrtime ();
686 ACE_hrtime_t now
= ACE_OS::gethrtime ();
687 history
.sample (now
- start
);
702 ACE_hrtime_t start
= ACE_OS::gethrtime ();
706 ACE_hrtime_t now
= ACE_OS::gethrtime ();
707 history
.sample (now
- start
);
713 ACE_hrtime_t test_end
= ACE_OS::gethrtime ();
717 ACE_DEBUG ((LM_DEBUG
,
718 "Any copying insertion test finished\n"));
722 ACE_DEBUG ((LM_DEBUG
,
723 "Any extraction test finished\n"));
726 ACE_DEBUG ((LM_DEBUG
,
727 "High resolution timer calibration...."));
728 ACE_High_Res_Timer::global_scale_factor_type gsf
=
729 ACE_High_Res_Timer::global_scale_factor ();
730 ACE_DEBUG ((LM_DEBUG
,
733 ACE_Basic_Stats stats
;
734 history
.collect_basic_stats (stats
);
735 stats
.dump_results (ACE_TEXT("Total"), gsf
);
737 ACE_Throughput_Stats::dump_throughput (ACE_TEXT("Total"),
739 test_end
- test_start
,
740 stats
.samples_count ());
743 ACE_DEBUG ((LM_DEBUG
, "\n"));
746 ACE_Sample_History
history (n
);
747 ACE_hrtime_t test_start
= ACE_OS::gethrtime ();
749 for (j
= 0; j
!= n
; ++j
)
756 *i
<<= CORBA::Short (123);
760 ACE_hrtime_t start
= ACE_OS::gethrtime ();
764 ACE_hrtime_t now
= ACE_OS::gethrtime ();
765 history
.sample (now
- start
);
780 ACE_hrtime_t start
= ACE_OS::gethrtime ();
784 ACE_hrtime_t now
= ACE_OS::gethrtime ();
785 history
.sample (now
- start
);
791 ACE_hrtime_t test_end
= ACE_OS::gethrtime ();
795 ACE_DEBUG ((LM_DEBUG
,
796 "Any non-copying insertion test finished\n"));
800 ACE_DEBUG ((LM_DEBUG
,
801 "Any extraction test finished\n"));
804 ACE_DEBUG ((LM_DEBUG
,
805 "High resolution timer calibration...."));
806 ACE_High_Res_Timer::global_scale_factor_type gsf
=
807 ACE_High_Res_Timer::global_scale_factor ();
808 ACE_DEBUG ((LM_DEBUG
,
811 ACE_Basic_Stats stats
;
812 history
.collect_basic_stats (stats
);
813 stats
.dump_results (ACE_TEXT("Total"), gsf
);
815 ACE_Throughput_Stats::dump_throughput (ACE_TEXT("Total"),
817 test_end
- test_start
,
818 stats
.samples_count ());
821 ACE_DEBUG ((LM_DEBUG
, "\n"));
824 ACE_Sample_History
history (n
);
825 ACE_hrtime_t test_start
= ACE_OS::gethrtime ();
827 for (j
= 0; j
!= n
; ++j
)
830 const char i
[] = "1234567890";
834 ACE_hrtime_t start
= ACE_OS::gethrtime ();
838 ACE_hrtime_t now
= ACE_OS::gethrtime ();
839 history
.sample (now
- start
);
851 ACE_hrtime_t start
= ACE_OS::gethrtime ();
855 ACE_hrtime_t now
= ACE_OS::gethrtime ();
856 history
.sample (now
- start
);
860 ACE_hrtime_t test_end
= ACE_OS::gethrtime ();
864 ACE_DEBUG ((LM_DEBUG
,
865 "String insertion test finished\n"));
869 ACE_DEBUG ((LM_DEBUG
,
870 "String extraction test finished\n"));
873 ACE_TEST_ASSERT (result
);
875 ACE_DEBUG ((LM_DEBUG
,
876 "High resolution timer calibration...."));
877 ACE_High_Res_Timer::global_scale_factor_type gsf
=
878 ACE_High_Res_Timer::global_scale_factor ();
879 ACE_DEBUG ((LM_DEBUG
,
882 ACE_Basic_Stats stats
;
883 history
.collect_basic_stats (stats
);
884 stats
.dump_results (ACE_TEXT("Total"), gsf
);
886 ACE_Throughput_Stats::dump_throughput (ACE_TEXT("Total"),
888 test_end
- test_start
,
889 stats
.samples_count ());
892 ACE_DEBUG ((LM_DEBUG
, "\n"));
895 ACE_Sample_History
history (n
);
896 ACE_hrtime_t test_start
= ACE_OS::gethrtime ();
898 for (j
= 0; j
!= n
; ++j
)
901 const char i
[] = "1234567890";
905 ACE_hrtime_t start
= ACE_OS::gethrtime ();
909 ACE_hrtime_t now
= ACE_OS::gethrtime ();
910 history
.sample (now
- start
);
913 ACE_hrtime_t test_end
= ACE_OS::gethrtime ();
915 ACE_DEBUG ((LM_DEBUG
,
916 "Copy test finished\n"));
917 ACE_DEBUG ((LM_DEBUG
,
918 "High resolution timer calibration...."));
919 ACE_High_Res_Timer::global_scale_factor_type gsf
=
920 ACE_High_Res_Timer::global_scale_factor ();
921 ACE_DEBUG ((LM_DEBUG
,
924 ACE_Basic_Stats stats
;
925 history
.collect_basic_stats (stats
);
926 stats
.dump_results (ACE_TEXT("Total"), gsf
);
928 ACE_Throughput_Stats::dump_throughput (ACE_TEXT("Total"),
930 test_end
- test_start
,
931 stats
.samples_count ());
934 catch (const CORBA::Exception
& ex
)
936 ex
._tao_print_exception ("Any performance test");