]>
Commit | Line | Data |
---|---|---|
729e4ab9 A |
1 | /* |
2 | ********************************************************************** | |
b331163b | 3 | * Copyright (c) 2002-2014,International Business Machines |
729e4ab9 A |
4 | * Corporation and others. All Rights Reserved. |
5 | ********************************************************************** | |
6 | ********************************************************************** | |
7 | */ | |
8 | ||
9 | #include "DateFmtPerf.h" | |
10 | #include "uoptions.h" | |
11 | #include <stdio.h> | |
12 | #include <fstream> | |
13 | ||
14 | #include <iostream> | |
15 | using namespace std; | |
16 | ||
17 | DateFormatPerfTest::DateFormatPerfTest(int32_t argc, const char* argv[], UErrorCode& status) | |
18 | : UPerfTest(argc,argv,status) { | |
19 | ||
20 | if (locale == NULL){ | |
21 | locale = "en_US"; // set default locale | |
22 | } | |
23 | } | |
24 | ||
25 | DateFormatPerfTest::~DateFormatPerfTest() | |
26 | { | |
27 | } | |
28 | ||
29 | UPerfFunction* DateFormatPerfTest::runIndexedTest(int32_t index, UBool exec,const char* &name, char* par) { | |
30 | ||
31 | //exec = true; | |
32 | ||
33 | switch (index) { | |
34 | TESTCASE(0,DateFmt250); | |
35 | TESTCASE(1,DateFmt10000); | |
4388f060 | 36 | TESTCASE(2,DateFmt100000); |
729e4ab9 | 37 | TESTCASE(3,BreakItWord250); |
4388f060 A |
38 | TESTCASE(4,BreakItWord10000); |
39 | TESTCASE(5,BreakItChar250); | |
40 | TESTCASE(6,BreakItChar10000); | |
729e4ab9 A |
41 | TESTCASE(7,NumFmt10000); |
42 | TESTCASE(8,NumFmt100000); | |
43 | TESTCASE(9,Collation10000); | |
44 | TESTCASE(10,Collation100000); | |
b331163b A |
45 | TESTCASE(11, DIFCreate250); |
46 | TESTCASE(12, DIFCreate10000); | |
47 | TESTCASE(13, TimeZoneCreate250); | |
48 | TESTCASE(14, TimeZoneCreate10000); | |
49 | TESTCASE(15, DTPatternGeneratorCreate250); | |
50 | TESTCASE(16, DTPatternGeneratorCreate10000); | |
51 | TESTCASE(17, DTPatternGeneratorCopy250); | |
52 | TESTCASE(18, DTPatternGeneratorCopy10000); | |
53 | TESTCASE(19, DTPatternGeneratorBestValue250); | |
54 | TESTCASE(20, DTPatternGeneratorBestValue10000); | |
55 | TESTCASE(21,DateFmtCopy250); | |
56 | TESTCASE(22,DateFmtCopy10000); | |
57 | TESTCASE(23,DateFmtCreate250); | |
58 | TESTCASE(24,DateFmtCreate10000); | |
59 | ||
729e4ab9 A |
60 | |
61 | default: | |
62 | name = ""; | |
63 | return NULL; | |
64 | } | |
65 | return NULL; | |
66 | } | |
67 | ||
68 | ||
69 | UPerfFunction* DateFormatPerfTest::DateFmt250(){ | |
70 | DateFmtFunction* func= new DateFmtFunction(1, locale); | |
71 | return func; | |
72 | } | |
73 | ||
74 | UPerfFunction* DateFormatPerfTest::DateFmt10000(){ | |
75 | DateFmtFunction* func= new DateFmtFunction(40, locale); | |
76 | return func; | |
77 | } | |
78 | ||
79 | UPerfFunction* DateFormatPerfTest::DateFmt100000(){ | |
80 | DateFmtFunction* func= new DateFmtFunction(400, locale); | |
81 | return func; | |
82 | } | |
83 | ||
84 | UPerfFunction* DateFormatPerfTest::BreakItWord250(){ | |
85 | BreakItFunction* func= new BreakItFunction(250, true); | |
86 | return func; | |
87 | } | |
88 | ||
89 | UPerfFunction* DateFormatPerfTest::BreakItWord10000(){ | |
90 | BreakItFunction* func= new BreakItFunction(10000, true); | |
91 | return func; | |
92 | } | |
93 | ||
94 | UPerfFunction* DateFormatPerfTest::BreakItChar250(){ | |
95 | BreakItFunction* func= new BreakItFunction(250, false); | |
96 | return func; | |
97 | } | |
98 | ||
99 | UPerfFunction* DateFormatPerfTest::BreakItChar10000(){ | |
100 | BreakItFunction* func= new BreakItFunction(10000, false); | |
101 | return func; | |
102 | } | |
103 | ||
104 | UPerfFunction* DateFormatPerfTest::NumFmt10000(){ | |
105 | NumFmtFunction* func= new NumFmtFunction(10000, locale); | |
106 | return func; | |
107 | } | |
108 | ||
109 | UPerfFunction* DateFormatPerfTest::NumFmt100000(){ | |
110 | NumFmtFunction* func= new NumFmtFunction(100000, locale); | |
111 | return func; | |
112 | } | |
113 | ||
114 | UPerfFunction* DateFormatPerfTest::Collation10000(){ | |
115 | CollationFunction* func= new CollationFunction(40, locale); | |
116 | return func; | |
117 | } | |
118 | ||
119 | UPerfFunction* DateFormatPerfTest::Collation100000(){ | |
120 | CollationFunction* func= new CollationFunction(400, locale); | |
121 | return func; | |
122 | } | |
123 | ||
124 | ||
b331163b A |
125 | UPerfFunction *DateFormatPerfTest::DIFCreate250() { |
126 | DIFCreateFunction* func = new DIFCreateFunction(250, locale); | |
127 | return func; | |
128 | } | |
129 | ||
130 | UPerfFunction *DateFormatPerfTest::DIFCreate10000() { | |
131 | DIFCreateFunction* func = new DIFCreateFunction(10000, locale); | |
132 | return func; | |
133 | } | |
134 | ||
135 | UPerfFunction *DateFormatPerfTest::TimeZoneCreate250() { | |
136 | return new TimeZoneCreateFunction(250, locale); | |
137 | } | |
138 | ||
139 | UPerfFunction *DateFormatPerfTest::TimeZoneCreate10000() { | |
140 | return new TimeZoneCreateFunction(10000, locale); | |
141 | } | |
142 | ||
143 | UPerfFunction *DateFormatPerfTest::DTPatternGeneratorCreate250() { | |
144 | return new DTPatternGeneratorCreateFunction(250, locale); | |
145 | } | |
146 | ||
147 | UPerfFunction *DateFormatPerfTest::DTPatternGeneratorCreate10000() { | |
148 | return new DTPatternGeneratorCreateFunction(10000, locale); | |
149 | } | |
150 | ||
151 | UPerfFunction *DateFormatPerfTest::DTPatternGeneratorCopy250() { | |
152 | return new DTPatternGeneratorCopyFunction(250, locale); | |
153 | } | |
154 | ||
155 | UPerfFunction *DateFormatPerfTest::DTPatternGeneratorCopy10000() { | |
156 | return new DTPatternGeneratorCopyFunction(10000, locale); | |
157 | } | |
158 | ||
159 | UPerfFunction *DateFormatPerfTest::DTPatternGeneratorBestValue250() { | |
160 | return new DTPatternGeneratorBestValueFunction(250, locale); | |
161 | } | |
162 | ||
163 | UPerfFunction *DateFormatPerfTest::DTPatternGeneratorBestValue10000() { | |
164 | return new DTPatternGeneratorBestValueFunction(10000, locale); | |
165 | } | |
166 | ||
167 | UPerfFunction* DateFormatPerfTest::DateFmtCopy250(){ | |
168 | return new DateFmtCopyFunction(250, locale); | |
169 | } | |
170 | ||
171 | UPerfFunction* DateFormatPerfTest::DateFmtCopy10000(){ | |
172 | return new DateFmtCopyFunction(10000, locale); | |
173 | } | |
174 | ||
175 | UPerfFunction* DateFormatPerfTest::DateFmtCreate250(){ | |
176 | return new DateFmtCreateFunction(250, locale); | |
177 | } | |
178 | ||
179 | UPerfFunction* DateFormatPerfTest::DateFmtCreate10000(){ | |
180 | return new DateFmtCreateFunction(10000, locale); | |
181 | } | |
182 | ||
729e4ab9 A |
183 | |
184 | int main(int argc, const char* argv[]){ | |
185 | ||
186 | // -x Filename.xml | |
187 | if((argc>1)&&(strcmp(argv[1],"-x") == 0)) | |
188 | { | |
189 | if(argc < 3) { | |
190 | fprintf(stderr, "Usage: %s -x <outfile>.xml\n", argv[0]); | |
191 | return 1; | |
192 | // not enough arguments | |
193 | } | |
194 | ||
195 | cout << "ICU version - " << U_ICU_VERSION << endl; | |
196 | UErrorCode status = U_ZERO_ERROR; | |
197 | ||
4388f060 | 198 | #define FUNCTION_COUNT 6 |
729e4ab9 | 199 | // Declare functions |
4388f060 A |
200 | UPerfFunction *functions[FUNCTION_COUNT]; |
201 | ||
729e4ab9 A |
202 | functions[0] = new DateFmtFunction(40, "en"); |
203 | functions[1] = new BreakItFunction(10000, true); // breakIterator word | |
204 | functions[2] = new BreakItFunction(10000, false); // breakIterator char | |
205 | functions[3] = new NumFmtFunction(100000, "en"); | |
206 | functions[4] = new CollationFunction(400, "en"); | |
4388f060 | 207 | functions[5] = new StdioNumFmtFunction(100000, "en"); |
729e4ab9 | 208 | |
4388f060 A |
209 | // Perform time recording |
210 | double t[FUNCTION_COUNT]; | |
211 | for(int i = 0; i < FUNCTION_COUNT; i++) t[i] = 0; | |
212 | ||
213 | #define ITER_COUNT 10 | |
214 | #ifdef U_DEBUG | |
215 | cout << "Doing " << ITER_COUNT << " iterations:" << endl; | |
216 | cout << "__________| Running...\r"; | |
217 | cout.flush(); | |
218 | #endif | |
219 | for(int i = 0; i < ITER_COUNT; i++) { | |
220 | #ifdef U_DEBUG | |
221 | cout << '*' << flush; | |
222 | #endif | |
223 | for(int j = 0; U_SUCCESS(status)&& j < FUNCTION_COUNT; j++) | |
224 | t[j] += (functions[j]->time(1, &status) / ITER_COUNT); | |
225 | } | |
226 | #ifdef U_DEBUG | |
227 | cout << " Done " << endl; | |
228 | #endif | |
729e4ab9 | 229 | |
4388f060 | 230 | if(U_SUCCESS(status)) { |
729e4ab9 | 231 | |
4388f060 A |
232 | // Output results as .xml |
233 | ofstream out; | |
234 | out.open(argv[2]); | |
729e4ab9 | 235 | |
4388f060 | 236 | out << "<perfTestResults icu=\"c\" version=\"" << U_ICU_VERSION << "\">" << endl; |
729e4ab9 | 237 | |
4388f060 | 238 | for(int i = 0; i < FUNCTION_COUNT; i++) |
729e4ab9 | 239 | { |
4388f060 A |
240 | out << " <perfTestResult" << endl; |
241 | out << " test=\""; | |
242 | switch(i) | |
243 | { | |
729e4ab9 A |
244 | case 0: out << "DateFormat"; break; |
245 | case 1: out << "BreakIterator Word"; break; | |
246 | case 2: out << "BreakIterator Char"; break; | |
247 | case 3: out << "NumbFormat"; break; | |
248 | case 4: out << "Collation"; break; | |
4388f060 A |
249 | case 5: out << "StdioNumbFormat"; break; |
250 | default: out << "Unknown " << i; break; | |
251 | } | |
252 | out << "\"" << endl; | |
253 | out << " iterations=\"" << functions[i]->getOperationsPerIteration() << "\"" << endl; | |
254 | out << " time=\"" << t[i] << "\" />" << endl; | |
729e4ab9 | 255 | } |
4388f060 A |
256 | out << "</perfTestResults>" << endl; |
257 | out.close(); | |
258 | cout << " Wrote to " << argv[2] << endl; | |
259 | } | |
260 | ||
261 | if(U_FAILURE(status)) { | |
262 | cout << "Error! " << u_errorName(status) << endl; | |
263 | return 1; | |
729e4ab9 | 264 | } |
729e4ab9 A |
265 | |
266 | return 0; | |
267 | } | |
268 | ||
269 | ||
270 | // Normal performance test mode | |
271 | UErrorCode status = U_ZERO_ERROR; | |
272 | ||
273 | DateFormatPerfTest test(argc, argv, status); | |
274 | ||
275 | ||
276 | if(U_FAILURE(status)){ // ERROR HERE!!! | |
277 | cout << "initialize failed! " << status << endl; | |
278 | return status; | |
279 | } | |
280 | //cout << "Done initializing!\n" << endl; | |
281 | ||
282 | if(test.run()==FALSE){ | |
283 | cout << "run failed!" << endl; | |
284 | fprintf(stderr,"FAILED: Tests could not be run please check the arguments.\n"); | |
285 | return -1; | |
286 | } | |
287 | cout << "done!" << endl; | |
288 | ||
289 | return 0; | |
4388f060 | 290 | } |