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