X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/374ca955a76ecab1204ca8bfa63ff9238d998416..ef6cf650f4a75c3f97de06b51fa104f2069b9ea2:/icuSources/test/perf/ustrperf/stringperf.cpp diff --git a/icuSources/test/perf/ustrperf/stringperf.cpp b/icuSources/test/perf/ustrperf/stringperf.cpp index 653e1a02..342e060a 100644 --- a/icuSources/test/perf/ustrperf/stringperf.cpp +++ b/icuSources/test/perf/ustrperf/stringperf.cpp @@ -1,6 +1,6 @@ /******************************************************************** * COPYRIGHT: - * Copyright (C) 2002-2004 International Business Machines Corporation + * Copyright (C) 2002-2006 International Business Machines Corporation * and others. All Rights Reserved. * ********************************************************************/ @@ -9,7 +9,7 @@ * * Modification History: * Name Description -* Doug Wang Second version +* Doug Wang Second version * Doug Wang First Version ****************************************************************************** */ @@ -28,55 +28,55 @@ int main(int argc, const char *argv[]) { UErrorCode status = U_ZERO_ERROR; - bCatenatePrealloc=TRUE; + bCatenatePrealloc=TRUE; StringPerformanceTest test(argc, argv, status); - if (U_FAILURE(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(); - } + + 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"); + "arguments.\n"); return -1; } - delete catICU; - delete catStd; + delete catICU; + delete catStd; return 0; } StringPerformanceTest::StringPerformanceTest(int32_t argc, const char *argv[], - UErrorCode &status) - : UPerfTest(argc, argv, status) + UErrorCode &status) + : UPerfTest(argc, argv, status) { - filelines_=NULL; - StrBuffer=NULL; - StrBufferLen=0; + filelines_=NULL; + StrBuffer=NULL; + StrBufferLen=0; - int32_t len =0; + int32_t len =0; - if (status== U_ILLEGAL_ARGUMENT_ERROR){ - //fprintf(stderr,gUsageString, "stringperf"); - return; + 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)); + u_errorName(status)); return; } @@ -87,15 +87,15 @@ StringPerformanceTest::StringPerformanceTest(int32_t argc, const char *argv[], 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 UChar[len]; + + filelines_ = new ULine[numLines]; + for (int i =0; i < numLines; i++) { + len = filelines[i].len; + filelines_[i].name = new UChar[len]; filelines_[i].len = len; - memcpy(filelines_[i].name, filelines[i].name, len * U_SIZEOF_UCHAR); - } - + memcpy(filelines_[i].name, filelines[i].name, len * U_SIZEOF_UCHAR); + } + }else if(bulk_mode){ int32_t srcLen = 0; const UChar* src = getBuffer(srcLen,status); @@ -103,50 +103,50 @@ StringPerformanceTest::StringPerformanceTest(int32_t argc, const char *argv[], fprintf(stderr, "FAILED to read buffer from file and create UPerfTest object. Error: %s\n", u_errorName(status)); return; } - - StrBuffer = new UChar[srcLen]; - StrBufferLen = srcLen; - memcpy(StrBuffer, src, srcLen * U_SIZEOF_UCHAR); + + StrBuffer = new UChar[srcLen]; + StrBufferLen = srcLen; + memcpy(StrBuffer, src, srcLen * U_SIZEOF_UCHAR); } } StringPerformanceTest::~StringPerformanceTest() { - delete[] filelines_; - delete[] StrBuffer; + delete[] filelines_; + delete[] StrBuffer; } UPerfFunction* StringPerformanceTest::runIndexedTest(int32_t index, UBool exec, - const char *&name, - char* par) + 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); + 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 = ""; @@ -157,219 +157,221 @@ UPerfFunction* StringPerformanceTest::runIndexedTest(int32_t index, UBool exec, UPerfFunction* StringPerformanceTest::TestCtor() { - if (line_mode) { - return new StringPerfFunction(ctor, filelines_, numLines, uselen); - } else { - return new StringPerfFunction(ctor, StrBuffer, StrBufferLen, uselen); - } + 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); - } + 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); - } + 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); - } + 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); - } + 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); - } + 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); - } + 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); - } + 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); - } + 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); - } + 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); - } + 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); - } + 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); - } + 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); - } + 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); - } + 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); - } + 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); - } + 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); - } + 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); - } + 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); - } + 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); - } + 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); - } + 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); - } + 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); - } -} \ No newline at end of file + if (line_mode) { + return new StringPerfFunction(StdLibScan2, filelines_, numLines, uselen); + } else { + return new StringPerfFunction(StdLibScan2, StrBuffer, StrBufferLen, uselen); + } +} + +