X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/b25be06635768807f8f693286fa73bb2297bb06c..4388f060552cc537e71e957d32f35e9d75a61233:/icuSources/test/perf/howExpensiveIs/howExpensiveIs.cpp diff --git a/icuSources/test/perf/howExpensiveIs/howExpensiveIs.cpp b/icuSources/test/perf/howExpensiveIs/howExpensiveIs.cpp new file mode 100644 index 00000000..b0205fc9 --- /dev/null +++ b/icuSources/test/perf/howExpensiveIs/howExpensiveIs.cpp @@ -0,0 +1,200 @@ +/* + ********************************************************************** + * Copyright (c) 2011,International Business Machines + * Corporation and others. All Rights Reserved. + ********************************************************************** + */ +#include +#include "sieve.h" +#include "unicode/utimer.h" +#include "udbgutil.h" + +void runTests(void); + +FILE *out = NULL; +UErrorCode setupStatus = U_ZERO_ERROR; + +int main(int argc, const char* argv[]){ +#if U_DEBUG + fprintf(stderr,"%s: warning: U_DEBUG is on.\n", argv[0]); +#endif +#if U_DEBUG + { + double m; + double s = uprv_getSieveTime(&m); + fprintf(stderr, "** Standard sieve time: %.9fs +/- %.9fs (%d iterations)\n", s,m, (int)U_LOTS_OF_TIMES); + } +#endif + + if(argc==2) { + out=fopen(argv[1],"w"); + if(out==NULL) { + fprintf(stderr,"Err: can't open %s for writing.\n", argv[1]); + return 1; + } + fprintf(out, "\n"); + fprintf(out, "\n", U_ICU_VERSION); + fprintf(out, "\n", U_COPYRIGHT_STRING); + } else if(argc>2) { + fprintf(stderr, "Err: usage: %s [ output-file.xml ]\n", argv[0]); + return 1; + } + + runTests(); + + + if(out!=NULL) { + udbg_writeIcuInfo(out); + fprintf(out, "\n"); + fclose(out); + } + + if(U_FAILURE(setupStatus)) { + fprintf(stderr, "Error in tests: %s\n", u_errorName(setupStatus)); + return 1; + } + + return 0; +} + +class HowExpensiveTest { +public: + virtual ~HowExpensiveTest(){} +protected: + HowExpensiveTest(const char *name, const char *file, int32_t line) : fName(name), fFile(file), fLine(line) {} +protected: + /** + * @return number of iterations + */ + virtual int32_t run() = 0; + virtual void warmup() { run(); } +public: + virtual int32_t runTest(double *subTime) { + UTimer a,b; + utimer_getTime(&a); + int32_t iter = run(); + utimer_getTime(&b); + *subTime = utimer_getDeltaSeconds(&a,&b); + return iter; + } + + virtual int32_t runTests(double *subTime, double *marginOfError) { + warmup(); /* warmup */ + #define ITERATIONS 5 + double times[ITERATIONS]; + int subIterations = 0; + for(int i=0;i\n", + t.fName,stn,st,me,iter); + fflush(out); + } +} + +/* ------------------- test code here --------------------- */ + +class SieveTest : public HowExpensiveTest { +public: + virtual ~SieveTest(){} + SieveTest():HowExpensiveTest("SieveTest",__FILE__,__LINE__){} + virtual int32_t run(){return 0;} // dummy + int32_t runTest(double *subTime) { + *subTime = uprv_getSieveTime(NULL); + return U_LOTS_OF_TIMES; + } + virtual int32_t runTests(double *subTime, double *marginOfError) { + *subTime = uprv_getSieveTime(marginOfError); + return U_LOTS_OF_TIMES; + } +}; + + +/* ------- NumParseTest ------------- */ +#include "unicode/unum.h" +/* open and close tests */ +#define OCName(svc,ub,testn,suffix,n) testn ## svc ## ub ## suffix ## n +#define OCStr(svc,ub,suffix,n) "Test_" # svc # ub # suffix # n +#define OCRun(svc,ub,suffix) svc ## ub ## suffix +// TODO: run away screaming +#define OpenCloseTest(n, svc,suffix,c,a,d) class OCName(svc,_,Test_,suffix,n) : public HowExpensiveTest { public: OCName(svc,_,Test_,suffix,n)():HowExpensiveTest(OCStr(svc,_,suffix,n),__FILE__,__LINE__) c int32_t run() { int32_t i; for(i=0;i