2 ***********************************************************************
3 * © 2016 and later: Unicode, Inc. and others.
4 * License & terms of use: http://www.unicode.org/copyright.html#License
5 ***********************************************************************
6 ***********************************************************************
7 * Copyright (c) 2002-2014,International Business Machines
8 * Corporation and others. All Rights Reserved.
9 ***********************************************************************
10 ***********************************************************************
13 #include "DateFmtPerf.h"
21 DateFormatPerfTest::DateFormatPerfTest(int32_t argc
, const char* argv
[], UErrorCode
& status
)
22 : UPerfTest(argc
,argv
,status
) {
25 locale
= "en_US"; // set default locale
29 DateFormatPerfTest::~DateFormatPerfTest()
33 UPerfFunction
* DateFormatPerfTest::runIndexedTest(int32_t index
, UBool exec
,const char* &name
, char* par
) {
38 TESTCASE(0,DateFmt250
);
39 TESTCASE(1,DateFmt10000
);
40 TESTCASE(2,DateFmt100000
);
41 TESTCASE(3,BreakItWord250
);
42 TESTCASE(4,BreakItWord10000
);
43 TESTCASE(5,BreakItChar250
);
44 TESTCASE(6,BreakItChar10000
);
45 TESTCASE(7,NumFmt10000
);
46 TESTCASE(8,NumFmt100000
);
47 TESTCASE(9,Collation10000
);
48 TESTCASE(10,Collation100000
);
49 TESTCASE(11, DIFCreate250
);
50 TESTCASE(12, DIFCreate10000
);
51 TESTCASE(13, TimeZoneCreate250
);
52 TESTCASE(14, TimeZoneCreate10000
);
53 TESTCASE(15, DTPatternGeneratorCreate250
);
54 TESTCASE(16, DTPatternGeneratorCreate10000
);
55 TESTCASE(17, DTPatternGeneratorCopy250
);
56 TESTCASE(18, DTPatternGeneratorCopy10000
);
57 TESTCASE(19, DTPatternGeneratorBestValue250
);
58 TESTCASE(20, DTPatternGeneratorBestValue10000
);
59 TESTCASE(21,DateFmtCopy250
);
60 TESTCASE(22,DateFmtCopy10000
);
61 TESTCASE(23,DateFmtCreate250
);
62 TESTCASE(24,DateFmtCreate10000
);
73 UPerfFunction
* DateFormatPerfTest::DateFmt250(){
74 DateFmtFunction
* func
= new DateFmtFunction(1, locale
);
78 UPerfFunction
* DateFormatPerfTest::DateFmt10000(){
79 DateFmtFunction
* func
= new DateFmtFunction(40, locale
);
83 UPerfFunction
* DateFormatPerfTest::DateFmt100000(){
84 DateFmtFunction
* func
= new DateFmtFunction(400, locale
);
88 UPerfFunction
* DateFormatPerfTest::BreakItWord250(){
89 BreakItFunction
* func
= new BreakItFunction(250, true);
93 UPerfFunction
* DateFormatPerfTest::BreakItWord10000(){
94 BreakItFunction
* func
= new BreakItFunction(10000, true);
98 UPerfFunction
* DateFormatPerfTest::BreakItChar250(){
99 BreakItFunction
* func
= new BreakItFunction(250, false);
103 UPerfFunction
* DateFormatPerfTest::BreakItChar10000(){
104 BreakItFunction
* func
= new BreakItFunction(10000, false);
108 UPerfFunction
* DateFormatPerfTest::NumFmt10000(){
109 NumFmtFunction
* func
= new NumFmtFunction(10000, locale
);
113 UPerfFunction
* DateFormatPerfTest::NumFmt100000(){
114 NumFmtFunction
* func
= new NumFmtFunction(100000, locale
);
118 UPerfFunction
* DateFormatPerfTest::Collation10000(){
119 CollationFunction
* func
= new CollationFunction(40, locale
);
123 UPerfFunction
* DateFormatPerfTest::Collation100000(){
124 CollationFunction
* func
= new CollationFunction(400, locale
);
129 UPerfFunction
*DateFormatPerfTest::DIFCreate250() {
130 DIFCreateFunction
* func
= new DIFCreateFunction(250, locale
);
134 UPerfFunction
*DateFormatPerfTest::DIFCreate10000() {
135 DIFCreateFunction
* func
= new DIFCreateFunction(10000, locale
);
139 UPerfFunction
*DateFormatPerfTest::TimeZoneCreate250() {
140 return new TimeZoneCreateFunction(250, locale
);
143 UPerfFunction
*DateFormatPerfTest::TimeZoneCreate10000() {
144 return new TimeZoneCreateFunction(10000, locale
);
147 UPerfFunction
*DateFormatPerfTest::DTPatternGeneratorCreate250() {
148 return new DTPatternGeneratorCreateFunction(250, locale
);
151 UPerfFunction
*DateFormatPerfTest::DTPatternGeneratorCreate10000() {
152 return new DTPatternGeneratorCreateFunction(10000, locale
);
155 UPerfFunction
*DateFormatPerfTest::DTPatternGeneratorCopy250() {
156 return new DTPatternGeneratorCopyFunction(250, locale
);
159 UPerfFunction
*DateFormatPerfTest::DTPatternGeneratorCopy10000() {
160 return new DTPatternGeneratorCopyFunction(10000, locale
);
163 UPerfFunction
*DateFormatPerfTest::DTPatternGeneratorBestValue250() {
164 return new DTPatternGeneratorBestValueFunction(250, locale
);
167 UPerfFunction
*DateFormatPerfTest::DTPatternGeneratorBestValue10000() {
168 return new DTPatternGeneratorBestValueFunction(10000, locale
);
171 UPerfFunction
* DateFormatPerfTest::DateFmtCopy250(){
172 return new DateFmtCopyFunction(250, locale
);
175 UPerfFunction
* DateFormatPerfTest::DateFmtCopy10000(){
176 return new DateFmtCopyFunction(10000, locale
);
179 UPerfFunction
* DateFormatPerfTest::DateFmtCreate250(){
180 return new DateFmtCreateFunction(250, locale
);
183 UPerfFunction
* DateFormatPerfTest::DateFmtCreate10000(){
184 return new DateFmtCreateFunction(10000, locale
);
188 int main(int argc
, const char* argv
[]){
191 if((argc
>1)&&(strcmp(argv
[1],"-x") == 0))
194 fprintf(stderr
, "Usage: %s -x <outfile>.xml\n", argv
[0]);
196 // not enough arguments
199 cout
<< "ICU version - " << U_ICU_VERSION
<< endl
;
200 UErrorCode status
= U_ZERO_ERROR
;
202 #define FUNCTION_COUNT 6
204 UPerfFunction
*functions
[FUNCTION_COUNT
];
206 functions
[0] = new DateFmtFunction(40, "en");
207 functions
[1] = new BreakItFunction(10000, true); // breakIterator word
208 functions
[2] = new BreakItFunction(10000, false); // breakIterator char
209 functions
[3] = new NumFmtFunction(100000, "en");
210 functions
[4] = new CollationFunction(400, "en");
211 functions
[5] = new StdioNumFmtFunction(100000, "en");
213 // Perform time recording
214 double t
[FUNCTION_COUNT
];
215 for(int i
= 0; i
< FUNCTION_COUNT
; i
++) t
[i
] = 0;
217 #define ITER_COUNT 10
219 cout
<< "Doing " << ITER_COUNT
<< " iterations:" << endl
;
220 cout
<< "__________| Running...\r";
223 for(int i
= 0; i
< ITER_COUNT
; i
++) {
225 cout
<< '*' << flush
;
227 for(int j
= 0; U_SUCCESS(status
)&& j
< FUNCTION_COUNT
; j
++)
228 t
[j
] += (functions
[j
]->time(1, &status
) / ITER_COUNT
);
231 cout
<< " Done " << endl
;
234 if(U_SUCCESS(status
)) {
236 // Output results as .xml
240 out
<< "<perfTestResults icu=\"c\" version=\"" << U_ICU_VERSION
<< "\">" << endl
;
242 for(int i
= 0; i
< FUNCTION_COUNT
; i
++)
244 out
<< " <perfTestResult" << endl
;
248 case 0: out
<< "DateFormat"; break;
249 case 1: out
<< "BreakIterator Word"; break;
250 case 2: out
<< "BreakIterator Char"; break;
251 case 3: out
<< "NumbFormat"; break;
252 case 4: out
<< "Collation"; break;
253 case 5: out
<< "StdioNumbFormat"; break;
254 default: out
<< "Unknown " << i
; break;
257 out
<< " iterations=\"" << functions
[i
]->getOperationsPerIteration() << "\"" << endl
;
258 out
<< " time=\"" << t
[i
] << "\" />" << endl
;
260 out
<< "</perfTestResults>" << endl
;
262 cout
<< " Wrote to " << argv
[2] << endl
;
265 if(U_FAILURE(status
)) {
266 cout
<< "Error! " << u_errorName(status
) << endl
;
274 // Normal performance test mode
275 UErrorCode status
= U_ZERO_ERROR
;
277 DateFormatPerfTest
test(argc
, argv
, status
);
280 if(U_FAILURE(status
)){ // ERROR HERE!!!
281 cout
<< "initialize failed! " << u_errorName(status
) << endl
;
284 //cout << "Done initializing!\n" << endl;
286 if(test
.run()==FALSE
){
287 cout
<< "run failed!" << endl
;
288 fprintf(stderr
,"FAILED: Tests could not be run please check the arguments.\n");
291 cout
<< "done!" << endl
;