]>
git.saurik.com Git - apple/icu.git/blob - icuSources/tools/toolutil/uperf.h
2 **********************************************************************
3 * Copyright (c) 2002-2004, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 **********************************************************************
6 **********************************************************************
11 #include "unicode/utypes.h"
12 #include "unicode/unistr.h"
13 #include "unicode/ustring.h"
19 // Use the TESTCASE macro in subclasses of IntlTest. Define the
20 // runIndexedTest method in this fashion:
22 //| void MyTest::runIndexedTest(int32_t index, UBool exec,
23 //| const char* &name, char* /*par*/) {
25 //| TESTCASE(0,TestSomething);
26 //| TESTCASE(1,TestSomethingElse);
27 //| TESTCASE(2,TestAnotherThing);
34 #define TESTCASE(id,test) \
38 fprintf(stdout,#test "---"); \
39 fprintf(stdout,"\n"); \
45 #define TESTCASE(id,test) \
54 * Subclasses of PerfTest will need to create subclasses of
55 * Function that define a call() method which contains the code to
56 * be timed. They then call setTestFunction() in their "Test..."
57 * method to establish this as the current test functor.
59 class U_EXPORT UPerfFunction
{
62 * Subclasses must implement this method to do the action to be
65 virtual void call(UErrorCode
* status
)=0;
68 * Subclasses must implement this method to return positive
69 * integer indicating the number of operations in a single
70 * call to this object's call() method.
72 virtual long getOperationsPerIteration()=0;
74 * Subclasses should override this method to return either positive
75 * or negative integer indicating the number of events in a single
76 * call to this object's call() method, if applicable
77 * e.g: Number of breaks / iterations for break iterator
79 virtual long getEventsPerIteration(){
84 * Call call() n times in a tight loop and return the elapsed
85 * milliseconds. If n is small and call() is fast the return
86 * result may be zero. Small return values have limited
87 * meaningfulness, depending on the underlying CPU and OS.
89 double time(int32_t n
, UErrorCode
* status
) {
91 utimer_getTime(&start
);
95 utimer_getTime(&stop
);
96 return utimer_getDeltaSeconds(&start
,&stop
); // ms
102 class U_EXPORT UPerfTest
{
105 UBool
runTest( char* name
= NULL
, char* par
= NULL
); // not to be overidden
107 virtual void usage( void ) ;
109 virtual ~UPerfTest();
111 void setCaller( UPerfTest
* callingTest
); // for internal use only
113 void setPath( char* path
); // for internal use only
115 ULine
* getLines(UErrorCode
& status
);
117 const UChar
* getBuffer(int32_t& len
,UErrorCode
& status
);
120 UPerfTest(int32_t argc
, const char* argv
[], UErrorCode
& status
);
122 virtual UPerfFunction
* runIndexedTest( int32_t index
, UBool exec
, const char* &name
, char* par
= NULL
); // overide !
124 virtual UBool
runTestLoop( char* testname
, char* par
);
126 virtual UBool
callTest( UPerfTest
& testToBeCalled
, char* par
);
129 const char* sourceDir
;
130 const char* fileName
;
131 char* resolvedFileName
;
132 const char* encoding
;
139 int32_t _remainingArgc
;
150 char* path
; // specifies subtests
154 static UPerfTest
* gTest
;
155 static const char gUsageString
[];