2010-07-09 16:14:46 +00:00
|
|
|
/*
|
|
|
|
**********************************************************************
|
|
|
|
* Copyright (c) 2002-2010,International Business Machines
|
|
|
|
* Corporation and others. All Rights Reserved.
|
|
|
|
**********************************************************************
|
|
|
|
**********************************************************************
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "DateFmtPerf.h"
|
|
|
|
#include "uoptions.h"
|
|
|
|
#include <stdio.h>
|
2010-07-29 19:09:01 +00:00
|
|
|
#include <fstream>
|
2010-07-09 16:14:46 +00:00
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
DateFormatPerfTest::DateFormatPerfTest(int32_t argc, const char* argv[], UErrorCode& status)
|
|
|
|
: UPerfTest(argc,argv,status) {
|
|
|
|
|
2010-07-29 19:09:01 +00:00
|
|
|
if (locale == NULL){
|
|
|
|
locale = "en_US"; // set default locale
|
|
|
|
}
|
2010-07-09 16:14:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DateFormatPerfTest::~DateFormatPerfTest()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
UPerfFunction* DateFormatPerfTest::runIndexedTest(int32_t index, UBool exec,const char* &name, char* par) {
|
|
|
|
|
|
|
|
//exec = true;
|
|
|
|
|
|
|
|
switch (index) {
|
|
|
|
TESTCASE(0,DateFmt250);
|
|
|
|
TESTCASE(1,DateFmt10000);
|
|
|
|
TESTCASE(2,DateFmt100000);
|
|
|
|
TESTCASE(3,BreakItWord250);
|
|
|
|
TESTCASE(4,BreakItWord10000);
|
|
|
|
TESTCASE(5,BreakItChar250);
|
|
|
|
TESTCASE(6,BreakItChar10000);
|
2010-07-29 19:09:01 +00:00
|
|
|
TESTCASE(7,NumFmt10000);
|
|
|
|
TESTCASE(8,NumFmt100000);
|
|
|
|
TESTCASE(9,Collation10000);
|
|
|
|
TESTCASE(10,Collation100000);
|
2010-07-09 16:14:46 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
name = "";
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
UPerfFunction* DateFormatPerfTest::DateFmt250(){
|
2010-07-29 19:09:01 +00:00
|
|
|
DateFmtFunction* func= new DateFmtFunction(1, locale);
|
2010-07-09 16:14:46 +00:00
|
|
|
return func;
|
|
|
|
}
|
|
|
|
|
|
|
|
UPerfFunction* DateFormatPerfTest::DateFmt10000(){
|
2010-07-29 19:09:01 +00:00
|
|
|
DateFmtFunction* func= new DateFmtFunction(40, locale);
|
2010-07-09 16:14:46 +00:00
|
|
|
return func;
|
|
|
|
}
|
|
|
|
|
|
|
|
UPerfFunction* DateFormatPerfTest::DateFmt100000(){
|
2010-07-29 19:09:01 +00:00
|
|
|
DateFmtFunction* func= new DateFmtFunction(400, locale);
|
2010-07-09 16:14:46 +00:00
|
|
|
return func;
|
|
|
|
}
|
|
|
|
|
|
|
|
UPerfFunction* DateFormatPerfTest::BreakItWord250(){
|
|
|
|
BreakItFunction* func= new BreakItFunction(250, true);
|
|
|
|
return func;
|
|
|
|
}
|
|
|
|
|
|
|
|
UPerfFunction* DateFormatPerfTest::BreakItWord10000(){
|
|
|
|
BreakItFunction* func= new BreakItFunction(10000, true);
|
|
|
|
return func;
|
|
|
|
}
|
|
|
|
|
|
|
|
UPerfFunction* DateFormatPerfTest::BreakItChar250(){
|
|
|
|
BreakItFunction* func= new BreakItFunction(250, false);
|
|
|
|
return func;
|
|
|
|
}
|
|
|
|
|
|
|
|
UPerfFunction* DateFormatPerfTest::BreakItChar10000(){
|
|
|
|
BreakItFunction* func= new BreakItFunction(10000, false);
|
|
|
|
return func;
|
|
|
|
}
|
|
|
|
|
2010-07-29 19:09:01 +00:00
|
|
|
UPerfFunction* DateFormatPerfTest::NumFmt10000(){
|
|
|
|
NumFmtFunction* func= new NumFmtFunction(10000, locale);
|
|
|
|
return func;
|
|
|
|
}
|
|
|
|
|
|
|
|
UPerfFunction* DateFormatPerfTest::NumFmt100000(){
|
|
|
|
NumFmtFunction* func= new NumFmtFunction(100000, locale);
|
|
|
|
return func;
|
|
|
|
}
|
|
|
|
|
|
|
|
UPerfFunction* DateFormatPerfTest::Collation10000(){
|
|
|
|
CollationFunction* func= new CollationFunction(40, locale);
|
|
|
|
return func;
|
|
|
|
}
|
|
|
|
|
|
|
|
UPerfFunction* DateFormatPerfTest::Collation100000(){
|
|
|
|
CollationFunction* func= new CollationFunction(400, locale);
|
|
|
|
return func;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-09 16:14:46 +00:00
|
|
|
|
|
|
|
int main(int argc, const char* argv[]){
|
|
|
|
|
2010-07-29 19:09:01 +00:00
|
|
|
// -x Filename.xml
|
|
|
|
if(strcmp(argv[1],"-x") == 0)
|
|
|
|
{
|
|
|
|
if(argc < 3) return 0; // not enough arguments
|
|
|
|
|
|
|
|
cout << "ICU version - " << U_ICU_VERSION << endl;
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
|
|
|
|
// Declare functions
|
|
|
|
UPerfFunction *functions[5];
|
|
|
|
functions[0] = new DateFmtFunction(40, "en");
|
|
|
|
functions[1] = new BreakItFunction(10000, true); // breakIterator word
|
|
|
|
functions[2] = new BreakItFunction(10000, false); // breakIterator char
|
|
|
|
functions[3] = new NumFmtFunction(100000, "en");
|
|
|
|
functions[4] = new CollationFunction(400, "en");
|
|
|
|
|
|
|
|
// Perform time recording
|
|
|
|
double t[5];
|
|
|
|
for(int i = 0; i < 5; i++) t[i] = 0;
|
|
|
|
|
|
|
|
for(int i = 0; i < 10; i++)
|
|
|
|
for(int j = 0; j < 5; j++)
|
|
|
|
t[j] += (functions[j]->time(1, &status) / 10);
|
|
|
|
|
|
|
|
|
|
|
|
// Output results as .xml
|
|
|
|
ofstream out;
|
|
|
|
out.open(argv[2]);
|
|
|
|
|
2010-08-04 17:36:18 +00:00
|
|
|
out << "<perfTestResults icu=\"c\" version=\"" << U_ICU_VERSION << "\">" << endl;
|
|
|
|
|
2010-07-29 19:09:01 +00:00
|
|
|
for(int i = 0; i < 5; i++)
|
|
|
|
{
|
2010-08-04 17:36:18 +00:00
|
|
|
out << " <perfTestResult" << endl;
|
|
|
|
out << " test=\"";
|
2010-07-29 19:09:01 +00:00
|
|
|
switch(i)
|
|
|
|
{
|
2010-08-04 17:36:18 +00:00
|
|
|
case 0: out << "DateFormat"; break;
|
|
|
|
case 1: out << "BreakIterator Word"; break;
|
|
|
|
case 2: out << "BreakIterator Char"; break;
|
|
|
|
case 3: out << "NumbFormat"; break;
|
|
|
|
case 4: out << "Collation"; break;
|
2010-07-29 19:09:01 +00:00
|
|
|
}
|
2010-08-04 17:36:18 +00:00
|
|
|
out << "\"" << endl;
|
|
|
|
int iter = 10000;
|
|
|
|
if(i > 2) iter = 100000;
|
|
|
|
out << " iterations=\"" << iter << "\"" << endl;
|
|
|
|
out << " time=\"" << t[i] << "\" />" << endl;
|
2010-07-29 19:09:01 +00:00
|
|
|
}
|
2010-08-04 17:36:18 +00:00
|
|
|
out << "</perfTestResults>" << endl;
|
2010-07-29 19:09:01 +00:00
|
|
|
out.close();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Normal performance test mode
|
2010-08-04 17:36:18 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
2010-07-09 16:14:46 +00:00
|
|
|
|
|
|
|
DateFormatPerfTest test(argc, argv, status);
|
2010-07-29 19:09:01 +00:00
|
|
|
|
|
|
|
|
2010-07-09 16:14:46 +00:00
|
|
|
if(U_FAILURE(status)){ // ERROR HERE!!!
|
|
|
|
cout << "initialize failed! " << status << endl;
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
//cout << "Done initializing!\n" << endl;
|
2010-07-29 19:09:01 +00:00
|
|
|
|
2010-07-09 16:14:46 +00:00
|
|
|
if(test.run()==FALSE){
|
|
|
|
cout << "run failed!" << endl;
|
|
|
|
fprintf(stderr,"FAILED: Tests could not be run please check the arguments.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
cout << "done!" << endl;
|
2010-07-29 19:09:01 +00:00
|
|
|
|
2010-07-09 16:14:46 +00:00
|
|
|
return 0;
|
|
|
|
}
|