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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/intl/icu/source/tools/ctestfw/unicode/uperf.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,179 @@
     1.4 +/*
     1.5 +**********************************************************************
     1.6 +* Copyright (c) 2002-2011, International Business Machines
     1.7 +* Corporation and others.  All Rights Reserved.
     1.8 +**********************************************************************
     1.9 +*/
    1.10 +#ifndef _UPERF_H
    1.11 +#define _UPERF_H
    1.12 +
    1.13 +#include "unicode/utypes.h"
    1.14 +#include "unicode/unistr.h"
    1.15 +#include "unicode/ustring.h"
    1.16 +
    1.17 +#include "unicode/testtype.h"
    1.18 +#include "unicode/utimer.h"
    1.19 +#include "ucbuf.h"
    1.20 +
    1.21 +// Forward declarations from uoptions.h.
    1.22 +struct UOption;
    1.23 +typedef struct UOption UOption;
    1.24 +
    1.25 +#if !UCONFIG_NO_CONVERSION
    1.26 +
    1.27 +U_NAMESPACE_USE
    1.28 +// Use the TESTCASE macro in subclasses of IntlTest.  Define the
    1.29 +// runIndexedTest method in this fashion:
    1.30 +//
    1.31 +//| void MyTest::runIndexedTest(int32_t index, UBool exec,
    1.32 +//|                             const char* &name, char* /*par*/) {
    1.33 +//|     switch (index) {
    1.34 +//|         TESTCASE(0,TestSomething);
    1.35 +//|         TESTCASE(1,TestSomethingElse);
    1.36 +//|         TESTCASE(2,TestAnotherThing);
    1.37 +//|         default: 
    1.38 +//|             name = ""; 
    1.39 +//|             return NULL;
    1.40 +//|     }
    1.41 +//| }
    1.42 +#if 0
    1.43 +#define TESTCASE(id,test)                       \
    1.44 +    case id:                                    \
    1.45 +        name = #test;                           \
    1.46 +        if (exec) {                             \
    1.47 +            fprintf(stdout,#test "---");        \
    1.48 +            fprintf(stdout,"\n");               \
    1.49 +            return test();                      \
    1.50 +        }                                       \
    1.51 +        break
    1.52 +
    1.53 +#endif
    1.54 +#define TESTCASE(id,test)                       \
    1.55 +    case id:                                    \
    1.56 +        name = #test;                           \
    1.57 +        if (exec) {                             \
    1.58 +            return test();                      \
    1.59 +        }                                       \
    1.60 +        break
    1.61 +
    1.62 +/**
    1.63 + * Subclasses of PerfTest will need to create subclasses of
    1.64 + * Function that define a call() method which contains the code to
    1.65 + * be timed.  They then call setTestFunction() in their "Test..."
    1.66 + * method to establish this as the current test functor.
    1.67 + */
    1.68 +class T_CTEST_EXPORT_API UPerfFunction {
    1.69 +public:
    1.70 +    /**
    1.71 +     * destructor
    1.72 +     */
    1.73 +    virtual ~UPerfFunction();
    1.74 +
    1.75 +    /**
    1.76 +     * Subclasses must implement this method to do the action to be
    1.77 +     * measured.
    1.78 +     */
    1.79 +    virtual void call(UErrorCode* status)=0;
    1.80 +
    1.81 +    /**
    1.82 +     * Subclasses must implement this method to return positive
    1.83 +     * integer indicating the number of operations in a single
    1.84 +     * call to this object's call() method.
    1.85 +     */
    1.86 +    virtual long getOperationsPerIteration()=0;
    1.87 +    /**
    1.88 +     * Subclasses should override this method to return either positive
    1.89 +     * or negative integer indicating the number of events in a single
    1.90 +     * call to this object's call() method, if applicable
    1.91 +     * e.g: Number of breaks / iterations for break iterator
    1.92 +     */
    1.93 +    virtual long getEventsPerIteration(){
    1.94 +        return -1;
    1.95 +    }
    1.96 +    /**
    1.97 +     * Call call() n times in a tight loop and return the elapsed
    1.98 +     * milliseconds.  If n is small and call() is fast the return
    1.99 +     * result may be zero.  Small return values have limited
   1.100 +     * meaningfulness, depending on the underlying CPU and OS.
   1.101 +     */
   1.102 +     virtual double time(int32_t n, UErrorCode* status) {
   1.103 +        UTimer start, stop;
   1.104 +        utimer_getTime(&start); 
   1.105 +        while (n-- > 0) {
   1.106 +            call(status);
   1.107 +        }
   1.108 +        utimer_getTime(&stop);
   1.109 +        return utimer_getDeltaSeconds(&start,&stop); // ms
   1.110 +    }
   1.111 +
   1.112 +};
   1.113 +
   1.114 +
   1.115 +class T_CTEST_EXPORT_API UPerfTest {
   1.116 +public:
   1.117 +    UBool run();
   1.118 +    UBool runTest( char* name = NULL, char* par = NULL ); // not to be overidden
   1.119 +        
   1.120 +    virtual void usage( void ) ;
   1.121 +    
   1.122 +    virtual ~UPerfTest();
   1.123 +
   1.124 +    void setCaller( UPerfTest* callingTest ); // for internal use only
   1.125 +    
   1.126 +    void setPath( char* path ); // for internal use only
   1.127 +    
   1.128 +    ULine* getLines(UErrorCode& status);
   1.129 +
   1.130 +    const UChar* getBuffer(int32_t& len,UErrorCode& status);
   1.131 +
   1.132 +protected:
   1.133 +    UPerfTest(int32_t argc, const char* argv[], UErrorCode& status);
   1.134 +
   1.135 +    UPerfTest(int32_t argc, const char* argv[],
   1.136 +              UOption addOptions[], int32_t addOptionsCount,
   1.137 +              const char *addUsage,
   1.138 +              UErrorCode& status);
   1.139 +
   1.140 +    void init(UOption addOptions[], int32_t addOptionsCount,
   1.141 +              UErrorCode& status);
   1.142 +
   1.143 +    virtual UPerfFunction* runIndexedTest( int32_t index, UBool exec, const char* &name, char* par = NULL ); // overide !
   1.144 +
   1.145 +    virtual UBool runTestLoop( char* testname, char* par );
   1.146 +
   1.147 +    virtual UBool callTest( UPerfTest& testToBeCalled, char* par );
   1.148 +
   1.149 +    int32_t      _argc;
   1.150 +    const char** _argv;
   1.151 +    const char * _addUsage;
   1.152 +    char*        resolvedFileName;
   1.153 +    UCHARBUF*    ucharBuf;
   1.154 +    const char*  encoding;
   1.155 +    UBool        uselen;
   1.156 +    const char*  fileName;
   1.157 +    const char*  sourceDir;
   1.158 +    int32_t      _remainingArgc;
   1.159 +    ULine*       lines;
   1.160 +    int32_t      numLines;
   1.161 +    UBool        line_mode;
   1.162 +    UChar* buffer;
   1.163 +    int32_t      bufferLen;
   1.164 +    UBool        verbose;
   1.165 +    UBool        bulk_mode;
   1.166 +    int32_t      passes;
   1.167 +    int32_t      iterations;
   1.168 +    int32_t      time;
   1.169 +    const char*  locale;
   1.170 +private:
   1.171 +    UPerfTest*   caller;
   1.172 +    char*        path;           // specifies subtests
   1.173 +
   1.174 +// static members
   1.175 +public:
   1.176 +    static UPerfTest* gTest;
   1.177 +    static const char gUsageString[];
   1.178 +};
   1.179 +
   1.180 +#endif
   1.181 +#endif
   1.182 +

mercurial