intl/icu/source/tools/ctestfw/unicode/uperf.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /*
michael@0 2 **********************************************************************
michael@0 3 * Copyright (c) 2002-2011, International Business Machines
michael@0 4 * Corporation and others. All Rights Reserved.
michael@0 5 **********************************************************************
michael@0 6 */
michael@0 7 #ifndef _UPERF_H
michael@0 8 #define _UPERF_H
michael@0 9
michael@0 10 #include "unicode/utypes.h"
michael@0 11 #include "unicode/unistr.h"
michael@0 12 #include "unicode/ustring.h"
michael@0 13
michael@0 14 #include "unicode/testtype.h"
michael@0 15 #include "unicode/utimer.h"
michael@0 16 #include "ucbuf.h"
michael@0 17
michael@0 18 // Forward declarations from uoptions.h.
michael@0 19 struct UOption;
michael@0 20 typedef struct UOption UOption;
michael@0 21
michael@0 22 #if !UCONFIG_NO_CONVERSION
michael@0 23
michael@0 24 U_NAMESPACE_USE
michael@0 25 // Use the TESTCASE macro in subclasses of IntlTest. Define the
michael@0 26 // runIndexedTest method in this fashion:
michael@0 27 //
michael@0 28 //| void MyTest::runIndexedTest(int32_t index, UBool exec,
michael@0 29 //| const char* &name, char* /*par*/) {
michael@0 30 //| switch (index) {
michael@0 31 //| TESTCASE(0,TestSomething);
michael@0 32 //| TESTCASE(1,TestSomethingElse);
michael@0 33 //| TESTCASE(2,TestAnotherThing);
michael@0 34 //| default:
michael@0 35 //| name = "";
michael@0 36 //| return NULL;
michael@0 37 //| }
michael@0 38 //| }
michael@0 39 #if 0
michael@0 40 #define TESTCASE(id,test) \
michael@0 41 case id: \
michael@0 42 name = #test; \
michael@0 43 if (exec) { \
michael@0 44 fprintf(stdout,#test "---"); \
michael@0 45 fprintf(stdout,"\n"); \
michael@0 46 return test(); \
michael@0 47 } \
michael@0 48 break
michael@0 49
michael@0 50 #endif
michael@0 51 #define TESTCASE(id,test) \
michael@0 52 case id: \
michael@0 53 name = #test; \
michael@0 54 if (exec) { \
michael@0 55 return test(); \
michael@0 56 } \
michael@0 57 break
michael@0 58
michael@0 59 /**
michael@0 60 * Subclasses of PerfTest will need to create subclasses of
michael@0 61 * Function that define a call() method which contains the code to
michael@0 62 * be timed. They then call setTestFunction() in their "Test..."
michael@0 63 * method to establish this as the current test functor.
michael@0 64 */
michael@0 65 class T_CTEST_EXPORT_API UPerfFunction {
michael@0 66 public:
michael@0 67 /**
michael@0 68 * destructor
michael@0 69 */
michael@0 70 virtual ~UPerfFunction();
michael@0 71
michael@0 72 /**
michael@0 73 * Subclasses must implement this method to do the action to be
michael@0 74 * measured.
michael@0 75 */
michael@0 76 virtual void call(UErrorCode* status)=0;
michael@0 77
michael@0 78 /**
michael@0 79 * Subclasses must implement this method to return positive
michael@0 80 * integer indicating the number of operations in a single
michael@0 81 * call to this object's call() method.
michael@0 82 */
michael@0 83 virtual long getOperationsPerIteration()=0;
michael@0 84 /**
michael@0 85 * Subclasses should override this method to return either positive
michael@0 86 * or negative integer indicating the number of events in a single
michael@0 87 * call to this object's call() method, if applicable
michael@0 88 * e.g: Number of breaks / iterations for break iterator
michael@0 89 */
michael@0 90 virtual long getEventsPerIteration(){
michael@0 91 return -1;
michael@0 92 }
michael@0 93 /**
michael@0 94 * Call call() n times in a tight loop and return the elapsed
michael@0 95 * milliseconds. If n is small and call() is fast the return
michael@0 96 * result may be zero. Small return values have limited
michael@0 97 * meaningfulness, depending on the underlying CPU and OS.
michael@0 98 */
michael@0 99 virtual double time(int32_t n, UErrorCode* status) {
michael@0 100 UTimer start, stop;
michael@0 101 utimer_getTime(&start);
michael@0 102 while (n-- > 0) {
michael@0 103 call(status);
michael@0 104 }
michael@0 105 utimer_getTime(&stop);
michael@0 106 return utimer_getDeltaSeconds(&start,&stop); // ms
michael@0 107 }
michael@0 108
michael@0 109 };
michael@0 110
michael@0 111
michael@0 112 class T_CTEST_EXPORT_API UPerfTest {
michael@0 113 public:
michael@0 114 UBool run();
michael@0 115 UBool runTest( char* name = NULL, char* par = NULL ); // not to be overidden
michael@0 116
michael@0 117 virtual void usage( void ) ;
michael@0 118
michael@0 119 virtual ~UPerfTest();
michael@0 120
michael@0 121 void setCaller( UPerfTest* callingTest ); // for internal use only
michael@0 122
michael@0 123 void setPath( char* path ); // for internal use only
michael@0 124
michael@0 125 ULine* getLines(UErrorCode& status);
michael@0 126
michael@0 127 const UChar* getBuffer(int32_t& len,UErrorCode& status);
michael@0 128
michael@0 129 protected:
michael@0 130 UPerfTest(int32_t argc, const char* argv[], UErrorCode& status);
michael@0 131
michael@0 132 UPerfTest(int32_t argc, const char* argv[],
michael@0 133 UOption addOptions[], int32_t addOptionsCount,
michael@0 134 const char *addUsage,
michael@0 135 UErrorCode& status);
michael@0 136
michael@0 137 void init(UOption addOptions[], int32_t addOptionsCount,
michael@0 138 UErrorCode& status);
michael@0 139
michael@0 140 virtual UPerfFunction* runIndexedTest( int32_t index, UBool exec, const char* &name, char* par = NULL ); // overide !
michael@0 141
michael@0 142 virtual UBool runTestLoop( char* testname, char* par );
michael@0 143
michael@0 144 virtual UBool callTest( UPerfTest& testToBeCalled, char* par );
michael@0 145
michael@0 146 int32_t _argc;
michael@0 147 const char** _argv;
michael@0 148 const char * _addUsage;
michael@0 149 char* resolvedFileName;
michael@0 150 UCHARBUF* ucharBuf;
michael@0 151 const char* encoding;
michael@0 152 UBool uselen;
michael@0 153 const char* fileName;
michael@0 154 const char* sourceDir;
michael@0 155 int32_t _remainingArgc;
michael@0 156 ULine* lines;
michael@0 157 int32_t numLines;
michael@0 158 UBool line_mode;
michael@0 159 UChar* buffer;
michael@0 160 int32_t bufferLen;
michael@0 161 UBool verbose;
michael@0 162 UBool bulk_mode;
michael@0 163 int32_t passes;
michael@0 164 int32_t iterations;
michael@0 165 int32_t time;
michael@0 166 const char* locale;
michael@0 167 private:
michael@0 168 UPerfTest* caller;
michael@0 169 char* path; // specifies subtests
michael@0 170
michael@0 171 // static members
michael@0 172 public:
michael@0 173 static UPerfTest* gTest;
michael@0 174 static const char gUsageString[];
michael@0 175 };
michael@0 176
michael@0 177 #endif
michael@0 178 #endif
michael@0 179

mercurial