]>
git.saurik.com Git - apple/icu.git/blob - icuSources/test/perf/ustrperf/stringperf.cpp
1 /********************************************************************
3 * Copyright (C) 2002-2006 International Business Machines Corporation
4 * and others. All Rights Reserved.
6 ********************************************************************/
7 /*****************************************************************************
10 * Modification History:
12 * Doug Wang Second version
13 * Doug Wang First Version
14 ******************************************************************************
18 * This program tests UnicodeString performance.
19 * APIs tested: UnicodeString
21 * Windows 2000/XP, Linux
24 #include "stringperf.h"
27 int main(int argc
, const char *argv
[])
29 UErrorCode status
= U_ZERO_ERROR
;
31 bCatenatePrealloc
=TRUE
;
33 StringPerformanceTest
test(argc
, argv
, status
);
34 if (U_FAILURE(status
)){
39 if (bCatenatePrealloc
) {
40 int to_alloc
= loops
* MAXNUMLINES
* (MAXSRCLEN
+ catenate_STRLEN
);
41 catICU
= new UnicodeString(to_alloc
,'a',0);
42 //catICU = new UnicodeString();
44 catStd
= new stlstring();
45 catStd
-> reserve(loops
* MAXNUMLINES
* (MAXSRCLEN
+ catenate_STRLEN
));
46 //catStd -> reserve(110000000);
48 catICU
= new UnicodeString();
49 catStd
= new stlstring();
52 if (test
.run() == FALSE
){
53 fprintf(stderr
, "FAILED: Tests could not be run please check the "
63 StringPerformanceTest::StringPerformanceTest(int32_t argc
, const char *argv
[],
65 : UPerfTest(argc
, argv
, status
)
73 if (status
== U_ILLEGAL_ARGUMENT_ERROR
){
74 //fprintf(stderr,gUsageString, "stringperf");
77 if (U_FAILURE(status
)){
78 fprintf(stderr
, "FAILED to create UPerfTest object. Error: %s\n",
85 ULine
* filelines
= getLines(status
);
86 if(U_FAILURE(status
)){
87 fprintf(stderr
, "FAILED to read lines from file and create UPerfTest object. Error: %s\n", u_errorName(status
));
91 filelines_
= new ULine
[numLines
];
92 for (int i
=0; i
< numLines
; i
++) {
93 len
= filelines
[i
].len
;
94 filelines_
[i
].name
= new UChar
[len
];
95 filelines_
[i
].len
= len
;
96 memcpy(filelines_
[i
].name
, filelines
[i
].name
, len
* U_SIZEOF_UCHAR
);
101 const UChar
* src
= getBuffer(srcLen
,status
);
102 if(U_FAILURE(status
)){
103 fprintf(stderr
, "FAILED to read buffer from file and create UPerfTest object. Error: %s\n", u_errorName(status
));
107 StrBuffer
= new UChar
[srcLen
];
108 StrBufferLen
= srcLen
;
109 memcpy(StrBuffer
, src
, srcLen
* U_SIZEOF_UCHAR
);
114 StringPerformanceTest::~StringPerformanceTest()
120 UPerfFunction
* StringPerformanceTest::runIndexedTest(int32_t index
, UBool exec
,
125 TESTCASE(0, TestCtor
);
126 TESTCASE(1, TestCtor1
);
127 TESTCASE(2, TestCtor2
);
128 TESTCASE(3, TestCtor3
);
129 TESTCASE(4, TestAssign
);
130 TESTCASE(5, TestAssign1
);
131 TESTCASE(6, TestAssign2
);
132 TESTCASE(7, TestGetch
);
133 TESTCASE(8, TestCatenate
);
134 TESTCASE(9, TestScan
);
135 TESTCASE(10, TestScan1
);
136 TESTCASE(11, TestScan2
);
138 TESTCASE(12, TestStdLibCtor
);
139 TESTCASE(13, TestStdLibCtor1
);
140 TESTCASE(14, TestStdLibCtor2
);
141 TESTCASE(15, TestStdLibCtor3
);
142 TESTCASE(16, TestStdLibAssign
);
143 TESTCASE(17, TestStdLibAssign1
);
144 TESTCASE(18, TestStdLibAssign2
);
145 TESTCASE(19, TestStdLibGetch
);
146 TESTCASE(20, TestStdLibCatenate
);
147 TESTCASE(21, TestStdLibScan
);
148 TESTCASE(22, TestStdLibScan1
);
149 TESTCASE(23, TestStdLibScan2
);
158 UPerfFunction
* StringPerformanceTest::TestCtor()
161 return new StringPerfFunction(ctor
, filelines_
, numLines
, uselen
);
163 return new StringPerfFunction(ctor
, StrBuffer
, StrBufferLen
, uselen
);
167 UPerfFunction
* StringPerformanceTest::TestCtor1()
170 return new StringPerfFunction(ctor1
, filelines_
, numLines
, uselen
);
172 return new StringPerfFunction(ctor1
, StrBuffer
, StrBufferLen
, uselen
);
176 UPerfFunction
* StringPerformanceTest::TestCtor2()
179 return new StringPerfFunction(ctor2
, filelines_
, numLines
, uselen
);
181 return new StringPerfFunction(ctor2
, StrBuffer
, StrBufferLen
, uselen
);
185 UPerfFunction
* StringPerformanceTest::TestCtor3()
188 return new StringPerfFunction(ctor3
, filelines_
, numLines
, uselen
);
190 return new StringPerfFunction(ctor3
, StrBuffer
, StrBufferLen
, uselen
);
194 UPerfFunction
* StringPerformanceTest::TestAssign()
197 return new StringPerfFunction(assign
, filelines_
, numLines
, uselen
);
199 return new StringPerfFunction(assign
, StrBuffer
, StrBufferLen
, uselen
);
203 UPerfFunction
* StringPerformanceTest::TestAssign1()
206 return new StringPerfFunction(assign1
, filelines_
, numLines
, uselen
);
208 return new StringPerfFunction(assign1
, StrBuffer
, StrBufferLen
, uselen
);
212 UPerfFunction
* StringPerformanceTest::TestAssign2()
215 return new StringPerfFunction(assign2
, filelines_
, numLines
, uselen
);
217 return new StringPerfFunction(assign2
, StrBuffer
, StrBufferLen
, uselen
);
222 UPerfFunction
* StringPerformanceTest::TestGetch()
225 return new StringPerfFunction(getch
, filelines_
, numLines
, uselen
);
227 return new StringPerfFunction(getch
, StrBuffer
, StrBufferLen
, uselen
);
231 UPerfFunction
* StringPerformanceTest::TestCatenate()
234 return new StringPerfFunction(catenate
, filelines_
, numLines
, uselen
);
236 //return new StringPerfFunction(catenate, buffer, bufferLen, uselen);
237 return new StringPerfFunction(catenate
, StrBuffer
, StrBufferLen
, uselen
);
241 UPerfFunction
* StringPerformanceTest::TestScan()
244 return new StringPerfFunction(scan
, filelines_
, numLines
, uselen
);
246 return new StringPerfFunction(scan
, StrBuffer
, StrBufferLen
, uselen
);
250 UPerfFunction
* StringPerformanceTest::TestScan1()
253 return new StringPerfFunction(scan1
, filelines_
, numLines
, uselen
);
255 return new StringPerfFunction(scan1
, StrBuffer
, StrBufferLen
, uselen
);
259 UPerfFunction
* StringPerformanceTest::TestScan2()
262 return new StringPerfFunction(scan2
, filelines_
, numLines
, uselen
);
264 return new StringPerfFunction(scan2
, StrBuffer
, StrBufferLen
, uselen
);
268 UPerfFunction
* StringPerformanceTest::TestStdLibCtor()
271 return new StringPerfFunction(StdLibCtor
, filelines_
, numLines
, uselen
);
273 return new StringPerfFunction(StdLibCtor
, StrBuffer
, StrBufferLen
, uselen
);
277 UPerfFunction
* StringPerformanceTest::TestStdLibCtor1()
280 return new StringPerfFunction(StdLibCtor1
, filelines_
, numLines
, uselen
);
282 return new StringPerfFunction(StdLibCtor1
, StrBuffer
, StrBufferLen
, uselen
);
286 UPerfFunction
* StringPerformanceTest::TestStdLibCtor2()
289 return new StringPerfFunction(StdLibCtor2
, filelines_
, numLines
, uselen
);
291 return new StringPerfFunction(StdLibCtor2
, StrBuffer
, StrBufferLen
, uselen
);
295 UPerfFunction
* StringPerformanceTest::TestStdLibCtor3()
298 return new StringPerfFunction(StdLibCtor3
, filelines_
, numLines
, uselen
);
300 return new StringPerfFunction(StdLibCtor3
, StrBuffer
, StrBufferLen
, uselen
);
304 UPerfFunction
* StringPerformanceTest::TestStdLibAssign()
307 return new StringPerfFunction(StdLibAssign
, filelines_
, numLines
, uselen
);
309 return new StringPerfFunction(StdLibAssign
, StrBuffer
, StrBufferLen
, uselen
);
313 UPerfFunction
* StringPerformanceTest::TestStdLibAssign1()
316 return new StringPerfFunction(StdLibAssign1
, filelines_
, numLines
, uselen
);
318 return new StringPerfFunction(StdLibAssign1
, StrBuffer
, StrBufferLen
, uselen
);
322 UPerfFunction
* StringPerformanceTest::TestStdLibAssign2()
325 return new StringPerfFunction(StdLibAssign2
, filelines_
, numLines
, uselen
);
327 return new StringPerfFunction(StdLibAssign2
, StrBuffer
, StrBufferLen
, uselen
);
331 UPerfFunction
* StringPerformanceTest::TestStdLibGetch()
334 return new StringPerfFunction(StdLibGetch
, filelines_
, numLines
, uselen
);
336 return new StringPerfFunction(StdLibGetch
, StrBuffer
, StrBufferLen
, uselen
);
340 UPerfFunction
* StringPerformanceTest::TestStdLibCatenate()
343 return new StringPerfFunction(StdLibCatenate
, filelines_
, numLines
, uselen
);
345 //return new StringPerfFunction(StdLibCatenate, buffer, bufferLen, uselen);
346 return new StringPerfFunction(StdLibCatenate
, StrBuffer
, StrBufferLen
, uselen
);
350 UPerfFunction
* StringPerformanceTest::TestStdLibScan()
353 return new StringPerfFunction(StdLibScan
, filelines_
, numLines
, uselen
);
355 return new StringPerfFunction(StdLibScan
, StrBuffer
, StrBufferLen
, uselen
);
359 UPerfFunction
* StringPerformanceTest::TestStdLibScan1()
362 return new StringPerfFunction(StdLibScan1
, filelines_
, numLines
, uselen
);
364 return new StringPerfFunction(StdLibScan1
, StrBuffer
, StrBufferLen
, uselen
);
368 UPerfFunction
* StringPerformanceTest::TestStdLibScan2()
371 return new StringPerfFunction(StdLibScan2
, filelines_
, numLines
, uselen
);
373 return new StringPerfFunction(StdLibScan2
, StrBuffer
, StrBufferLen
, uselen
);