Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / performance-tests / Sequence_Latency / Sequence_Operations_Time / test.cpp
blob1163c7866f31f32d32c8364e2cd630f0bbfa4d6a
1 // Test of raw copy performance when using different sequence allocations
2 #include "sequenceC.h"
3 #include "ace/Time_Value.h"
4 #include "ace/High_Res_Timer.h"
5 #include "ace/OS_NS_strings.h"
6 #include "ace/Log_Msg.h"
9 const char * short_str = "abcdefghijklmnopqrstuvwxyz";
10 const char * long_str = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ";
12 bool use_csv = false;
14 void stringseq_time_test (CORBA::ULong num_loops, bool use_long_str)
16 ACE_High_Res_Timer timer;
17 ACE_hrtime_t time;
19 CORBA::ULong str_len;
21 Str_Sequences seqs;
22 seqs.first_str.length(0);
23 seqs.second_str.length(0);
25 // start timing
26 timer.start();
28 for (CORBA::ULong idx = 0; idx < num_loops; ++idx)
30 str_len = seqs.first_str.length();
31 seqs.first_str.length(str_len + 1);
32 seqs.first_str[str_len] = use_long_str ? long_str : short_str;
34 // end timing
35 timer.stop();
36 timer.elapsed_time(time);
38 if (use_csv)
40 ACE_DEBUG((LM_INFO,
41 ACE_TEXT("1, 0, 0, %u, %s, %Q\n"),
42 num_loops,
43 use_long_str ? ACE_TEXT("long"): ACE_TEXT("short"),
44 time ));
46 else
48 ACE_DEBUG((LM_INFO,
49 ACE_TEXT("String sequence (%u, %s) = %Q ns\n"),
50 num_loops,
51 use_long_str ? ACE_TEXT("long"): ACE_TEXT("short"),
52 time ));
57 void seqstrseq_time_test (CORBA::ULong num_seq_loops,
58 CORBA::ULong num_string_loops,
59 bool use_long_str)
61 ACE_High_Res_Timer timer;
62 ACE_hrtime_t time;
64 CORBA::ULong sss_len;
65 CORBA::ULong str_len;
67 Sequence_Str_Sequences seqs;
68 seqs.seq_str_seq.length(0);
70 // start timing
71 timer.start();
73 for (CORBA::ULong seq_idx = 0; seq_idx < num_seq_loops; ++seq_idx)
75 sss_len = seqs.seq_str_seq.length();
76 seqs.seq_str_seq.length(sss_len + 1);
77 Str_Sequences & strs = seqs.seq_str_seq[sss_len];
78 //strs.first_str.length(0);
79 for (CORBA::ULong str_idx = 0; str_idx < num_string_loops; ++str_idx)
81 str_len = strs.second_str.length();
82 strs.second_str.length(str_len + 1);
83 strs.second_str[str_len] = use_long_str ? long_str : short_str;
86 // end timing
87 timer.stop();
88 timer.elapsed_time(time);
90 if (use_csv)
92 ACE_DEBUG((LM_INFO,
93 ACE_TEXT("2, 0, %u, %u, %s, %Q\n"),
94 num_string_loops,
95 num_seq_loops,
96 use_long_str ? ACE_TEXT("long"): ACE_TEXT("short"),
97 time ));
99 else
101 ACE_DEBUG((LM_INFO,
102 ACE_TEXT("Sequence of string seq (%u, %u, %s) = %Q ns\n"),
103 num_string_loops,
104 num_seq_loops,
105 use_long_str ? ACE_TEXT("long"): ACE_TEXT("short"),
106 time ));
111 void big_time_test (CORBA::ULong num_list_loops,
112 CORBA::ULong num_seq_loops,
113 CORBA::ULong num_string_loops,
114 bool use_long_str)
116 ACE_High_Res_Timer timer;
117 ACE_hrtime_t time;
119 Seq_Structs big_list;
120 big_list.seq.length(0);
122 CORBA::ULong big_len;
123 CORBA::ULong red_len;
124 CORBA::ULong sss_len;
125 CORBA::ULong str_len;
127 // start timing
128 timer.start();
130 for (CORBA::ULong list_idx = 0; list_idx < num_list_loops; ++list_idx)
132 big_len = big_list.seq.length();
133 big_list.seq.length(big_len + 1);
134 Biglist_Struct & list = big_list.seq[big_len];
136 for (CORBA::ULong seq_idx = 0; seq_idx < num_seq_loops; ++seq_idx)
138 red_len = list.red_seqs.length();
139 list.red_seqs.length(red_len + 1);
141 Sequence_Str_Sequences & sss = list.red_seqs[red_len];
143 sss_len = sss.seq_str_seq.length();
144 sss.seq_str_seq.length(sss_len + 1);
146 Str_Sequences & strs = sss.seq_str_seq[sss_len];
147 for (CORBA::ULong str_idx = 0; str_idx < num_string_loops; ++str_idx)
149 str_len = strs.second_str.length();
150 strs.second_str.length(str_len + 1);
151 strs.second_str[str_len] = use_long_str ? long_str : short_str;
153 str_len = list.strs.first_str.length();
154 list.strs.first_str.length(str_len + 1);
155 list.strs.first_str[str_len] = use_long_str ? long_str : short_str;
157 } // end of str loop
158 } // end of seq loop
160 } // end of list loop
161 // end timing
162 timer.stop();
163 timer.elapsed_time(time);
165 if (use_csv)
167 ACE_DEBUG((LM_INFO,
168 ACE_TEXT("3, %u, %u, %u, %s, %Q\n"),
169 num_list_loops,
170 num_string_loops,
171 num_seq_loops,
172 use_long_str ? ACE_TEXT("long"): ACE_TEXT("short"),
173 time ));
175 else
177 ACE_DEBUG((LM_INFO,
178 ACE_TEXT("Big list test(%u, %u, %u, %s) = %Q ns\n"),
179 num_list_loops,
180 num_string_loops,
181 num_seq_loops,
182 use_long_str ? ACE_TEXT("long"): ACE_TEXT("short"),
183 time ));
188 ACE_TMAIN (int argc, ACE_TCHAR *argv[])
191 if (argc > 1 && ACE_OS::strcasecmp (argv[1],ACE_TEXT("-csv")) == 0)
192 use_csv = true;
196 stringseq_time_test(100, false);
197 stringseq_time_test(1000, false);
199 stringseq_time_test(100, true);
200 stringseq_time_test(1000, true);
203 seqstrseq_time_test(100, 1, false);
204 seqstrseq_time_test(100, 10, false);
205 seqstrseq_time_test(1000, 10, false);
207 seqstrseq_time_test(100, 1, true);
208 seqstrseq_time_test(100, 10, true);
209 seqstrseq_time_test(1000, 10, true);
212 big_time_test(10, 1, 10, false);
213 big_time_test(10, 1, 10, false);
214 big_time_test(10, 10, 10, false);
215 big_time_test(100, 1, 10, false);
217 big_time_test(10, 1, 10, true);
218 big_time_test(10, 1, 10, true);
219 big_time_test(10, 10, 10, true);
220 big_time_test(100, 1, 10, true);
222 catch (const CORBA::Exception &ex)
224 ex._tao_print_exception ("MAIN: Unexpected CORBA exception caught:");
225 return 1;
229 return 0;