• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 **********************************************************************
3 * Copyright (c) 2002-2010,International Business Machines
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 
DateFormatPerfTest(int32_t argc,const char * argv[],UErrorCode & status)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 
~DateFormatPerfTest()25 DateFormatPerfTest::~DateFormatPerfTest()
26 {
27 }
28 
runIndexedTest(int32_t index,UBool exec,const char * & name,char * par)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);
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 
46         default:
47             name = "";
48             return NULL;
49     }
50     return NULL;
51 }
52 
53 
DateFmt250()54 UPerfFunction* DateFormatPerfTest::DateFmt250(){
55     DateFmtFunction* func= new DateFmtFunction(1, locale);
56     return func;
57 }
58 
DateFmt10000()59 UPerfFunction* DateFormatPerfTest::DateFmt10000(){
60     DateFmtFunction* func= new DateFmtFunction(40, locale);
61     return func;
62 }
63 
DateFmt100000()64 UPerfFunction* DateFormatPerfTest::DateFmt100000(){
65     DateFmtFunction* func= new DateFmtFunction(400, locale);
66     return func;
67 }
68 
BreakItWord250()69 UPerfFunction* DateFormatPerfTest::BreakItWord250(){
70     BreakItFunction* func= new BreakItFunction(250, true);
71     return func;
72 }
73 
BreakItWord10000()74 UPerfFunction* DateFormatPerfTest::BreakItWord10000(){
75     BreakItFunction* func= new BreakItFunction(10000, true);
76     return func;
77 }
78 
BreakItChar250()79 UPerfFunction* DateFormatPerfTest::BreakItChar250(){
80     BreakItFunction* func= new BreakItFunction(250, false);
81     return func;
82 }
83 
BreakItChar10000()84 UPerfFunction* DateFormatPerfTest::BreakItChar10000(){
85     BreakItFunction* func= new BreakItFunction(10000, false);
86     return func;
87 }
88 
NumFmt10000()89 UPerfFunction* DateFormatPerfTest::NumFmt10000(){
90     NumFmtFunction* func= new NumFmtFunction(10000, locale);
91     return func;
92 }
93 
NumFmt100000()94 UPerfFunction* DateFormatPerfTest::NumFmt100000(){
95     NumFmtFunction* func= new NumFmtFunction(100000, locale);
96     return func;
97 }
98 
Collation10000()99 UPerfFunction* DateFormatPerfTest::Collation10000(){
100     CollationFunction* func= new CollationFunction(40, locale);
101     return func;
102 }
103 
Collation100000()104 UPerfFunction* DateFormatPerfTest::Collation100000(){
105     CollationFunction* func= new CollationFunction(400, locale);
106     return func;
107 }
108 
109 
110 
main(int argc,const char * argv[])111 int main(int argc, const char* argv[]){
112 
113     // -x Filename.xml
114     if((argc>1)&&(strcmp(argv[1],"-x") == 0))
115     {
116         if(argc < 3) {
117 			fprintf(stderr, "Usage: %s -x <outfile>.xml\n", argv[0]);
118 			return 1;
119 			// not enough arguments
120 		}
121 
122 		cout << "ICU version - " << U_ICU_VERSION << endl;
123         UErrorCode status = U_ZERO_ERROR;
124 
125         // Declare functions
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");
132 
133         // Perform time recording
134         double t[5];
135         for(int i = 0; i < 5; i++) t[i] = 0;
136 
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);
140 
141 
142         // Output results as .xml
143         ofstream out;
144         out.open(argv[2]);
145 
146         out << "<perfTestResults icu=\"c\" version=\"" << U_ICU_VERSION << "\">" << endl;
147 
148         for(int i = 0; i < 5; i++)
149         {
150             out << "    <perfTestResult" << endl;
151             out << "        test=\"";
152             switch(i)
153             {
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;
159             }
160             out << "\"" << endl;
161             int iter = 10000;
162             if(i > 2) iter = 100000;
163             out << "        iterations=\"" << iter << "\"" << endl;
164             out << "        time=\"" << t[i] << "\" />" << endl;
165         }
166         out << "</perfTestResults>" << endl;
167         out.close();
168 
169         return 0;
170     }
171 
172 
173     // Normal performance test mode
174     UErrorCode status = U_ZERO_ERROR;
175 
176     DateFormatPerfTest test(argc, argv, status);
177 
178 
179     if(U_FAILURE(status)){   // ERROR HERE!!!
180 		cout << "initialize failed! " << status << endl;
181         return status;
182     }
183 	//cout << "Done initializing!\n" << endl;
184 
185     if(test.run()==FALSE){
186 		cout << "run failed!" << endl;
187         fprintf(stderr,"FAILED: Tests could not be run please check the arguments.\n");
188         return -1;
189     }
190 	cout << "done!" << endl;
191 
192     return 0;
193 }