2 **********************************************************************
3 * Copyright (c) 2002-2014,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
);
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
);
69 UPerfFunction
* DateFormatPerfTest::DateFmt250(){
70 DateFmtFunction
* func
= new DateFmtFunction(1, locale
);
74 UPerfFunction
* DateFormatPerfTest::DateFmt10000(){
75 DateFmtFunction
* func
= new DateFmtFunction(40, locale
);
79 UPerfFunction
* DateFormatPerfTest::DateFmt100000(){
80 DateFmtFunction
* func
= new DateFmtFunction(400, locale
);
84 UPerfFunction
* DateFormatPerfTest::BreakItWord250(){
85 BreakItFunction
* func
= new BreakItFunction(250, true);
89 UPerfFunction
* DateFormatPerfTest::BreakItWord10000(){
90 BreakItFunction
* func
= new BreakItFunction(10000, true);
94 UPerfFunction
* DateFormatPerfTest::BreakItChar250(){
95 BreakItFunction
* func
= new BreakItFunction(250, false);
99 UPerfFunction
* DateFormatPerfTest::BreakItChar10000(){
100 BreakItFunction
* func
= new BreakItFunction(10000, false);
104 UPerfFunction
* DateFormatPerfTest::NumFmt10000(){
105 NumFmtFunction
* func
= new NumFmtFunction(10000, locale
);
109 UPerfFunction
* DateFormatPerfTest::NumFmt100000(){
110 NumFmtFunction
* func
= new NumFmtFunction(100000, locale
);
114 UPerfFunction
* DateFormatPerfTest::Collation10000(){
115 CollationFunction
* func
= new CollationFunction(40, locale
);
119 UPerfFunction
* DateFormatPerfTest::Collation100000(){
120 CollationFunction
* func
= new CollationFunction(400, locale
);
125 UPerfFunction
*DateFormatPerfTest::DIFCreate250() {
126 DIFCreateFunction
* func
= new DIFCreateFunction(250, locale
);
130 UPerfFunction
*DateFormatPerfTest::DIFCreate10000() {
131 DIFCreateFunction
* func
= new DIFCreateFunction(10000, locale
);
135 UPerfFunction
*DateFormatPerfTest::TimeZoneCreate250() {
136 return new TimeZoneCreateFunction(250, locale
);
139 UPerfFunction
*DateFormatPerfTest::TimeZoneCreate10000() {
140 return new TimeZoneCreateFunction(10000, locale
);
143 UPerfFunction
*DateFormatPerfTest::DTPatternGeneratorCreate250() {
144 return new DTPatternGeneratorCreateFunction(250, locale
);
147 UPerfFunction
*DateFormatPerfTest::DTPatternGeneratorCreate10000() {
148 return new DTPatternGeneratorCreateFunction(10000, locale
);
151 UPerfFunction
*DateFormatPerfTest::DTPatternGeneratorCopy250() {
152 return new DTPatternGeneratorCopyFunction(250, locale
);
155 UPerfFunction
*DateFormatPerfTest::DTPatternGeneratorCopy10000() {
156 return new DTPatternGeneratorCopyFunction(10000, locale
);
159 UPerfFunction
*DateFormatPerfTest::DTPatternGeneratorBestValue250() {
160 return new DTPatternGeneratorBestValueFunction(250, locale
);
163 UPerfFunction
*DateFormatPerfTest::DTPatternGeneratorBestValue10000() {
164 return new DTPatternGeneratorBestValueFunction(10000, locale
);
167 UPerfFunction
* DateFormatPerfTest::DateFmtCopy250(){
168 return new DateFmtCopyFunction(250, locale
);
171 UPerfFunction
* DateFormatPerfTest::DateFmtCopy10000(){
172 return new DateFmtCopyFunction(10000, locale
);
175 UPerfFunction
* DateFormatPerfTest::DateFmtCreate250(){
176 return new DateFmtCreateFunction(250, locale
);
179 UPerfFunction
* DateFormatPerfTest::DateFmtCreate10000(){
180 return new DateFmtCreateFunction(10000, locale
);
184 int main(int argc
, const char* argv
[]){
187 if((argc
>1)&&(strcmp(argv
[1],"-x") == 0))
190 fprintf(stderr
, "Usage: %s -x <outfile>.xml\n", argv
[0]);
192 // not enough arguments
195 cout
<< "ICU version - " << U_ICU_VERSION
<< endl
;
196 UErrorCode status
= U_ZERO_ERROR
;
198 #define FUNCTION_COUNT 6
200 UPerfFunction
*functions
[FUNCTION_COUNT
];
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");
207 functions
[5] = new StdioNumFmtFunction(100000, "en");
209 // Perform time recording
210 double t
[FUNCTION_COUNT
];
211 for(int i
= 0; i
< FUNCTION_COUNT
; i
++) t
[i
] = 0;
213 #define ITER_COUNT 10
215 cout
<< "Doing " << ITER_COUNT
<< " iterations:" << endl
;
216 cout
<< "__________| Running...\r";
219 for(int i
= 0; i
< ITER_COUNT
; i
++) {
221 cout
<< '*' << flush
;
223 for(int j
= 0; U_SUCCESS(status
)&& j
< FUNCTION_COUNT
; j
++)
224 t
[j
] += (functions
[j
]->time(1, &status
) / ITER_COUNT
);
227 cout
<< " Done " << endl
;
230 if(U_SUCCESS(status
)) {
232 // Output results as .xml
236 out
<< "<perfTestResults icu=\"c\" version=\"" << U_ICU_VERSION
<< "\">" << endl
;
238 for(int i
= 0; i
< FUNCTION_COUNT
; i
++)
240 out
<< " <perfTestResult" << endl
;
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;
249 case 5: out
<< "StdioNumbFormat"; break;
250 default: out
<< "Unknown " << i
; break;
253 out
<< " iterations=\"" << functions
[i
]->getOperationsPerIteration() << "\"" << endl
;
254 out
<< " time=\"" << t
[i
] << "\" />" << endl
;
256 out
<< "</perfTestResults>" << endl
;
258 cout
<< " Wrote to " << argv
[2] << endl
;
261 if(U_FAILURE(status
)) {
262 cout
<< "Error! " << u_errorName(status
) << endl
;
270 // Normal performance test mode
271 UErrorCode status
= U_ZERO_ERROR
;
273 DateFormatPerfTest
test(argc
, argv
, status
);
276 if(U_FAILURE(status
)){ // ERROR HERE!!!
277 cout
<< "initialize failed! " << status
<< endl
;
280 //cout << "Done initializing!\n" << endl;
282 if(test
.run()==FALSE
){
283 cout
<< "run failed!" << endl
;
284 fprintf(stderr
,"FAILED: Tests could not be run please check the arguments.\n");
287 cout
<< "done!" << endl
;