ICU-7275 added -x option and several new performance tests
X-SVN-Rev: 28387
This commit is contained in:
parent
3183eeaac0
commit
3432e64ad6
@ -9,6 +9,7 @@
|
||||
#include "DateFmtPerf.h"
|
||||
#include "uoptions.h"
|
||||
#include <stdio.h>
|
||||
#include <fstream>
|
||||
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
@ -16,6 +17,9 @@ using namespace std;
|
||||
DateFormatPerfTest::DateFormatPerfTest(int32_t argc, const char* argv[], UErrorCode& status)
|
||||
: UPerfTest(argc,argv,status) {
|
||||
|
||||
if (locale == NULL){
|
||||
locale = "en_US"; // set default locale
|
||||
}
|
||||
}
|
||||
|
||||
DateFormatPerfTest::~DateFormatPerfTest()
|
||||
@ -34,6 +38,10 @@ UPerfFunction* DateFormatPerfTest::runIndexedTest(int32_t index, UBool exec,cons
|
||||
TESTCASE(4,BreakItWord10000);
|
||||
TESTCASE(5,BreakItChar250);
|
||||
TESTCASE(6,BreakItChar10000);
|
||||
TESTCASE(7,NumFmt10000);
|
||||
TESTCASE(8,NumFmt100000);
|
||||
TESTCASE(9,Collation10000);
|
||||
TESTCASE(10,Collation100000);
|
||||
|
||||
default:
|
||||
name = "";
|
||||
@ -44,17 +52,17 @@ UPerfFunction* DateFormatPerfTest::runIndexedTest(int32_t index, UBool exec,cons
|
||||
|
||||
|
||||
UPerfFunction* DateFormatPerfTest::DateFmt250(){
|
||||
DateFmtFunction* func= new DateFmtFunction(1);
|
||||
DateFmtFunction* func= new DateFmtFunction(1, locale);
|
||||
return func;
|
||||
}
|
||||
|
||||
UPerfFunction* DateFormatPerfTest::DateFmt10000(){
|
||||
DateFmtFunction* func= new DateFmtFunction(40);
|
||||
DateFmtFunction* func= new DateFmtFunction(40, locale);
|
||||
return func;
|
||||
}
|
||||
|
||||
UPerfFunction* DateFormatPerfTest::DateFmt100000(){
|
||||
DateFmtFunction* func= new DateFmtFunction(400);
|
||||
DateFmtFunction* func= new DateFmtFunction(400, locale);
|
||||
return func;
|
||||
}
|
||||
|
||||
@ -78,23 +86,94 @@ UPerfFunction* DateFormatPerfTest::BreakItChar10000(){
|
||||
return func;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main(int argc, const char* argv[]){
|
||||
|
||||
cout << "ICU version - " << U_ICU_VERSION << endl;
|
||||
// -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]);
|
||||
|
||||
for(int i = 0; i < 5; i++)
|
||||
{
|
||||
switch(i)
|
||||
{
|
||||
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;
|
||||
}
|
||||
out << t[i] << endl;
|
||||
}
|
||||
out.close();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// Normal performance test mode
|
||||
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
DateFormatPerfTest test(argc, argv, status);
|
||||
|
||||
|
||||
if(U_FAILURE(status)){ // ERROR HERE!!!
|
||||
cout << "initialize failed! " << status << endl;
|
||||
return status;
|
||||
}
|
||||
//cout << "Done initializing!\n" << endl;
|
||||
|
||||
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;
|
||||
|
||||
return 0;
|
||||
}
|
@ -15,9 +15,15 @@
|
||||
#include "unicode/calendar.h"
|
||||
#include "unicode/uclean.h"
|
||||
#include "unicode/brkiter.h"
|
||||
#include "unicode/numfmt.h"
|
||||
#include "unicode/coll.h"
|
||||
#include "unicode/utypes.h"
|
||||
#include "util.h"
|
||||
|
||||
#include "datedata.h"
|
||||
#include "breakdata.h"
|
||||
#include "collationdata.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
@ -51,10 +57,10 @@ public:
|
||||
BreakIterator* boundary;
|
||||
|
||||
if(wordIteration)
|
||||
{
|
||||
{
|
||||
for(int i = 0; i < num; i++)
|
||||
{
|
||||
boundary = BreakIterator::createWordInstance(Locale::getUS(), *status);
|
||||
boundary = BreakIterator::createWordInstance("en", *status);
|
||||
boundary->setText(str);
|
||||
|
||||
int32_t start = boundary->first();
|
||||
@ -66,10 +72,11 @@ public:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else // character iteration
|
||||
{
|
||||
for(int i = 0; i < num; i++)
|
||||
{
|
||||
{
|
||||
boundary = BreakIterator::createCharacterInstance(Locale::getUS(), *status);
|
||||
boundary->setText(str);
|
||||
|
||||
@ -131,6 +138,7 @@ class DateFmtFunction : public UPerfFunction
|
||||
|
||||
private:
|
||||
int num;
|
||||
char locale[25];
|
||||
public:
|
||||
|
||||
DateFmtFunction()
|
||||
@ -138,13 +146,15 @@ public:
|
||||
num = -1;
|
||||
}
|
||||
|
||||
DateFmtFunction(int a)
|
||||
DateFmtFunction(int a, const char* loc)
|
||||
{
|
||||
num = a;
|
||||
strcpy(locale, loc);
|
||||
}
|
||||
|
||||
virtual void call(UErrorCode* status)
|
||||
{
|
||||
|
||||
UErrorCode status2 = U_ZERO_ERROR;
|
||||
Calendar *cal;
|
||||
TimeZone *zone;
|
||||
@ -156,10 +166,10 @@ public:
|
||||
zone = TimeZone::createTimeZone("GMT"); // Create a GMT zone
|
||||
cal->adoptTimeZone(zone);
|
||||
|
||||
Locale loc("en");
|
||||
Locale loc(locale);
|
||||
DateFormat *fmt;
|
||||
fmt = DateFormat::createDateTimeInstance(
|
||||
DateFormat::kFull, DateFormat::kFull, loc);
|
||||
DateFormat::kShort, DateFormat::kFull, loc);
|
||||
|
||||
|
||||
// (dates are imported from datedata.h)
|
||||
@ -187,7 +197,6 @@ public:
|
||||
delete fmt;
|
||||
delete cal;
|
||||
//u_cleanup();
|
||||
|
||||
}
|
||||
|
||||
virtual long getOperationsPerIteration()
|
||||
@ -218,6 +227,176 @@ public:
|
||||
|
||||
};
|
||||
|
||||
class NumFmtFunction : public UPerfFunction
|
||||
{
|
||||
|
||||
private:
|
||||
int num;
|
||||
char locale[25];
|
||||
public:
|
||||
|
||||
NumFmtFunction()
|
||||
{
|
||||
num = -1;
|
||||
}
|
||||
|
||||
NumFmtFunction(int a, const char* loc)
|
||||
{
|
||||
num = a;
|
||||
strcpy(locale, loc);
|
||||
}
|
||||
|
||||
virtual void call(UErrorCode* status2)
|
||||
{
|
||||
Locale loc(locale);
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
|
||||
// Create a number formatter for the locale
|
||||
NumberFormat *fmt = NumberFormat::createInstance(loc, status);
|
||||
|
||||
// Parse a string. The string uses the digits '0' through '9'
|
||||
// and the decimal separator '.', standard in the US locale
|
||||
|
||||
for(int i = 0; i < num; i++)
|
||||
{
|
||||
UnicodeString str("9876543210.123");
|
||||
Formattable result;
|
||||
fmt->parse(str, result, status);
|
||||
|
||||
//uprintf(formattableToString(result));
|
||||
//printf("\n");
|
||||
|
||||
// Take the number parsed above, and use the formatter to
|
||||
// format it.
|
||||
str.remove(); // format() will APPEND to this string
|
||||
fmt->format(result, str, status);
|
||||
|
||||
//uprintf(str);
|
||||
//printf("\n");
|
||||
}
|
||||
|
||||
delete fmt; // Release the storage used by the formatter
|
||||
}
|
||||
|
||||
enum {
|
||||
U_SPACE=0x20,
|
||||
U_DQUOTE=0x22,
|
||||
U_COMMA=0x2c,
|
||||
U_LEFT_SQUARE_BRACKET=0x5b,
|
||||
U_BACKSLASH=0x5c,
|
||||
U_RIGHT_SQUARE_BRACKET=0x5d,
|
||||
U_SMALL_U=0x75
|
||||
};
|
||||
|
||||
// Create a display string for a formattable
|
||||
UnicodeString formattableToString(const Formattable& f) {
|
||||
switch (f.getType()) {
|
||||
case Formattable::kDate:
|
||||
// TODO: Finish implementing this
|
||||
return UNICODE_STRING_SIMPLE("Formattable_DATE_TBD");
|
||||
case Formattable::kDouble:
|
||||
{
|
||||
char buf[256];
|
||||
sprintf(buf, "%gD", f.getDouble());
|
||||
return UnicodeString(buf, "");
|
||||
}
|
||||
case Formattable::kLong:
|
||||
case Formattable::kInt64:
|
||||
{
|
||||
char buf[256];
|
||||
sprintf(buf, "%ldL", f.getLong());
|
||||
return UnicodeString(buf, "");
|
||||
}
|
||||
case Formattable::kString:
|
||||
return UnicodeString((UChar)U_DQUOTE).append(f.getString()).append((UChar)U_DQUOTE);
|
||||
case Formattable::kArray:
|
||||
{
|
||||
int32_t i, count;
|
||||
const Formattable* array = f.getArray(count);
|
||||
UnicodeString result((UChar)U_LEFT_SQUARE_BRACKET);
|
||||
for (i=0; i<count; ++i) {
|
||||
if (i > 0) {
|
||||
(result += (UChar)U_COMMA) += (UChar)U_SPACE;
|
||||
}
|
||||
result += formattableToString(array[i]);
|
||||
}
|
||||
result += (UChar)U_RIGHT_SQUARE_BRACKET;
|
||||
return result;
|
||||
}
|
||||
default:
|
||||
return UNICODE_STRING_SIMPLE("INVALID_Formattable");
|
||||
}
|
||||
}
|
||||
|
||||
virtual long getOperationsPerIteration()
|
||||
{
|
||||
return num;
|
||||
}
|
||||
|
||||
// Print the given string to stdout using the UTF-8 converter (for debugging purposes only)
|
||||
void uprintf(const UnicodeString &str) {
|
||||
char stackBuffer[100];
|
||||
char *buf = 0;
|
||||
|
||||
int32_t bufLen = str.extract(0, 0x7fffffff, stackBuffer, sizeof(stackBuffer), "UTF-8");
|
||||
if(bufLen < sizeof(stackBuffer)) {
|
||||
buf = stackBuffer;
|
||||
} else {
|
||||
buf = new char[bufLen + 1];
|
||||
bufLen = str.extract(0, 0x7fffffff, buf, bufLen + 1, "UTF-8");
|
||||
}
|
||||
printf("%s", buf);
|
||||
if(buf != stackBuffer) {
|
||||
delete[] buf;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class CollationFunction : public UPerfFunction
|
||||
{
|
||||
|
||||
private:
|
||||
int num;
|
||||
char locale[25];
|
||||
public:
|
||||
|
||||
CollationFunction()
|
||||
{
|
||||
num = -1;
|
||||
}
|
||||
|
||||
CollationFunction(int a, const char* loc)
|
||||
{
|
||||
num = a;
|
||||
strcpy(locale, loc);
|
||||
}
|
||||
|
||||
virtual void call(UErrorCode* status2)
|
||||
{
|
||||
uint32_t listSize = sizeof(collation_strings)/sizeof(collation_strings[0]);
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
Collator *coll = Collator::createInstance(Locale(locale), status);
|
||||
|
||||
for(int k = 0; k < num; k++)
|
||||
{
|
||||
uint32_t i, j;
|
||||
for(i=listSize-1; i>=1; i--) {
|
||||
for(j=0; j<i; j++) {
|
||||
if(coll->compare(collation_strings[j], collation_strings[j+1]) == UCOL_LESS) {
|
||||
//cout << "Success!" << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
delete coll;
|
||||
}
|
||||
|
||||
virtual long getOperationsPerIteration()
|
||||
{
|
||||
return num;
|
||||
}
|
||||
};
|
||||
|
||||
class DateFormatPerfTest : public UPerfTest
|
||||
{
|
||||
private:
|
||||
@ -235,6 +414,10 @@ public:
|
||||
UPerfFunction* BreakItWord10000();
|
||||
UPerfFunction* BreakItChar250();
|
||||
UPerfFunction* BreakItChar10000();
|
||||
UPerfFunction* NumFmt10000();
|
||||
UPerfFunction* NumFmt100000();
|
||||
UPerfFunction* Collation10000();
|
||||
UPerfFunction* Collation100000();
|
||||
};
|
||||
|
||||
#endif // DateFmtPerf
|
@ -41,13 +41,14 @@
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories="..\..\..\..\include;..\..\..\tools\toolutil;..\..\..\common;..\..\..\tools\ctestfw"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="3"
|
||||
UsePrecompiledHeader="2"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
DebugInformationFormat="4"
|
||||
DebugInformationFormat="0"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
@ -60,6 +61,7 @@
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="icuucd.lib icutud.lib icutestd.lib winmm.lib icuucd.lib icuind.lib"
|
||||
OutputFile=".\x86\Debug/datefmtperf.exe"
|
||||
LinkIncremental="2"
|
||||
AdditionalLibraryDirectories="..\..\..\..\lib\"
|
||||
@ -194,6 +196,10 @@
|
||||
RelativePath=".\breakdata.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\collationdata.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\datedata.h"
|
||||
>
|
||||
|
@ -14,4 +14,4 @@ UnicodeString str =
|
||||
"The official release date of all Project Gutenberg Etexts is at"
|
||||
"Midnight, Central Time, of the last day of the stated month. A"
|
||||
"preliminary version may often be posted for suggestion, comment"
|
||||
"and editing by those who wish to do so.";
|
||||
"and editing by those who wish to do so.";
|
||||
|
Loading…
Reference in New Issue
Block a user