ICU-2363 weiv's changes to the perf base class:
- added locale parameter - changed output - changed test loop running - fixed some bugs X-SVN-Rev: 10291
This commit is contained in:
parent
dcce141a6d
commit
d0af485712
@ -4,6 +4,7 @@ static const char delim = '/';
|
|||||||
static int32_t execCount = 0;
|
static int32_t execCount = 0;
|
||||||
UPerfTest* UPerfTest::gTest = NULL;
|
UPerfTest* UPerfTest::gTest = NULL;
|
||||||
static const int MAXLINES = 40000;
|
static const int MAXLINES = 40000;
|
||||||
|
//static const char *currDir = ".";
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
@ -18,7 +19,8 @@ enum
|
|||||||
ITERATIONS,
|
ITERATIONS,
|
||||||
TIME,
|
TIME,
|
||||||
LINE_MODE,
|
LINE_MODE,
|
||||||
BULK_MODE
|
BULK_MODE,
|
||||||
|
LOCALE
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -35,6 +37,7 @@ UOption options[]={
|
|||||||
UOPTION_DEF( "time", 't', UOPT_REQUIRES_ARG),
|
UOPTION_DEF( "time", 't', UOPT_REQUIRES_ARG),
|
||||||
UOPTION_DEF( "line-mode", 'l', UOPT_NO_ARG),
|
UOPTION_DEF( "line-mode", 'l', UOPT_NO_ARG),
|
||||||
UOPTION_DEF( "bulk-mode", 'b', UOPT_NO_ARG),
|
UOPTION_DEF( "bulk-mode", 'b', UOPT_NO_ARG),
|
||||||
|
UOPTION_DEF( "locale", 'L', UOPT_REQUIRES_ARG)
|
||||||
};
|
};
|
||||||
|
|
||||||
UPerfTest::UPerfTest(int32_t argc, const char* argv[], UErrorCode& status){
|
UPerfTest::UPerfTest(int32_t argc, const char* argv[], UErrorCode& status){
|
||||||
@ -45,7 +48,7 @@ UPerfTest::UPerfTest(int32_t argc, const char* argv[], UErrorCode& status){
|
|||||||
encoding = "";
|
encoding = "";
|
||||||
uselen = FALSE;
|
uselen = FALSE;
|
||||||
fileName = NULL;
|
fileName = NULL;
|
||||||
sourceDir = NULL;
|
sourceDir = ".";
|
||||||
lines = NULL;
|
lines = NULL;
|
||||||
numLines = 0;
|
numLines = 0;
|
||||||
line_mode = FALSE;
|
line_mode = FALSE;
|
||||||
@ -54,6 +57,7 @@ UPerfTest::UPerfTest(int32_t argc, const char* argv[], UErrorCode& status){
|
|||||||
verbose = FALSE;
|
verbose = FALSE;
|
||||||
bulk_mode = FALSE;
|
bulk_mode = FALSE;
|
||||||
passes = iterations = time = 0;
|
passes = iterations = time = 0;
|
||||||
|
locale = NULL;
|
||||||
|
|
||||||
//initialize the argument list
|
//initialize the argument list
|
||||||
U_MAIN_INIT_ARGS(argc, argv);
|
U_MAIN_INIT_ARGS(argc, argv);
|
||||||
@ -109,6 +113,10 @@ UPerfTest::UPerfTest(int32_t argc, const char* argv[], UErrorCode& status){
|
|||||||
line_mode = FALSE;
|
line_mode = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(options[LOCALE].doesOccur) {
|
||||||
|
locale = options[LOCALE].value;
|
||||||
|
}
|
||||||
|
|
||||||
if(time > 0 && iterations >0){
|
if(time > 0 && iterations >0){
|
||||||
status = U_ILLEGAL_ARGUMENT_ERROR;
|
status = U_ILLEGAL_ARGUMENT_ERROR;
|
||||||
return;
|
return;
|
||||||
@ -181,7 +189,8 @@ UBool UPerfTest::run(){
|
|||||||
if (_argv[i][0] != '-') {
|
if (_argv[i][0] != '-') {
|
||||||
char* name = (char*) _argv[i];
|
char* name = (char*) _argv[i];
|
||||||
if(verbose==TRUE){
|
if(verbose==TRUE){
|
||||||
fprintf(stdout, "\n=== Handling test: %s: ===\n", name);
|
//fprintf(stdout, "\n=== Handling test: %s: ===\n", name);
|
||||||
|
//fprintf(stdout, "\n%s:\n", name);
|
||||||
}
|
}
|
||||||
char* parameter = strchr( name, '@' );
|
char* parameter = strchr( name, '@' );
|
||||||
if (parameter) {
|
if (parameter) {
|
||||||
@ -260,6 +269,9 @@ UBool UPerfTest::runTestLoop( char* testname, char* par )
|
|||||||
UErrorCode status = U_ZERO_ERROR;
|
UErrorCode status = U_ZERO_ERROR;
|
||||||
UPerfTest* saveTest = gTest;
|
UPerfTest* saveTest = gTest;
|
||||||
gTest = this;
|
gTest = this;
|
||||||
|
int32_t loops = 0;
|
||||||
|
double t=0;
|
||||||
|
int32_t n = 1;
|
||||||
do {
|
do {
|
||||||
this->runIndexedTest( index, FALSE, name );
|
this->runIndexedTest( index, FALSE, name );
|
||||||
if (!name || (name[0] == 0))
|
if (!name || (name[0] == 0))
|
||||||
@ -281,72 +293,86 @@ UBool UPerfTest::runTestLoop( char* testname, char* par )
|
|||||||
fprintf(stderr, "%s returned an illegal operations/iteration()\n", name);
|
fprintf(stderr, "%s returned an illegal operations/iteration()\n", name);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
double t=0;
|
if(iterations == 0) {
|
||||||
int32_t n = 1;
|
n = time;
|
||||||
long events = -1;
|
// Run for specified duration in seconds
|
||||||
if (iterations > 0) {
|
if(verbose==TRUE){
|
||||||
n = iterations;
|
fprintf(stdout,"= %s calibrating %i seconds \n" ,name, n);
|
||||||
// print info only if in verbose mode
|
}
|
||||||
if(verbose==TRUE){
|
|
||||||
fprintf(stdout,"= %s begin %i \n" ,name, n);
|
|
||||||
}
|
|
||||||
// Run the test function for specified of passe and iterations
|
|
||||||
for(int32_t ps =0; ps < passes; ps++){
|
|
||||||
t = testFunction->time(n,&status);
|
|
||||||
if(U_FAILURE(status)){
|
|
||||||
printf("Performance test failed with error: %s \n", u_errorName(status));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
events = testFunction->getEventsPerIteration();
|
|
||||||
} else {
|
|
||||||
n = time;
|
|
||||||
// Run for specified duration in seconds
|
|
||||||
if(verbose==TRUE){
|
|
||||||
fprintf(stdout,"= %s begin %i seconds \n" ,name, n);
|
|
||||||
}
|
|
||||||
|
|
||||||
//n *= 1000; // s => ms
|
//n *= 1000; // s => ms
|
||||||
//System.out.println("# " + meth.getName() + " " + n + " sec");
|
//System.out.println("# " + meth.getName() + " " + n + " sec");
|
||||||
for(int32_t ps=0;ps<passes;ps++){
|
int32_t failsafe = 1; // last resort for very fast methods
|
||||||
int32_t loops = 0;
|
t = 0;
|
||||||
int32_t failsafe = 1; // last resort for very fast methods
|
while (t < (int)(n * 0.9)) { // 90% is close enough
|
||||||
t = 0;
|
if (loops == 0 || t == 0) {
|
||||||
while (t < (int)(n * 0.9)) { // 90% is close enough
|
loops = failsafe;
|
||||||
if (loops == 0 || t == 0) {
|
failsafe *= 10;
|
||||||
loops = failsafe;
|
} else {
|
||||||
failsafe *= 10;
|
//System.out.println("# " + meth.getName() + " x " + loops + " = " + t);
|
||||||
} else {
|
loops = (int)((double)n / t * loops + 0.5);
|
||||||
//System.out.println("# " + meth.getName() + " x " + loops + " = " + t);
|
if (loops == 0) {
|
||||||
loops = (int)((double)n / t * loops + 0.5);
|
fprintf(stderr,"Unable to converge on desired duration");
|
||||||
if (loops == 0) {
|
return FALSE;
|
||||||
fprintf(stderr,"Unable to converge on desired duration");
|
}
|
||||||
return FALSE;
|
}
|
||||||
}
|
//System.out.println("# " + meth.getName() + " x " + loops);
|
||||||
}
|
|
||||||
//System.out.println("# " + meth.getName() + " x " + loops);
|
|
||||||
t = testFunction->time(loops,&status);
|
t = testFunction->time(loops,&status);
|
||||||
if(U_FAILURE(status)){
|
if(U_FAILURE(status)){
|
||||||
printf("Performance test failed with error: %s \n", u_errorName(status));
|
printf("Performance test failed with error: %s \n", u_errorName(status));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
events = testFunction->getEventsPerIteration();
|
loops = iterations;
|
||||||
}
|
}
|
||||||
//print info only in verbose mode
|
|
||||||
if(verbose==TRUE){
|
for(int32_t ps =0; ps < passes; ps++){
|
||||||
if(events == -1){
|
long events = -1;
|
||||||
fprintf(stdout,"= %s end: %f operations: %i \n",name , t , testFunction->getOperationsPerIteration());
|
fprintf(stdout,"= %s begin " ,name);
|
||||||
}else{
|
if(verbose==TRUE){
|
||||||
fprintf(stdout,"= %s end: %f operations: %i events: %i\n",name , t , testFunction->getOperationsPerIteration(), events);
|
if(iterations > 0) {
|
||||||
}
|
fprintf(stdout, "%i\n", loops);
|
||||||
}else{
|
} else {
|
||||||
if(events == -1){
|
fprintf(stdout, "%i\n", n);
|
||||||
fprintf(stdout,"= %f %i \n", t , testFunction->getOperationsPerIteration());
|
}
|
||||||
}else{
|
} else {
|
||||||
fprintf(stdout,"= %f %i %i\n", t , testFunction->getOperationsPerIteration(), events);
|
fprintf(stdout, "\n");
|
||||||
}
|
}
|
||||||
|
t = testFunction->time(loops, &status);
|
||||||
|
if(U_FAILURE(status)){
|
||||||
|
printf("Performance test failed with error: %s \n", u_errorName(status));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
events = testFunction->getEventsPerIteration();
|
||||||
|
//print info only in verbose mode
|
||||||
|
if(verbose==TRUE){
|
||||||
|
/*
|
||||||
|
if(events == -1){
|
||||||
|
fprintf(stdout,"= %s end %f %i %i\n",name , t , loops, testFunction->getOperationsPerIteration());
|
||||||
|
}else{
|
||||||
|
fprintf(stdout,"= %s end %f %i %i %i\n",name , t , loops, testFunction->getOperationsPerIteration(), events);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
if(events == -1){
|
||||||
|
fprintf(stdout,"= %s end: %f loops: %i operations: %i \n",name , t , loops, testFunction->getOperationsPerIteration());
|
||||||
|
}else{
|
||||||
|
fprintf(stdout,"= %s end: %f loops: %i operations: %i events: %i\n",name , t , loops, testFunction->getOperationsPerIteration(), events);
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
/*
|
||||||
|
if(events == -1){
|
||||||
|
fprintf(stdout,"= %f %i %i \n", t , loops, testFunction->getOperationsPerIteration());
|
||||||
|
}else{
|
||||||
|
fprintf(stdout,"= %f %i %i %i\n", t , loops, testFunction->getOperationsPerIteration(), events);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
if(events == -1){
|
||||||
|
fprintf(stdout,"= %s end %f %i %i\n",name , t , loops, testFunction->getOperationsPerIteration());
|
||||||
|
}else{
|
||||||
|
fprintf(stdout,"= %s end %f %i %i %i\n",name , t , loops, testFunction->getOperationsPerIteration(), events);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
delete testFunction;
|
delete testFunction;
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,7 @@ U_NAMESPACE_USE
|
|||||||
//| return NULL;
|
//| return NULL;
|
||||||
//| }
|
//| }
|
||||||
//| }
|
//| }
|
||||||
|
#if 0
|
||||||
#define TESTCASE(id,test) \
|
#define TESTCASE(id,test) \
|
||||||
case id: \
|
case id: \
|
||||||
name = #test; \
|
name = #test; \
|
||||||
@ -40,6 +41,15 @@ U_NAMESPACE_USE
|
|||||||
} \
|
} \
|
||||||
break
|
break
|
||||||
|
|
||||||
|
#endif
|
||||||
|
#define TESTCASE(id,test) \
|
||||||
|
case id: \
|
||||||
|
name = #test; \
|
||||||
|
if (exec) { \
|
||||||
|
return test(); \
|
||||||
|
} \
|
||||||
|
break
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Subclasses of PerfTest will need to create subclasses of
|
* Subclasses of PerfTest will need to create subclasses of
|
||||||
* Function that define a call() method which contains the code to
|
* Function that define a call() method which contains the code to
|
||||||
@ -134,6 +144,7 @@ protected:
|
|||||||
UBool bulk_mode;
|
UBool bulk_mode;
|
||||||
UChar* buffer;
|
UChar* buffer;
|
||||||
int32_t bufferLen;
|
int32_t bufferLen;
|
||||||
|
const char* locale;
|
||||||
private:
|
private:
|
||||||
UPerfTest* caller;
|
UPerfTest* caller;
|
||||||
char* path; // specifies subtests
|
char* path; // specifies subtests
|
||||||
@ -159,7 +170,8 @@ const char* UPerfTest::gUsageString =
|
|||||||
"\t-i or --iterations Number of iterations to be performed. Requires Numeric argument\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.Cannot be used with --iterations\n"
|
"\t-t or --time Threshold time for looping until in seconds. Requires Numeric argument.Cannot be used with --iterations\n"
|
||||||
"\t-l or --line-mode The data file should be processed in line mode\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. Cannot be used with --line-mode\n";
|
"\t-b or --bulk-mode The data file should be processed in file based. Cannot be used with --line-mode\n"
|
||||||
|
"\t-L or --locale Locale for the test\n";
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user