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