staticconstchar delim = '/'; static int32_t execCount = 0;
UPerfTest* UPerfTest::gTest = nullptr; staticconstint MAXLINES = 40000; constchar UPerfTest::gUsageString[] = "Usage: %s [OPTIONS] [FILES]\n" "\tReads the input file and prints out time taken in seconds\n" "Options:\n" "\t-h or -? or --help this usage text\n" "\t-v or --verbose print extra information when processing files\n" "\t-s or --sourcedir source directory for files followed by path\n" "\t followed by path\n" "\t-e or --encoding encoding of source files\n" "\t-u or --uselen perform timing analysis on non-null terminated buffer using length\n" "\t-f or --file-name file to be used as input data\n" "\t-p or --passes Number of passes to be performed. Requires Numeric argument.\n" "\t Cannot be used with --time\n" "\t-i or --iterations Number of iterations to be performed. Requires Numeric argument\n" "\t-t or --time Threshold time for looping until in seconds. Requires Numeric argument.\n" "\t Cannot be used with --iterations\n" "\t-l or --line-mode The data file should be processed in line mode\n" "\t-b or --bulk-mode The data file should be processed in file based.\n" "\t Cannot be used with --line-mode\n" "\t-L or --locale Locale for the test\n";
if(U_FAILURE(status)){
printf("Could not open the input file %s. Error: %s\n", fileName, u_errorName(status)); return;
}
}
}
ULine* UPerfTest::getLines(UErrorCode& status){ if (U_FAILURE(status)) { return nullptr;
} if (lines != nullptr) { return lines; // don't do it again
}
lines = new ULine[MAXLINES]; int maxLines = MAXLINES;
numLines=0; const char16_t* line=nullptr;
int32_t len =0; for (;;) {
line = ucbuf_readline(ucharBuf,&len,&status); if(line == nullptr || U_FAILURE(status)){ break;
}
lines[numLines].name = new char16_t[len];
lines[numLines].len = len;
memcpy(lines[numLines].name, line, len * U_SIZEOF_UCHAR);
numLines++;
len = 0; if (numLines >= maxLines) {
maxLines += MAXLINES;
ULine *newLines = new ULine[maxLines]; if(newLines == nullptr) {
fprintf(stderr, "Out of memory reading line %d.\n", static_cast<int>(numLines));
status= U_MEMORY_ALLOCATION_ERROR; delete []lines; return nullptr;
}
memcpy(newLines, lines, numLines*sizeof(ULine)); delete []lines;
lines = newLines;
}
} return lines;
} const char16_t* UPerfTest::getBuffer(int32_t& len, UErrorCode& status){ if (U_FAILURE(status)) { return nullptr;
}
len = ucbuf_size(ucharBuf);
buffer = static_cast<char16_t*>(uprv_malloc(U_SIZEOF_UCHAR * (len + 1)));
u_strncpy(buffer,ucbuf_getBuffer(ucharBuf,&bufferLen,&status),len);
buffer[len]=0;
len = bufferLen; return buffer;
}
UBool UPerfTest::run(){ if(_remainingArgc==1){ // Testing all methods return runTest();
}
UBool res=false; // Test only the specified function for (int i = 1; i < _remainingArgc; ++i) { if (_argv[i][0] != '-') { char* name = const_cast<char*>(_argv[i]); if(verbose==true){ //fprintf(stdout, "\n=== Handling test: %s: ===\n", name); //fprintf(stdout, "\n%s:\n", name);
} char* parameter = strchr( name, '@' ); if (parameter) {
*parameter = 0;
parameter += 1;
}
execCount = 0;
res = runTest( name, parameter ); if (!res || (execCount <= 0)) {
fprintf(stdout, "\n---ERROR: Test doesn't exist: %s!\n", name); returnfalse;
}
}
} return res;
}
UBool UPerfTest::runTest(char* name, char* par ){
UBool rval; char* pos = nullptr;
if (name)
pos = strchr( name, delim ); // check if name contains path (by looking for '/') if (pos) {
path = pos+1; // store subpath for calling subtest
*pos = 0; // split into two strings
}else{
path = nullptr;
}
// call individual tests, to be overridden to call implementations
UPerfFunction* UPerfTest::runIndexedTest( int32_t /*index*/, UBool /*exec*/, const char* & /*name*/, char* /*par*/ )
{ // to be overridden by a method like: /* switch (index) { case 0: name = "First Test"; if (exec) FirstTest( par ); break; case 1: name = "Second Test"; if (exec) SecondTest( par ); break; default: name = ""; break; }
*/
fprintf(stderr,"*** runIndexedTest needs to be overridden! ***"); return nullptr;
}
UBool UPerfTest::runTestLoop( char* testname, char* par )
{
int32_t index = 0; constchar* name;
UBool run_this_test;
UBool rval = false;
UErrorCode status = U_ZERO_ERROR;
UPerfTest* saveTest = gTest;
gTest = this;
int32_t loops = 0; double t=0;
int32_t n = 1; long ops; do {
this->runIndexedTest( index, false, name ); if (!name || (name[0] == 0)) break; if (!testname) {
run_this_test = true;
}else{
run_this_test = static_cast<UBool>(strcmp(name, testname) == 0);
} if (run_this_test) {
UPerfFunction* testFunction = this->runIndexedTest( index, true, name, par );
execCount++;
rval=true; if(testFunction==nullptr){
fprintf(stderr,"%s function returned nullptr", name); returnfalse;
}
ops = testFunction->getOperationsPerIteration(); if (ops < 1) {
fprintf(stderr, "%s returned an illegal operations/iteration()\n", name); returnfalse;
} if(iterations == 0) {
n = time; // Run for specified duration in seconds if(verbose==true){
fprintf(stdout, "= %s calibrating %i seconds \n", name, static_cast<int>(n));
}
//n *= 1000; // s => ms //System.out.println("# " + meth.getName() + " " + n + " sec");
int32_t failsafe = 1; // last resort for very fast methods
t = 0; while (t < static_cast<int>(n * 0.9)) { // 90% is close enough if (loops == 0 || t == 0) {
loops = failsafe;
failsafe *= 10;
} else { //System.out.println("# " + meth.getName() + " x " + loops + " = " + t);
loops = static_cast<int>(static_cast<double>(n) / t * loops + 0.5); if (loops == 0) {
fprintf(stderr,"Unable to converge on desired duration"); returnfalse;
}
} //System.out.println("# " + meth.getName() + " x " + loops);
t = testFunction->time(loops,&status); if(U_FAILURE(status)){
printf("Performance test failed with error: %s \n", u_errorName(status)); break;
}
}
} else {
loops = iterations;
}
double min_t=1000000.0, sum_t=0.0; long events = -1;
UBool UPerfTest::callTest( UPerfTest& testToBeCalled, char* par )
{
execCount--; // correct a previously assumed test-exec, as this only calls a subtest
testToBeCalled.setCaller( this ); return testToBeCalled.runTest( path, par );
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.