]>
git.saurik.com Git - apple/icu.git/blob - icuSources/test/perf/DateFmtPerf/DateFmtPerf.cpp
2 **********************************************************************
3 * Copyright (c) 2002-2010,International Business Machines
4 * Corporation and others. All Rights Reserved.
5 **********************************************************************
6 **********************************************************************
9 #include "DateFmtPerf.h"
17 DateFormatPerfTest::DateFormatPerfTest(int32_t argc
, const char* argv
[], UErrorCode
& status
)
18 : UPerfTest(argc
,argv
,status
) {
21 locale
= "en_US"; // set default locale
25 DateFormatPerfTest::~DateFormatPerfTest()
29 UPerfFunction
* DateFormatPerfTest::runIndexedTest(int32_t index
, UBool exec
,const char* &name
, char* par
) {
34 TESTCASE(0,DateFmt250
);
35 TESTCASE(1,DateFmt10000
);
36 TESTCASE(2,DateFmt100000
);
37 TESTCASE(3,BreakItWord250
);
38 TESTCASE(4,BreakItWord10000
);
39 TESTCASE(5,BreakItChar250
);
40 TESTCASE(6,BreakItChar10000
);
41 TESTCASE(7,NumFmt10000
);
42 TESTCASE(8,NumFmt100000
);
43 TESTCASE(9,Collation10000
);
44 TESTCASE(10,Collation100000
);
54 UPerfFunction
* DateFormatPerfTest::DateFmt250(){
55 DateFmtFunction
* func
= new DateFmtFunction(1, locale
);
59 UPerfFunction
* DateFormatPerfTest::DateFmt10000(){
60 DateFmtFunction
* func
= new DateFmtFunction(40, locale
);
64 UPerfFunction
* DateFormatPerfTest::DateFmt100000(){
65 DateFmtFunction
* func
= new DateFmtFunction(400, locale
);
69 UPerfFunction
* DateFormatPerfTest::BreakItWord250(){
70 BreakItFunction
* func
= new BreakItFunction(250, true);
74 UPerfFunction
* DateFormatPerfTest::BreakItWord10000(){
75 BreakItFunction
* func
= new BreakItFunction(10000, true);
79 UPerfFunction
* DateFormatPerfTest::BreakItChar250(){
80 BreakItFunction
* func
= new BreakItFunction(250, false);
84 UPerfFunction
* DateFormatPerfTest::BreakItChar10000(){
85 BreakItFunction
* func
= new BreakItFunction(10000, false);
89 UPerfFunction
* DateFormatPerfTest::NumFmt10000(){
90 NumFmtFunction
* func
= new NumFmtFunction(10000, locale
);
94 UPerfFunction
* DateFormatPerfTest::NumFmt100000(){
95 NumFmtFunction
* func
= new NumFmtFunction(100000, locale
);
99 UPerfFunction
* DateFormatPerfTest::Collation10000(){
100 CollationFunction
* func
= new CollationFunction(40, locale
);
104 UPerfFunction
* DateFormatPerfTest::Collation100000(){
105 CollationFunction
* func
= new CollationFunction(400, locale
);
111 int main(int argc
, const char* argv
[]){
114 if((argc
>1)&&(strcmp(argv
[1],"-x") == 0))
117 fprintf(stderr
, "Usage: %s -x <outfile>.xml\n", argv
[0]);
119 // not enough arguments
122 cout
<< "ICU version - " << U_ICU_VERSION
<< endl
;
123 UErrorCode status
= U_ZERO_ERROR
;
126 UPerfFunction
*functions
[5];
127 functions
[0] = new DateFmtFunction(40, "en");
128 functions
[1] = new BreakItFunction(10000, true); // breakIterator word
129 functions
[2] = new BreakItFunction(10000, false); // breakIterator char
130 functions
[3] = new NumFmtFunction(100000, "en");
131 functions
[4] = new CollationFunction(400, "en");
133 // Perform time recording
135 for(int i
= 0; i
< 5; i
++) t
[i
] = 0;
137 for(int i
= 0; i
< 10; i
++)
138 for(int j
= 0; j
< 5; j
++)
139 t
[j
] += (functions
[j
]->time(1, &status
) / 10);
142 // Output results as .xml
146 out
<< "<perfTestResults icu=\"c\" version=\"" << U_ICU_VERSION
<< "\">" << endl
;
148 for(int i
= 0; i
< 5; i
++)
150 out
<< " <perfTestResult" << endl
;
154 case 0: out
<< "DateFormat"; break;
155 case 1: out
<< "BreakIterator Word"; break;
156 case 2: out
<< "BreakIterator Char"; break;
157 case 3: out
<< "NumbFormat"; break;
158 case 4: out
<< "Collation"; break;
162 if(i
> 2) iter
= 100000;
163 out
<< " iterations=\"" << iter
<< "\"" << endl
;
164 out
<< " time=\"" << t
[i
] << "\" />" << endl
;
166 out
<< "</perfTestResults>" << endl
;
173 // Normal performance test mode
174 UErrorCode status
= U_ZERO_ERROR
;
176 DateFormatPerfTest
test(argc
, argv
, status
);
179 if(U_FAILURE(status
)){ // ERROR HERE!!!
180 cout
<< "initialize failed! " << status
<< endl
;
183 //cout << "Done initializing!\n" << endl;
185 if(test
.run()==FALSE
){
186 cout
<< "run failed!" << endl
;
187 fprintf(stderr
,"FAILED: Tests could not be run please check the arguments.\n");
190 cout
<< "done!" << endl
;