1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382
|
/***********************************************************************
* © 2016 and later: Unicode, Inc. and others.
* License & terms of use: http://www.unicode.org/copyright.html
*
***********************************************************************
***********************************************************************
* COPYRIGHT:
* Copyright (C) 2002-2006 International Business Machines Corporation
* and others. All Rights Reserved.
*
***********************************************************************/
/*****************************************************************************
* File stringperf.cpp
*
* Modification History:
* Name Description
* Doug Wang Second version
* Doug Wang First Version
******************************************************************************
*/
/**
* This program tests UnicodeString performance.
* APIs tested: UnicodeString
* ICU4C
* Windows 2000/XP, Linux
*/
#include "stringperf.h"
int main(int argc, const char *argv[])
{
UErrorCode status = U_ZERO_ERROR;
bCatenatePrealloc=true;
StringPerformanceTest test(argc, argv, status);
if (U_FAILURE(status)){
return status;
}
int loops = LOOPS;
if (bCatenatePrealloc) {
int to_alloc = loops * MAXNUMLINES * (MAXSRCLEN + catenate_STRLEN);
catICU = new UnicodeString(to_alloc,'a',0);
//catICU = new UnicodeString();
catStd = new stlstring();
catStd -> reserve(loops * MAXNUMLINES * (MAXSRCLEN + catenate_STRLEN));
//catStd -> reserve(110000000);
} else {
catICU = new UnicodeString();
catStd = new stlstring();
}
if (test.run() == false){
fprintf(stderr, "FAILED: Tests could not be run please check the "
"arguments.\n");
return -1;
}
delete catICU;
delete catStd;
return 0;
}
StringPerformanceTest::StringPerformanceTest(int32_t argc, const char *argv[],
UErrorCode &status)
: UPerfTest(argc, argv, status)
{
filelines_=nullptr;
StrBuffer=nullptr;
StrBufferLen=0;
int32_t len =0;
if (status== U_ILLEGAL_ARGUMENT_ERROR){
//fprintf(stderr,gUsageString, "stringperf");
return;
}
if (U_FAILURE(status)){
fprintf(stderr, "FAILED to create UPerfTest object. Error: %s\n",
u_errorName(status));
return;
}
if(line_mode){
ULine* filelines = getLines(status);
if(U_FAILURE(status)){
fprintf(stderr, "FAILED to read lines from file and create UPerfTest object. Error: %s\n", u_errorName(status));
return;
}
filelines_ = new ULine[numLines];
for (int i =0; i < numLines; i++) {
len = filelines[i].len;
filelines_[i].name = new char16_t[len];
filelines_[i].len = len;
memcpy(filelines_[i].name, filelines[i].name, len * U_SIZEOF_UCHAR);
}
}else if(bulk_mode){
int32_t srcLen = 0;
const char16_t* src = getBuffer(srcLen,status);
if(U_FAILURE(status)){
fprintf(stderr, "FAILED to read buffer from file and create UPerfTest object. Error: %s\n", u_errorName(status));
return;
}
StrBuffer = new char16_t[srcLen];
StrBufferLen = srcLen;
memcpy(StrBuffer, src, srcLen * U_SIZEOF_UCHAR);
}
}
StringPerformanceTest::~StringPerformanceTest()
{
delete[] filelines_;
delete[] StrBuffer;
}
UPerfFunction* StringPerformanceTest::runIndexedTest(int32_t index, UBool exec,
const char *&name,
char* par)
{
switch (index) {
TESTCASE(0, TestCtor);
TESTCASE(1, TestCtor1);
TESTCASE(2, TestCtor2);
TESTCASE(3, TestCtor3);
TESTCASE(4, TestAssign);
TESTCASE(5, TestAssign1);
TESTCASE(6, TestAssign2);
TESTCASE(7, TestGetch);
TESTCASE(8, TestCatenate);
TESTCASE(9, TestScan);
TESTCASE(10, TestScan1);
TESTCASE(11, TestScan2);
TESTCASE(12, TestStdLibCtor);
TESTCASE(13, TestStdLibCtor1);
TESTCASE(14, TestStdLibCtor2);
TESTCASE(15, TestStdLibCtor3);
TESTCASE(16, TestStdLibAssign);
TESTCASE(17, TestStdLibAssign1);
TESTCASE(18, TestStdLibAssign2);
TESTCASE(19, TestStdLibGetch);
TESTCASE(20, TestStdLibCatenate);
TESTCASE(21, TestStdLibScan);
TESTCASE(22, TestStdLibScan1);
TESTCASE(23, TestStdLibScan2);
default:
name = "";
return nullptr;
}
return nullptr;
}
UPerfFunction* StringPerformanceTest::TestCtor()
{
if (line_mode) {
return new StringPerfFunction(ctor, filelines_, numLines, uselen);
} else {
return new StringPerfFunction(ctor, StrBuffer, StrBufferLen, uselen);
}
}
UPerfFunction* StringPerformanceTest::TestCtor1()
{
if (line_mode) {
return new StringPerfFunction(ctor1, filelines_, numLines, uselen);
} else {
return new StringPerfFunction(ctor1, StrBuffer, StrBufferLen, uselen);
}
}
UPerfFunction* StringPerformanceTest::TestCtor2()
{
if (line_mode) {
return new StringPerfFunction(ctor2, filelines_, numLines, uselen);
} else {
return new StringPerfFunction(ctor2, StrBuffer, StrBufferLen, uselen);
}
}
UPerfFunction* StringPerformanceTest::TestCtor3()
{
if (line_mode) {
return new StringPerfFunction(ctor3, filelines_, numLines, uselen);
} else {
return new StringPerfFunction(ctor3, StrBuffer, StrBufferLen, uselen);
}
}
UPerfFunction* StringPerformanceTest::TestAssign()
{
if (line_mode) {
return new StringPerfFunction(assign, filelines_, numLines, uselen);
} else {
return new StringPerfFunction(assign, StrBuffer, StrBufferLen, uselen);
}
}
UPerfFunction* StringPerformanceTest::TestAssign1()
{
if (line_mode) {
return new StringPerfFunction(assign1, filelines_, numLines, uselen);
} else {
return new StringPerfFunction(assign1, StrBuffer, StrBufferLen, uselen);
}
}
UPerfFunction* StringPerformanceTest::TestAssign2()
{
if (line_mode) {
return new StringPerfFunction(assign2, filelines_, numLines, uselen);
} else {
return new StringPerfFunction(assign2, StrBuffer, StrBufferLen, uselen);
}
}
UPerfFunction* StringPerformanceTest::TestGetch()
{
if (line_mode) {
return new StringPerfFunction(getch, filelines_, numLines, uselen);
} else {
return new StringPerfFunction(getch, StrBuffer, StrBufferLen, uselen);
}
}
UPerfFunction* StringPerformanceTest::TestCatenate()
{
if (line_mode) {
return new StringPerfFunction(catenate, filelines_, numLines, uselen);
} else {
//return new StringPerfFunction(catenate, buffer, bufferLen, uselen);
return new StringPerfFunction(catenate, StrBuffer, StrBufferLen, uselen);
}
}
UPerfFunction* StringPerformanceTest::TestScan()
{
if (line_mode) {
return new StringPerfFunction(scan, filelines_, numLines, uselen);
} else {
return new StringPerfFunction(scan, StrBuffer, StrBufferLen, uselen);
}
}
UPerfFunction* StringPerformanceTest::TestScan1()
{
if (line_mode) {
return new StringPerfFunction(scan1, filelines_, numLines, uselen);
} else {
return new StringPerfFunction(scan1, StrBuffer, StrBufferLen, uselen);
}
}
UPerfFunction* StringPerformanceTest::TestScan2()
{
if (line_mode) {
return new StringPerfFunction(scan2, filelines_, numLines, uselen);
} else {
return new StringPerfFunction(scan2, StrBuffer, StrBufferLen, uselen);
}
}
UPerfFunction* StringPerformanceTest::TestStdLibCtor()
{
if (line_mode) {
return new StringPerfFunction(StdLibCtor, filelines_, numLines, uselen);
} else {
return new StringPerfFunction(StdLibCtor, StrBuffer, StrBufferLen, uselen);
}
}
UPerfFunction* StringPerformanceTest::TestStdLibCtor1()
{
if (line_mode) {
return new StringPerfFunction(StdLibCtor1, filelines_, numLines, uselen);
} else {
return new StringPerfFunction(StdLibCtor1, StrBuffer, StrBufferLen, uselen);
}
}
UPerfFunction* StringPerformanceTest::TestStdLibCtor2()
{
if (line_mode) {
return new StringPerfFunction(StdLibCtor2, filelines_, numLines, uselen);
} else {
return new StringPerfFunction(StdLibCtor2, StrBuffer, StrBufferLen, uselen);
}
}
UPerfFunction* StringPerformanceTest::TestStdLibCtor3()
{
if (line_mode) {
return new StringPerfFunction(StdLibCtor3, filelines_, numLines, uselen);
} else {
return new StringPerfFunction(StdLibCtor3, StrBuffer, StrBufferLen, uselen);
}
}
UPerfFunction* StringPerformanceTest::TestStdLibAssign()
{
if (line_mode) {
return new StringPerfFunction(StdLibAssign, filelines_, numLines, uselen);
} else {
return new StringPerfFunction(StdLibAssign, StrBuffer, StrBufferLen, uselen);
}
}
UPerfFunction* StringPerformanceTest::TestStdLibAssign1()
{
if (line_mode) {
return new StringPerfFunction(StdLibAssign1, filelines_, numLines, uselen);
} else {
return new StringPerfFunction(StdLibAssign1, StrBuffer, StrBufferLen, uselen);
}
}
UPerfFunction* StringPerformanceTest::TestStdLibAssign2()
{
if (line_mode) {
return new StringPerfFunction(StdLibAssign2, filelines_, numLines, uselen);
} else {
return new StringPerfFunction(StdLibAssign2, StrBuffer, StrBufferLen, uselen);
}
}
UPerfFunction* StringPerformanceTest::TestStdLibGetch()
{
if (line_mode) {
return new StringPerfFunction(StdLibGetch, filelines_, numLines, uselen);
} else {
return new StringPerfFunction(StdLibGetch, StrBuffer, StrBufferLen, uselen);
}
}
UPerfFunction* StringPerformanceTest::TestStdLibCatenate()
{
if (line_mode) {
return new StringPerfFunction(StdLibCatenate, filelines_, numLines, uselen);
} else {
//return new StringPerfFunction(StdLibCatenate, buffer, bufferLen, uselen);
return new StringPerfFunction(StdLibCatenate, StrBuffer, StrBufferLen, uselen);
}
}
UPerfFunction* StringPerformanceTest::TestStdLibScan()
{
if (line_mode) {
return new StringPerfFunction(StdLibScan, filelines_, numLines, uselen);
} else {
return new StringPerfFunction(StdLibScan, StrBuffer, StrBufferLen, uselen);
}
}
UPerfFunction* StringPerformanceTest::TestStdLibScan1()
{
if (line_mode) {
return new StringPerfFunction(StdLibScan1, filelines_, numLines, uselen);
} else {
return new StringPerfFunction(StdLibScan1, StrBuffer, StrBufferLen, uselen);
}
}
UPerfFunction* StringPerformanceTest::TestStdLibScan2()
{
if (line_mode) {
return new StringPerfFunction(StdLibScan2, filelines_, numLines, uselen);
} else {
return new StringPerfFunction(StdLibScan2, StrBuffer, StrBufferLen, uselen);
}
}
|