Use a variable on the stack to not have a temporary in the call
[ACE_TAO.git] / TAO / performance-tests / Sequence_Latency / Sequence_Operations_Time / test.cpp
blob0c274c3aa5c5a9e1d3de5eb21d354e9cd7937471
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;
156 } // end of str loop
157 } // end of seq loop
159 } // end of list loop
160 // end timing
161 timer.stop();
162 timer.elapsed_time(time);
164 if (use_csv)
166 ACE_DEBUG((LM_INFO,
167 ACE_TEXT("3, %u, %u, %u, %s, %Q\n"),
168 num_list_loops,
169 num_string_loops,
170 num_seq_loops,
171 use_long_str ? ACE_TEXT("long"): ACE_TEXT("short"),
172 time ));
174 else
176 ACE_DEBUG((LM_INFO,
177 ACE_TEXT("Big list test(%u, %u, %u, %s) = %Q ns\n"),
178 num_list_loops,
179 num_string_loops,
180 num_seq_loops,
181 use_long_str ? ACE_TEXT("long"): ACE_TEXT("short"),
182 time ));
187 ACE_TMAIN (int argc, ACE_TCHAR *argv[])
189 if (argc > 1 && ACE_OS::strcasecmp (argv[1],ACE_TEXT("-csv")) == 0)
190 use_csv = true;
194 stringseq_time_test(100, false);
195 stringseq_time_test(1000, false);
197 stringseq_time_test(100, true);
198 stringseq_time_test(1000, true);
201 seqstrseq_time_test(100, 1, false);
202 seqstrseq_time_test(100, 10, false);
203 seqstrseq_time_test(1000, 10, false);
205 seqstrseq_time_test(100, 1, true);
206 seqstrseq_time_test(100, 10, true);
207 seqstrseq_time_test(1000, 10, true);
210 big_time_test(10, 1, 10, false);
211 big_time_test(10, 1, 10, false);
212 big_time_test(10, 10, 10, false);
213 big_time_test(100, 1, 10, false);
215 big_time_test(10, 1, 10, true);
216 big_time_test(10, 1, 10, true);
217 big_time_test(10, 10, 10, true);
218 big_time_test(100, 1, 10, true);
220 catch (const CORBA::Exception &ex)
222 ex._tao_print_exception ("MAIN: Unexpected CORBA exception caught:");
223 return 1;
227 return 0;