1ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* 2ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru********************************************************************** 3ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* Copyright (c) 2002-2005, International Business Machines 4ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* Corporation and others. All Rights Reserved. 5ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru********************************************************************** 6ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* 2005Nov22 Raymond Yang 7ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* 8ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru* migrate old test created by aliu to perf test framework. 9ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru*/ 10ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 11ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include <stdio.h> 12ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 13ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/utypes.h" 14ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/uniset.h" 15ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/uchar.h" 16ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/usetiter.h" 17ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "bitset.h" 18ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/uperf.h" 19ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 20ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustatic const char* PAT[] = { 21ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "['A-Za-z\\u00C0-\\u00C5\\u00C7-\\u00CF\\u00D1-\\u00D6\\u00D9-\\u00DD\\u00E0-\\u00E5\\u00E7-\\u00EF\\u00F1-\\u00F6\\u00F9-\\u00FD\\u00FF-\\u010F\\u0112-\\u0125\\u0128-\\u0130\\u0134-\\u0137\\u0139-\\u013E\\u0143-\\u0148\\u014C-\\u0151\\u0154-\\u0165\\u0168-\\u017E\\u01A0-\\u01A1\\u01AF-\\u01B0\\u01CD-\\u01DC\\u01DE-\\u01E1\\u01E6-\\u01ED\\u01F0\\u01F4-\\u01F5\\u01F8-\\u01FB\\u0200-\\u021B\\u021E-\\u021F\\u0226-\\u0233\\u1E00-\\u1E99\\u1EA0-\\u1EF9\\u212A-\\u212B]", 22ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 23ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "['.0-9A-Za-z~\\u00C0-\\u00C5\\u00C7-\\u00CF\\u00D1-\\u00D6\\u00D9-\\u00DD\\u00E0-\\u00E5\\u00E7-\\u00EF\\u00F1-\\u00F6\\u00F9-\\u00FD\\u00FF-\\u010F\\u0112-\\u0125\\u0128-\\u0130\\u0134-\\u0137\\u0139-\\u013E\\u0143-\\u0148\\u014C-\\u0151\\u0154-\\u0165\\u0168-\\u017E\\u01A0-\\u01A1\\u01AF-\\u01B0\\u01CD-\\u01DC\\u01DE-\\u01E3\\u01E6-\\u01ED\\u01F0\\u01F4-\\u01F5\\u01F8-\\u021B\\u021E-\\u021F\\u0226-\\u0233\\u0301\\u0303-\\u0304\\u0306-\\u0307\\u0310\\u0314-\\u0315\\u0323\\u0325\\u0331\\u0341\\u0344\\u0385-\\u0386\\u0388-\\u038A\\u038C\\u038E-\\u0390\\u03AC-\\u03B0\\u03CC-\\u03CE\\u03D3\\u0403\\u040C\\u040E\\u0419\\u0439\\u0453\\u045C\\u045E\\u04C1-\\u04C2\\u04D0-\\u04D1\\u04D6-\\u04D7\\u04E2-\\u04E3\\u04EE-\\u04EF\\u1E00-\\u1E99\\u1EA0-\\u1EF9\\u1F01\\u1F03-\\u1F05\\u1F07\\u1F09\\u1F0B-\\u1F0D\\u1F0F\\u1F11\\u1F13-\\u1F15\\u1F19\\u1F1B-\\u1F1D\\u1F21\\u1F23-\\u1F25\\u1F27\\u1F29\\u1F2B-\\u1F2D\\u1F2F\\u1F31\\u1F33-\\u1F35\\u1F37\\u1F39\\u1F3B-\\u1F3D\\u1F3F\\u1F41\\u1F43-\\u1F45\\u1F49\\u1F4B-\\u1F4D\\u1F51\\u1F53-\\u1F55\\u1F57\\u1F59\\u1F5B\\u1F5D\\u1F5F\\u1F61\\u1F63-\\u1F65\\u1F67\\u1F69\\u1F6B-\\u1F6D\\u1F6F\\u1F71\\u1F73\\u1F75\\u1F77\\u1F79\\u1F7B\\u1F7D\\u1F81\\u1F83-\\u1F85\\u1F87\\u1F89\\u1F8B-\\u1F8D\\u1F8F\\u1F91\\u1F93-\\u1F95\\u1F97\\u1F99\\u1F9B-\\u1F9D\\u1F9F\\u1FA1\\u1FA3-\\u1FA5\\u1FA7\\u1FA9\\u1FAB-\\u1FAD\\u1FAF-\\u1FB1\\u1FB4\\u1FB8-\\u1FB9\\u1FBB\\u1FC4\\u1FC9\\u1FCB\\u1FCE\\u1FD0-\\u1FD1\\u1FD3\\u1FD8-\\u1FD9\\u1FDB\\u1FDE\\u1FE0-\\u1FE1\\u1FE3\\u1FE5\\u1FE8-\\u1FE9\\u1FEB-\\u1FEC\\u1FEE\\u1FF4\\u1FF9\\u1FFB\\u212A-\\u212B\\uE04D\\uE064]", 24ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 25ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "[\\u0901-\\u0903\\u0905-\\u0939\\u093C-\\u094D\\u0950-\\u0954\\u0958-\\u096F]", 26ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}; 27ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 28ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruclass CmdPattern : public UPerfFunction { 29ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruprivate: 30ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UnicodeString pat; 31ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UnicodeSet set; 32ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querupublic: 33ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CmdPattern(const char * pattern):pat(pattern,""){ 34ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 35ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru virtual long getOperationsPerIteration(){ 36ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return 1; 37ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 38ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru virtual void call(UErrorCode* pErrorCode){ 39ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru set.applyPattern(pat, *pErrorCode); 40ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 41ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}; 42ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 43ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruclass CmdOp : public UPerfFunction { 44ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruprivate: 45ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UnicodeSet us; 46ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru BitSet bs; 47ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t total; 48ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru void (CmdOp::*op) (); 49ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querupublic: 50ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru CmdOp(UCharCategory prop, void (CmdOp::*op)()):op(op){ 51ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru total = 0; 52ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru bs.clearAll(); 53ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for (UChar32 cp=0; cp<0x110000; ++cp) { 54ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (u_charType(cp) == prop) { 55ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru bs.set((int32_t) cp); 56ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ++total; 57ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 58ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 59ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 60ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru virtual long getOperationsPerIteration(){ 61ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return total; 62ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 63ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 64ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru virtual void call(UErrorCode* pErrorCode){ 65ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru (this->*op)(); 66ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 67ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru void add (void){ 68ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru us.clear(); 69ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for (UChar32 cp=0; cp<0x110000; ++cp) { 70ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (bs.get((int32_t) cp)) { 71ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru us.add(cp); 72ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 73ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 74ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 75ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 76ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru void contains(void){ 77ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t temp = 0; 78ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru us.clear(); 79ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru for (UChar32 cp=0; cp<0x110000; ++cp) { 80ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (us.contains(cp)) { 81ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru temp += cp; 82ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 83ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 84ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 85ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 86ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru void iterator(void){ 87ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t temp = 0; 88ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UnicodeSetIterator uit(us); 89ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru while (uit.next()) { 90ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru temp += uit.getCodepoint(); 91ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 92ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 93ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}; 94ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 95ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruclass UsetPerformanceTest : public UPerfTest{ 96ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querupublic: 97ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UsetPerformanceTest(int32_t argc, const char *argv[], UErrorCode &status) :UPerfTest(argc,argv,status){ 98ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 99ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 100ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru virtual UPerfFunction* runIndexedTest( int32_t index, UBool exec, const char* &name, char* par = NULL ){ 101ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru switch (index) { 102ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru case 0: name = "titlecase_letter_add"; 103ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (exec) return new CmdOp(U_TITLECASE_LETTER, &CmdOp::add) ; break; 104ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru case 1: name = "titlecase_letter_contains"; 105ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (exec) return new CmdOp(U_TITLECASE_LETTER, &CmdOp::contains) ; break; 106ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru case 2: name = "titlecase_letter_iterator"; 107ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (exec) return new CmdOp(U_TITLECASE_LETTER, &CmdOp::iterator) ; break; 108ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru case 3: name = "unassigned_add"; 109ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (exec) return new CmdOp(U_UNASSIGNED, &CmdOp::add) ; break; 110ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru case 4: name = "unassigned_contains"; 111ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (exec) return new CmdOp(U_UNASSIGNED, &CmdOp::contains) ; break; 112ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru case 5: name = "unassigned_iterator"; 113ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (exec) return new CmdOp(U_UNASSIGNED, &CmdOp::iterator) ; break; 114ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru case 6: name = "pattern1"; 115ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (exec) return new CmdPattern(PAT[0]) ; break; 116ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru case 7: name = "pattern2"; 117ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (exec) return new CmdPattern(PAT[1]) ; break; 118ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru case 8: name = "pattern3"; 119ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (exec) return new CmdPattern(PAT[2]) ; break; 120ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru default: name = ""; break; 121ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 122ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return NULL; 123ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 124ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}; 125ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 126ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 127ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruint main(int argc, const char *argv[]) 128ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru{ 129ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UErrorCode status = U_ZERO_ERROR; 130ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UsetPerformanceTest test(argc, argv, status); 131ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 132ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (U_FAILURE(status)){ 133ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru printf("The error is %s\n", u_errorName(status)); 134ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return status; 135ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 136ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 137ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (test.run() == FALSE){ 138ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru fprintf(stderr, "FAILED: Tests could not be run please check the " 139ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru "arguments.\n"); 140ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return -1; 141ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 142ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru return 0; 143ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 144