]>
git.saurik.com Git - apple/icu.git/blob - icuSources/test/perf/DateFmtPerf/DateFmtPerf.cpp
2 **********************************************************************
3 * Copyright (c) 2002-2011,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
;
125 #define FUNCTION_COUNT 6
127 UPerfFunction
*functions
[FUNCTION_COUNT
];
129 functions
[0] = new DateFmtFunction(40, "en");
130 functions
[1] = new BreakItFunction(10000, true); // breakIterator word
131 functions
[2] = new BreakItFunction(10000, false); // breakIterator char
132 functions
[3] = new NumFmtFunction(100000, "en");
133 functions
[4] = new CollationFunction(400, "en");
134 functions
[5] = new StdioNumFmtFunction(100000, "en");
136 // Perform time recording
137 double t
[FUNCTION_COUNT
];
138 for(int i
= 0; i
< FUNCTION_COUNT
; i
++) t
[i
] = 0;
140 #define ITER_COUNT 10
142 cout
<< "Doing " << ITER_COUNT
<< " iterations:" << endl
;
143 cout
<< "__________| Running...\r";
146 for(int i
= 0; i
< ITER_COUNT
; i
++) {
148 cout
<< '*' << flush
;
150 for(int j
= 0; U_SUCCESS(status
)&& j
< FUNCTION_COUNT
; j
++)
151 t
[j
] += (functions
[j
]->time(1, &status
) / ITER_COUNT
);
154 cout
<< " Done " << endl
;
157 if(U_SUCCESS(status
)) {
159 // Output results as .xml
163 out
<< "<perfTestResults icu=\"c\" version=\"" << U_ICU_VERSION
<< "\">" << endl
;
165 for(int i
= 0; i
< FUNCTION_COUNT
; i
++)
167 out
<< " <perfTestResult" << endl
;
171 case 0: out
<< "DateFormat"; break;
172 case 1: out
<< "BreakIterator Word"; break;
173 case 2: out
<< "BreakIterator Char"; break;
174 case 3: out
<< "NumbFormat"; break;
175 case 4: out
<< "Collation"; break;
176 case 5: out
<< "StdioNumbFormat"; break;
177 default: out
<< "Unknown " << i
; break;
180 out
<< " iterations=\"" << functions
[i
]->getOperationsPerIteration() << "\"" << endl
;
181 out
<< " time=\"" << t
[i
] << "\" />" << endl
;
183 out
<< "</perfTestResults>" << endl
;
185 cout
<< " Wrote to " << argv
[2] << endl
;
188 if(U_FAILURE(status
)) {
189 cout
<< "Error! " << u_errorName(status
) << endl
;
197 // Normal performance test mode
198 UErrorCode status
= U_ZERO_ERROR
;
200 DateFormatPerfTest
test(argc
, argv
, status
);
203 if(U_FAILURE(status
)){ // ERROR HERE!!!
204 cout
<< "initialize failed! " << status
<< endl
;
207 //cout << "Done initializing!\n" << endl;
209 if(test
.run()==FALSE
){
210 cout
<< "run failed!" << endl
;
211 fprintf(stderr
,"FAILED: Tests could not be run please check the arguments.\n");
214 cout
<< "done!" << endl
;