ICU-4844 port the performance tests to new perf test framework

X-SVN-Rev: 18932
This commit is contained in:
Ram Viswanadha 2005-12-30 21:40:34 +00:00
parent ac56587b0d
commit 9daf3cee7c
17 changed files with 2289 additions and 1 deletions

View File

@ -0,0 +1,82 @@
#!/usr/bin/perl -w
# ********************************************************************
# * COPYRIGHT:
# * Copyright (c) 2005, International Business Machines Corporation and
# * others. All Rights Reserved.
# ********************************************************************
use strict;
use lib '../perldriver';
use PerfFramework;
my $options = {
"title"=>"Collation performance: ICU,POSIX,and Win",
"headers"=>"ICU_POSIX_WIN",
"operationIs"=>"unicode String",
"passes"=>"1",
"time"=>"2",
#"outputType"=>"HTML",
"dataDir"=>"../data",
"outputDir"=>"../results"
};
# programs
# tests will be done for all the programs. Results will be stored and connected
my $p = "debug/collperf.exe ";
my $tests = {
"Key Gen ICU null", ["$p TestIcu_KeyGen_null"],
"Key Gen ICU len", ["$p TestIcu_KeyGen_len"],
"Key Gen POSIX", ["$p TestPosix_KeyGen_null"],
"Key Gen Win", ["$p TestWin_KeyGen_null"],
"Iteration icu forward null", ["$p TestIcu_ForwardIter_null"],
"Iteration icu forward len", ["$p TestIcu_ForwardIter_len"],
"Iteration icu backward null", ["$p TestIcu_BackwardIter_null"],
"Iteration icu backward len", ["$p TestIcu_BackwardIter_len"],
"Iteration/all icu forward null", ["$p TestIcu_ForwardIter_all_null"],
"Iteration/all icu forward len", ["$p TestIcu_ForwardIter_all_len"],
"Iteration/all icu backward null", ["$p TestIcu_BackwardIter_all_null"],
"Iteration/all icu backward len", ["$p TestIcu_BackwardIter_all_len"],
"qsort icu strcoll null", ["$p TestIcu_qsort_strcoll_null"],
"qsort icu strcoll len", ["$p TestIcu_qsort_strcoll_len"],
"qsort icu use key", ["$p TestIcu_qsort_usekey"],
"qsort posix strcoll null", ["$p TestPosix_qsort_strcoll_null"],
"qsort posix use key", ["$p TestPosix_qsort_usekey"],
"qsort win CompareStringW null", ["$p TestWin_qsort_CompareStringW_null"],
"qsort win CompareStringW len", ["$p TestWin_qsort_CompareStringW_len"],
"qsort win use key", ["$p TestWin_qsort_usekey"],
"Binary Search icu strcoll null", ["$p TestIcu_BinarySearch_strcoll_null"],
"Binary Search icu strcoll len", ["$p TestIcu_BinarySearch_strcoll_len"],
"Binary Search icu use key", ["$p TestIcu_BinarySearch_usekey"],
"Binary Search icu u_strcmp", ["$p TestIcu_BinarySearch_strcmp"],
"Binary Search icu cmpCPO", ["$p TestIcu_BinarySearch_cmpCPO"],
"Binary Search posix strcoll null", ["$p TestPosix_BinarySearch_strcoll_null"],
"Binary Search posix use key", ["$p TestPosix_BinarySearch_usekey"],
"Binary Search win CompareStringW null", ["$p TestWin_BinarySearch_CompareStringW_null"],
"Binary Search win CompareStringW len", ["$p TestWin_BinarySearch_CompareStringW_len"],
"Binary Search win use key", ["$p TestWin_BinarySearch_usekey"],
"Binary Search win wcscmp", ["$p TestWin_BinarySearch_wcscmp"],
};
my $dataFiles = {
"",
[
"TestNames_Asian.txt",
# "TestNames_Chinese.txt",
# "TestNames_Japanese.txt",
# "TestNames_Japanese_h.txt",
# "TestNames_Japanese_k.txt",
# "TestNames_Korean.txt",
# "TestNames_Latin.txt",
# "Testnames_Russian.txt",
# "TestNames_SerbianSH.txt",
# "TestNames_SerbianSR.txt",
# "TestNames_Simplified_Chinese.txt",
# "TestNames_Thai.txt"
]
};
runTests($options, $tests, $dataFiles);

View File

@ -0,0 +1,89 @@
## Makefile.in for ICU - test/collperf
## Copyright (c) 2001-2005, International Business Machines Corporation and
## others. All Rights Reserved.
## Source directory information
srcdir = @srcdir@
top_srcdir = @top_srcdir@
top_builddir = ../../..
include $(top_builddir)/icudefs.mk
## Platform-specific setup
include @platform_make_fragment@
## Build directory information
subdir = test/collperf
## Extra files to remove for 'make clean'
CLEANFILES = *~ $(DEPS)
## Target information
TARGET = collperf
DEFS = @DEFS@
CPPFLAGS = @CPPFLAGS@ -I$(top_builddir)/common -I$(top_srcdir)/common -I$(top_srcdir)/tools/toolutil
CFLAGS = @CFLAGS@
CXXFLAGS = @CXXFLAGS@
ENABLE_RPATH = @ENABLE_RPATH@
ifeq ($(ENABLE_RPATH),YES)
RPATHLDFLAGS = $(LD_RPATH)$(LD_RPATH_PRE)$(libdir)
endif
LDFLAGS = @LDFLAGS@ $(RPATHLDFLAGS)
LIBS = $(LIBICUUC) $(LIBICUI18N) $(LIBICUTOOLUTIL) @LIBS@ @LIB_M@
OBJECTS = collperf.o
DEPS = $(OBJECTS:.o=.d)
## List of phony targets
.PHONY : all all-local install install-local clean clean-local \
distclean distclean-local dist dist-local check check-local
## Clear suffix list
.SUFFIXES :
## List of standard targets
all: all-local
install: install-local
clean: clean-local
distclean : distclean-local
dist: dist-local
check: all check-local
all-local: $(TARGET)
install-local:
dist-local:
clean-local:
test -z "$(CLEANFILES)" || $(RMV) $(CLEANFILES)
$(RMV) $(OBJECTS) $(TARGET)
distclean-local: clean-local
$(RMV) Makefile
check-local: all-local
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
cd $(top_builddir) \
&& CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status
$(TARGET) : $(OBJECTS)
$(LINK.cc) -o $@ $^ $(LIBS)
invoke:
ICU_DATA=$${ICU_DATA:-$(top_builddir)/data/} TZ=PST8PDT $(INVOKE) $(INVOCATION)
ifeq (,$(MAKECMDGOALS))
-include $(DEPS)
else
ifneq ($(patsubst %clean,,$(MAKECMDGOALS)),)
ifneq ($(patsubst %install,,$(MAKECMDGOALS)),)
-include $(DEPS)
endif
endif
endif

View File

@ -0,0 +1,878 @@
/********************************************************************
* COPYRIGHT:
* Copyright (C) 2001-2005 IBM, Inc. All Rights Reserved.
*
********************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
#include <limits.h>
#include "unicode/uperf.h"
#include "uoptions.h"
#include "unicode/coll.h"
#include <unicode/ucoleitr.h>
/* To store an array of string<UNIT> in continue space.
Since string<UNIT> itself is treated as an array of UNIT, this
class will ease our memory management for an array of string<UNIT>.
*/
//template<typename UNIT>
#define COMPATCT_ARRAY(CompactArrays, UNIT) \
struct CompactArrays{\
CompactArrays(const CompactArrays & );\
CompactArrays & operator=(const CompactArrays & );\
int32_t count;/*total number of the strings*/ \
int32_t * index;/*relative offset in data*/ \
UNIT * data; /*the real space to hold strings*/ \
\
~CompactArrays(){free(index);free(data);} \
CompactArrays():data(NULL), index(NULL), count(0){ \
index = (int32_t *) realloc(index, sizeof(int32_t)); \
index[0] = 0; \
} \
void append_one(int32_t theLen){ /*include terminal NULL*/ \
count++; \
index = (int32_t *) realloc(index, sizeof(int32_t) * (count + 1)); \
index[count] = index[count - 1] + theLen; \
data = (UNIT *) realloc(data, sizeof(UNIT) * index[count]); \
} \
UNIT * last(){return data + index[count - 1];} \
UNIT * dataOf(int32_t i){return data + index[i];} \
int32_t lengthOf(int i){return index[i+1] - index[i] - 1; } /*exclude terminating NULL*/ \
};
//typedef CompactArrays<UChar> CA_uchar;
//typedef CompactArrays<char> CA_char;
//typedef CompactArrays<uint8_t> CA_uint8;
//typedef CompactArrays<WCHAR> CA_win_wchar;
COMPATCT_ARRAY(CA_uchar, UChar)
COMPATCT_ARRAY(CA_char, char)
COMPATCT_ARRAY(CA_uint8, uint8_t)
COMPATCT_ARRAY(CA_win_wchar, WCHAR)
struct DataIndex {
static DWORD win_langid; // for qsort callback function
static UCollator * col; // for qsort callback function
uint8_t * icu_key;
UChar * icu_data;
int32_t icu_data_len;
char* posix_key;
char* posix_data;
int32_t posix_data_len;
char* win_key;
WCHAR * win_data;
int32_t win_data_len;
};
DWORD DataIndex::win_langid;
UCollator * DataIndex::col;
class CmdKeyGen : public UPerfFunction {
typedef void (CmdKeyGen::* Func)(int32_t);
enum{MAX_KEY_LENGTH = 5000};
UCollator * col;
DWORD win_langid;
int32_t count;
DataIndex * data;
Func fn;
union { // to save sapce
uint8_t icu_key[MAX_KEY_LENGTH];
char posix_key[MAX_KEY_LENGTH];
WCHAR win_key[MAX_KEY_LENGTH];
};
public:
CmdKeyGen(UErrorCode, UCollator * col,DWORD win_langid, int32_t count, DataIndex * data,Func fn,int32_t)
:col(col),win_langid(win_langid), count(count), data(data), fn(fn){}
virtual long getOperationsPerIteration(){return count;}
virtual void call(UErrorCode* status){
for(int32_t i = 0; i< count; i++){
(this->*fn)(i);
}
}
void icu_key_null(int32_t i){
ucol_getSortKey(col, data[i].icu_data, -1, icu_key, MAX_KEY_LENGTH);
}
void icu_key_len(int32_t i){
ucol_getSortKey(col, data[i].icu_data, data[i].icu_data_len, icu_key, MAX_KEY_LENGTH);
}
// pre-generated in CollPerfTest::prepareData(), need not to check error here
void win_key_null(int32_t i){
//LCMAP_SORTsk 0x00000400 // WC sort sk (normalize)
LCMapStringW(win_langid, LCMAP_SORTKEY, data[i].win_data, -1, win_key, MAX_KEY_LENGTH);
}
void win_key_len(int32_t i){
LCMapStringW(win_langid, LCMAP_SORTKEY, data[i].win_data, data[i].win_data_len, win_key, MAX_KEY_LENGTH);
}
void posix_key_null(int32_t i){
strxfrm(posix_key, data[i].posix_data, MAX_KEY_LENGTH);
}
};
class CmdIter : public UPerfFunction {
typedef void (CmdIter::* Func)(UErrorCode* , int32_t );
int32_t count;
CA_uchar * data;
Func fn;
UCollationElements *iter;
int32_t exec_count;
public:
CmdIter(UErrorCode & status, UCollator * col, int32_t count, CA_uchar *data, Func fn, int32_t,int32_t)
:count(count), data(data), fn(fn){
exec_count = 0;
UChar dummytext[] = {0, 0};
iter = ucol_openElements(col, NULL, 0, &status);
ucol_setText(iter, dummytext, 1, &status);
}
~CmdIter(){
ucol_closeElements(iter);
}
virtual long getOperationsPerIteration(){return exec_count ? exec_count : 1;}
virtual void call(UErrorCode* status){
exec_count = 0;
for(int32_t i = 0; i< count; i++){
(this->*fn)(status, i);
}
}
void icu_forward_null(UErrorCode* status, int32_t i){
ucol_setText(iter, data->dataOf(i), -1, status);
while (ucol_next(iter, status) != UCOL_NULLORDER) exec_count++;
}
void icu_forward_len(UErrorCode* status, int32_t i){
ucol_setText(iter, data->dataOf(i), data->lengthOf(i) , status);
while (ucol_next(iter, status) != UCOL_NULLORDER) exec_count++;
}
void icu_backward_null(UErrorCode* status, int32_t i){
ucol_setText(iter, data->dataOf(i), -1, status);
while (ucol_previous(iter, status) != UCOL_NULLORDER) exec_count++;
}
void icu_backward_len(UErrorCode* status, int32_t i){
ucol_setText(iter, data->dataOf(i), data->lengthOf(i) , status);
while (ucol_previous(iter, status) != UCOL_NULLORDER) exec_count++;
}
};
class CmdIterAll : public UPerfFunction {
typedef void (CmdIterAll::* Func)(UErrorCode* status);
int32_t count;
UChar * data;
Func fn;
UCollationElements *iter;
int32_t exec_count;
public:
enum CALL {forward_null, forward_len, backward_null, backward_len};
~CmdIterAll(){
ucol_closeElements(iter);
}
CmdIterAll(UErrorCode & status, UCollator * col, int32_t count, UChar * data, CALL call,int32_t,int32_t)
:count(count),data(data){
exec_count = 0;
if (call == forward_null || call == backward_null) {
iter = ucol_openElements(col, data, -1, &status);
} else {
iter = ucol_openElements(col, data, count, &status);
}
if (call == forward_null || call == forward_len){
fn = icu_forward_all;
} else {
fn = icu_backward_all;
}
}
virtual long getOperationsPerIteration(){return exec_count ? exec_count : 1;}
virtual void call(UErrorCode* status){
(this->*fn)(status);
}
void icu_forward_all(UErrorCode* status){
int strlen = count - 5;
int count5 = 5;
int strindex = 0;
ucol_setOffset(iter, strindex, status);
while (TRUE) {
if (ucol_next(iter, status) == UCOL_NULLORDER) {
break;
}
exec_count++;
count5 --;
if (count5 == 0) {
strindex += 10;
if (strindex > strlen) {
break;
}
ucol_setOffset(iter, strindex, status);
count5 = 5;
}
}
}
void icu_backward_all(UErrorCode* status){
int strlen = count;
int count5 = 5;
int strindex = 5;
ucol_setOffset(iter, strindex, status);
while (TRUE) {
if (ucol_previous(iter, status) == UCOL_NULLORDER) {
break;
}
exec_count++;
count5 --;
if (count5 == 0) {
strindex += 10;
if (strindex > strlen) {
break;
}
ucol_setOffset(iter, strindex, status);
count5 = 5;
}
}
}
};
struct CmdQsort : public UPerfFunction{
static int q_random(const void * a, const void * b){
uint8_t * key_a = ((DataIndex *)a)->icu_key;
uint8_t * key_b = ((DataIndex *)b)->icu_key;
int val_a = 0;
int val_b = 0;
while (*key_a != 0) {val_a += val_a*37 + *key_a++;}
while (*key_b != 0) {val_b += val_b*37 + *key_b++;}
return val_a - val_b;
}
#define QCAST() \
DataIndex * da = (DataIndex *) a; \
DataIndex * db = (DataIndex *) b; \
++exec_count
static int icu_strcoll_null(const void *a, const void *b){
QCAST();
return ucol_strcoll(da->col, da->icu_data, -1, db->icu_data, -1) - UCOL_EQUAL;
}
static int icu_strcoll_len(const void *a, const void *b){
QCAST();
return ucol_strcoll(da->col, da->icu_data, da->icu_data_len, db->icu_data, db->icu_data_len) - UCOL_EQUAL;
}
static int icu_cmpkey (const void *a, const void *b){
QCAST();
return strcmp((char *) da->icu_key, (char *) db->icu_key);
}
static int win_cmp_null(const void *a, const void *b) {
QCAST();
//CSTR_LESS_THAN 1
//CSTR_EQUAL 2
//CSTR_GREATER_THAN 3
int t = CompareStringW(da->win_langid, 0, da->win_data, -1, db->win_data, -1);
if (t == 0){
fprintf(stderr, "CompareStringW error, error number %x\n", GetLastError());
exit(-1);
} else{
return t - CSTR_EQUAL;
}
}
static int win_cmp_len(const void *a, const void *b) {
QCAST();
int t = CompareStringW(da->win_langid, 0, da->win_data, da->win_data_len, db->win_data, db->win_data_len);
if (t == 0){
fprintf(stderr, "CompareStringW error, error number %x\n", GetLastError());
exit(-1);
} else{
return t - CSTR_EQUAL;
}
}
#define QFUNC(name, func, data) \
static int name (const void *a, const void *b){ \
QCAST(); \
return func(da->data, db->data); \
}
QFUNC(posix_strcoll_null, strcoll, posix_data)
QFUNC(posix_cmpkey, strcmp, posix_key)
QFUNC(win_cmpkey, strcmp, win_key)
QFUNC(win_wcscmp, wcscmp, win_data)
QFUNC(icu_strcmp, u_strcmp, icu_data)
QFUNC(icu_cmpcpo, u_strcmpCodePointOrder, icu_data)
private:
static int32_t exec_count; // potential muilt-thread problem
typedef int (* Func)(const void *, const void *);
Func fn;
void * base; //Start of target array.
int32_t num; //Array size in elements.
int32_t width; //Element size in bytes.
void * backup; //copy source of base
public:
CmdQsort(UErrorCode & status,void *theBase, int32_t num, int32_t width, Func fn, int32_t,int32_t)
:backup(theBase),num(num),width(width),fn(fn){
base = malloc(num * width);
time_empty(100, &status); // warm memory/cache
}
~CmdQsort(){
free(base);
}
void empty_call(){
exec_count = 0;
memcpy(base, backup, num * width);
}
double time_empty(int32_t n, UErrorCode* status) {
UTimer start, stop;
utimer_getTime(&start);
while (n-- > 0) {
empty_call();
}
utimer_getTime(&stop);
return utimer_getDeltaSeconds(&start,&stop); // ms
}
virtual void call(UErrorCode* status){
exec_count = 0;
memcpy(base, backup, num * width);
qsort(base, num, width, fn);
}
virtual double time(int32_t n, UErrorCode* status) {
double t1 = time_empty(n,status);
double t2 = UPerfFunction::time(n, status);
return t2-t1;// < 0 ? t2 : t2-t1;
}
virtual long getOperationsPerIteration(){ return exec_count?exec_count:1;}
};
int32_t CmdQsort::exec_count;
class CmdBinSearch : public UPerfFunction{
public:
typedef int (CmdBinSearch::* Func)(int, int);
UCollator * col;
DWORD win_langid;
int32_t count;
DataIndex * rnd;
DataIndex * ord;
Func fn;
int32_t exec_count;
CmdBinSearch(UErrorCode, UCollator * col,DWORD win_langid,int32_t count,DataIndex * rnd,DataIndex * ord,Func fn)
:col(col),win_langid(win_langid), count(count), rnd(rnd), ord(ord), fn(fn),exec_count(0){}
virtual void call(UErrorCode* status){
exec_count = 0;
for(int32_t i = 0; i< count; i++){ // search all data
binary_search(i);
}
}
virtual long getOperationsPerIteration(){ return exec_count?exec_count:1;}
void binary_search(int32_t random) {
int low = 0;
int high = count - 1;
int guess;
int last_guess = -1;
int r;
while (TRUE) {
guess = (high + low)/2;
if (last_guess == guess) break; // nothing to search
r = (this->*fn)(random, guess);
exec_count++;
if (r == 0)
return; // found, search end.
if (r < 0) {
high = guess;
} else {
low = guess;
}
last_guess = guess;
}
}
int icu_strcoll_null(int32_t i, int32_t j){
return ucol_strcoll(col, rnd[i].icu_data, -1, ord[j].icu_data,-1);
}
int icu_strcoll_len(int32_t i, int32_t j){
return ucol_strcoll(col, rnd[i].icu_data, rnd[i].icu_data_len, ord[j].icu_data, ord[j].icu_data_len);
}
int icu_cmpkey(int32_t i, int32_t j) {
return strcmp( (char *) rnd[i].icu_key, (char *) ord[j].icu_key );
}
int win_cmp_null(int32_t i, int32_t j) {
int t = CompareStringW(win_langid, 0, rnd[i].win_data, -1, ord[j].win_data, -1);
if (t == 0){
fprintf(stderr, "CompareStringW error, error number %x\n", GetLastError());
exit(-1);
} else{
return t - CSTR_EQUAL;
}
}
int win_cmp_len(int32_t i, int32_t j) {
int t = CompareStringW(win_langid, 0, rnd[i].win_data, rnd[i].win_data_len, ord[j].win_data, ord[j].win_data_len);
if (t == 0){
fprintf(stderr, "CompareStringW error, error number %x\n", GetLastError());
exit(-1);
} else{
return t - CSTR_EQUAL;
}
}
#define BFUNC(name, func, data) \
int name(int32_t i, int32_t j) { \
return func(rnd[i].data, ord[j].data); \
}
BFUNC(posix_strcoll_null, strcoll, posix_data)
BFUNC(posix_cmpkey, strcmp, posix_key)
BFUNC(win_cmpkey, strcmp, win_key)
BFUNC(win_wcscmp, wcscmp, win_data)
BFUNC(icu_strcmp, u_strcmp, icu_data)
BFUNC(icu_cmpcpo, u_strcmpCodePointOrder, icu_data)
};
class CollPerfTest : public UPerfTest {
public:
UCollator * col;
DWORD win_langid;
UChar * icu_data_all;
int32_t icu_data_all_len;
int32_t count;
CA_uchar * icu_data;
CA_uint8 * icu_key;
CA_char * posix_data;
CA_char * posix_key;
CA_win_wchar * win_data;
CA_char * win_key;
DataIndex * rnd_index; // random by icu key
DataIndex * ord_win_data;
DataIndex * ord_win_key;
DataIndex * ord_posix_data;
DataIndex * ord_posix_key;
DataIndex * ord_icu_data;
DataIndex * ord_icu_key;
DataIndex * ord_win_wcscmp;
DataIndex * ord_icu_strcmp;
DataIndex * ord_icu_cmpcpo;
virtual ~CollPerfTest(){
ucol_close(col);
delete [] icu_data_all;
delete icu_data;
delete icu_key;
delete posix_data;
delete posix_key;
delete win_data;
delete win_key;
delete[] rnd_index;
delete[] ord_win_data;
delete[] ord_win_key;
delete[] ord_posix_data;
delete[] ord_posix_key;
delete[] ord_icu_data;
delete[] ord_icu_key;
delete[] ord_win_wcscmp;
delete[] ord_icu_strcmp;
delete[] ord_icu_cmpcpo;
}
CollPerfTest(int32_t argc, const char* argv[], UErrorCode& status):UPerfTest(argc, argv, status){
col = NULL;
icu_data_all = NULL;
icu_data = NULL;
icu_key = NULL;
posix_data = NULL;
posix_key = NULL;
win_data =NULL;
win_key = NULL;
rnd_index = NULL;
ord_win_data= NULL;
ord_win_key= NULL;
ord_posix_data= NULL;
ord_posix_key= NULL;
ord_icu_data= NULL;
ord_icu_key= NULL;
ord_win_wcscmp = NULL;
ord_icu_strcmp = NULL;
ord_icu_cmpcpo = NULL;
if (U_FAILURE(status)){
return;
}
// Parse additional arguments
UOption options[] = {
UOPTION_DEF("langid", 'i', UOPT_REQUIRES_ARG), // Windows Language ID number.
UOPTION_DEF("rulefile", 'r', UOPT_REQUIRES_ARG), // --rulefile <filename>
// Collation related arguments. All are optional.
// To simplify parsing, two choice arguments are disigned as NO_ARG.
// The default value is UPPER word in the comment
UOPTION_DEF("c_french", 'f', UOPT_NO_ARG), // --french <on | OFF>
UOPTION_DEF("c_alternate", 'a', UOPT_NO_ARG), // --alternate <NON_IGNORE | shifted>
UOPTION_DEF("c_casefirst", 'c', UOPT_REQUIRES_ARG), // --casefirst <lower | upper | OFF>
UOPTION_DEF("c_caselevel", 'l', UOPT_NO_ARG), // --caselevel <on | OFF>
UOPTION_DEF("c_normal", 'n', UOPT_NO_ARG), // --normal <on | OFF>
UOPTION_DEF("c_strength", 's', UOPT_REQUIRES_ARG), // --strength <1-5>
};
int32_t opt_len = (sizeof(options)/sizeof(options[0]));
enum {i, r,f,a,c,l,n,s}; // The buffer between the option items' order and their references
_remainingArgc = u_parseArgs(_remainingArgc, (char**)argv, opt_len, options);
if (_remainingArgc < 0){
status = U_ILLEGAL_ARGUMENT_ERROR;
return;
}
if (locale == NULL){
locale = "en_US"; // set default locale
}
//#ifdef U_WINDOWS
if (options[i].doesOccur) {
char *endp;
int tmp = strtol(options[i].value, &endp, 0);
if (endp == options[i].value) {
status = U_ILLEGAL_ARGUMENT_ERROR;
return;
}
win_langid = MAKELCID(tmp, SORT_DEFAULT);
} else {
win_langid = uloc_getLCID(locale);
}
//#endif
// Set up an ICU collator
if (options[r].doesOccur) {
// TODO: implement it
} else {
col = ucol_open(locale, &status);
if (U_FAILURE(status)) {
return;
}
}
if (options[f].doesOccur) {
ucol_setAttribute(col, UCOL_FRENCH_COLLATION, UCOL_ON, &status);
} else {
ucol_setAttribute(col, UCOL_FRENCH_COLLATION, UCOL_OFF, &status);
}
if (options[a].doesOccur) {
ucol_setAttribute(col, UCOL_ALTERNATE_HANDLING, UCOL_SHIFTED, &status);
}
if (options[c].doesOccur) { // strcmp() has i18n encoding problem
if (strcmp("lower", options[c].value) == 0){
ucol_setAttribute(col, UCOL_CASE_FIRST, UCOL_LOWER_FIRST, &status);
} else if (strcmp("upper", options[c].value) == 0) {
ucol_setAttribute(col, UCOL_CASE_FIRST, UCOL_UPPER_FIRST, &status);
} else {
status = U_ILLEGAL_ARGUMENT_ERROR;
return;
}
}
if (options[l].doesOccur){
ucol_setAttribute(col, UCOL_CASE_LEVEL, UCOL_ON, &status);
}
if (options[n].doesOccur){
ucol_setAttribute(col, UCOL_NORMALIZATION_MODE, UCOL_ON, &status);
}
if (options[s].doesOccur) {
char *endp;
int tmp = strtol(options[l].value, &endp, 0);
if (endp == options[l].value) {
status = U_ILLEGAL_ARGUMENT_ERROR;
return;
}
switch (tmp) {
case 1: ucol_setAttribute(col, UCOL_STRENGTH, UCOL_PRIMARY, &status); break;
case 2: ucol_setAttribute(col, UCOL_STRENGTH, UCOL_SECONDARY, &status); break;
case 3: ucol_setAttribute(col, UCOL_STRENGTH, UCOL_TERTIARY, &status); break;
case 4: ucol_setAttribute(col, UCOL_STRENGTH, UCOL_QUATERNARY, &status); break;
case 5: ucol_setAttribute(col, UCOL_STRENGTH, UCOL_IDENTICAL, &status); break;
default: status = U_ILLEGAL_ARGUMENT_ERROR; return;
}
}
prepareData(status);
}
//to avoid use the annoying 'id' in TESTCASE(id,test) macro or the like
#define TEST(testname, classname, arg1, arg2, arg3, arg4, arg5, arg6) \
if(temp == index) {\
name = #testname;\
if (exec) {\
UErrorCode status = U_ZERO_ERROR;\
UPerfFunction * t = new classname(status,arg1, arg2, arg3, arg4, arg5, arg6);\
if (U_FAILURE(status)) {\
delete t;\
return NULL;\
} else {\
return t;\
}\
} else {\
return NULL;\
}\
}\
temp++\
virtual UPerfFunction* runIndexedTest( /*[in]*/int32_t index, /*[in]*/UBool exec, /*[out]*/const char* &name, /*[in]*/ char* par = NULL ){
int temp = 0;
#define TEST_KEYGEN(testname, func)\
TEST(testname, CmdKeyGen, col, win_langid, count, rnd_index, CmdKeyGen::func, 0)
TEST_KEYGEN(TestIcu_KeyGen_null, icu_key_null);
TEST_KEYGEN(TestIcu_KeyGen_len, icu_key_len);
TEST_KEYGEN(TestPosix_KeyGen_null, posix_key_null);
TEST_KEYGEN(TestWin_KeyGen_null, win_key_null);
TEST_KEYGEN(TestWin_KeyGen_len, win_key_len);
#define TEST_ITER(testname, func)\
TEST(testname, CmdIter, col, count, icu_data, CmdIter::func,0,0)
TEST_ITER(TestIcu_ForwardIter_null, icu_forward_null);
TEST_ITER(TestIcu_ForwardIter_len, icu_forward_len);
TEST_ITER(TestIcu_BackwardIter_null, icu_backward_null);
TEST_ITER(TestIcu_BackwardIter_len, icu_backward_len);
#define TEST_ITER_ALL(testname, func)\
TEST(testname, CmdIterAll, col, icu_data_all_len, icu_data_all, CmdIterAll::func,0,0)
TEST_ITER_ALL(TestIcu_ForwardIter_all_null, forward_null);
TEST_ITER_ALL(TestIcu_ForwardIter_all_len, forward_len);
TEST_ITER_ALL(TestIcu_BackwardIter_all_null, backward_null);
TEST_ITER_ALL(TestIcu_BackwardIter_all_len, backward_len);
#define TEST_QSORT(testname, func)\
TEST(testname, CmdQsort, rnd_index, count, sizeof(DataIndex), CmdQsort::func,0,0)
TEST_QSORT(TestIcu_qsort_strcoll_null, icu_strcoll_null);
TEST_QSORT(TestIcu_qsort_strcoll_len, icu_strcoll_len);
TEST_QSORT(TestIcu_qsort_usekey, icu_cmpkey);
TEST_QSORT(TestPosix_qsort_strcoll_null, posix_strcoll_null);
TEST_QSORT(TestPosix_qsort_usekey, posix_cmpkey);
TEST_QSORT(TestWin_qsort_CompareStringW_null, win_cmp_null);
TEST_QSORT(TestWin_qsort_CompareStringW_len, win_cmp_len);
TEST_QSORT(TestWin_qsort_usekey, win_cmpkey);
#define TEST_BIN(testname, func)\
TEST(testname, CmdBinSearch, col, win_langid, count, rnd_index, ord_icu_key,CmdBinSearch::func)
TEST_BIN(TestIcu_BinarySearch_strcoll_null, icu_strcoll_null);
TEST_BIN(TestIcu_BinarySearch_strcoll_len, icu_strcoll_len);
TEST_BIN(TestIcu_BinarySearch_usekey, icu_cmpkey);
TEST_BIN(TestIcu_BinarySearch_strcmp, icu_strcmp);
TEST_BIN(TestIcu_BinarySearch_cmpCPO, icu_cmpcpo);
TEST_BIN(TestPosix_BinarySearch_strcoll_null, posix_strcoll_null);
TEST_BIN(TestPosix_BinarySearch_usekey, posix_cmpkey);
TEST_BIN(TestWin_BinarySearch_CompareStringW_null, win_cmp_null);
TEST_BIN(TestWin_BinarySearch_CompareStringW_len, win_cmp_len);
TEST_BIN(TestWin_BinarySearch_usekey, win_cmpkey);
TEST_BIN(TestWin_BinarySearch_wcscmp, win_wcscmp);
name="";
return NULL;
}
void prepareData(UErrorCode& status){
if(U_FAILURE(status)) return;
if (icu_data) return; // prepared
icu_data = new CA_uchar();
// Following code is borrowed from UPerfTest::getLines();
const UChar* line=NULL;
int32_t len =0;
for (;;) {
line = ucbuf_readline(ucharBuf,&len,&status);
if(line == NULL || U_FAILURE(status)){break;}
// Refer to the source code of ucbuf_readline()
// 1. 'len' includs the line terminal symbols
// 2. The length of the line terminal symbols is only one character
// 3. The Windows CR LF line terminal symbols will be converted to CR
if (len == 1) {
continue; //skip empty line
} else {
icu_data->append_one(len);
memcpy(icu_data->last(), line, len * sizeof(UChar));
icu_data->last()[len -1] = NULL;
}
}
if(U_FAILURE(status)) return;
// UTF-16 -> UTF-8 conversion.
UConverter *conv = ucnv_open("utf-8", &status); // just UTF-8 for now.
if (U_FAILURE(status)) return;
count = icu_data->count;
icu_data_all_len = icu_data->index[count]; // includes all NULLs
icu_data_all_len -= count; // excludes all NULLs
icu_data_all_len += 1; // the terminal NULL
icu_data_all = new UChar[icu_data_all_len];
icu_data_all[icu_data_all_len - 1] = 0; //the terminal NULL
icu_key = new CA_uint8;
win_data = new CA_win_wchar;
win_key = new CA_char;
posix_data = new CA_char;
posix_key = new CA_char;
rnd_index = new DataIndex[count];
DataIndex::win_langid = win_langid;
DataIndex::col = col;
UChar * p = icu_data_all;
int32_t s;
int32_t t;
for (int i=0; i < count; i++) {
// ICU all data
s = sizeof(UChar) * icu_data->lengthOf(i);
memcpy(p, icu_data->dataOf(i), s);
p += icu_data->lengthOf(i);
// ICU data
// ICU key
s = ucol_getSortKey(col, icu_data->dataOf(i), -1,NULL, 0);
icu_key->append_one(s);
t = ucol_getSortKey(col, icu_data->dataOf(i), -1,icu_key->last(), s);
if (t != s) {status = U_INVALID_FORMAT_ERROR;return;}
// POSIX data
s = ucnv_fromUChars(conv,NULL, 0, icu_data->dataOf(i), icu_data->lengthOf(i), &status);
if (status == U_BUFFER_OVERFLOW_ERROR || status == U_ZERO_ERROR){
status = U_ZERO_ERROR;
} else {
return;
}
posix_data->append_one(s + 1); // plus terminal NULL
t = ucnv_fromUChars(conv,posix_data->last(), s, icu_data->dataOf(i), icu_data->lengthOf(i), &status);
if (U_FAILURE(status)) return;
if ( t != s){status = U_INVALID_FORMAT_ERROR;return;}
posix_data->last()[s] = 0;
// POSIX key
s = strxfrm(NULL, posix_data->dataOf(i), 0);
if (s == INT_MAX){status = U_INVALID_FORMAT_ERROR;return;}
posix_key->append_one(s);
t = strxfrm(posix_key->last(), posix_data->dataOf(i), s);
if (t != s) {status = U_INVALID_FORMAT_ERROR;return;}
// Win data
s = icu_data->lengthOf(i) + 1; // plus terminal NULL
win_data->append_one(s);
memcpy(win_data->last(), icu_data->dataOf(i), sizeof(WCHAR) * s);
// Win key
s = LCMapStringW(win_langid, LCMAP_SORTKEY, win_data->dataOf(i), win_data->lengthOf(i), NULL,0);
if (s == 0) {status = U_INVALID_FORMAT_ERROR;return;}
win_key->append_one(s);
t = LCMapStringW(win_langid, LCMAP_SORTKEY, win_data->dataOf(i), win_data->lengthOf(i), (WCHAR *)(win_key->last()),s);
if (t != s) {status = U_INVALID_FORMAT_ERROR;return;}
};
// append_one() will make points shifting, should not merge following code into previous iteration
for (int i=0; i < count; i++) {
rnd_index[i].icu_key = icu_key->dataOf(i);
rnd_index[i].icu_data = icu_data->dataOf(i);
rnd_index[i].icu_data_len = icu_data->lengthOf(i);
rnd_index[i].posix_key = posix_key->last();
rnd_index[i].posix_data = posix_data->dataOf(i);
rnd_index[i].posix_data_len = posix_data->lengthOf(i);
rnd_index[i].win_key = win_key->dataOf(i);
rnd_index[i].win_data = win_data->dataOf(i);
rnd_index[i].win_data_len = win_data->lengthOf(i);
};
ucnv_close(conv);
qsort(rnd_index, count, sizeof(DataIndex), CmdQsort::q_random);
#define SORT(data, func) \
data = new DataIndex[count];\
memcpy(data, rnd_index, count * sizeof(DataIndex));\
qsort(data, count, sizeof(DataIndex), CmdQsort::func)
SORT(ord_icu_data, icu_strcoll_len);
SORT(ord_icu_key, icu_cmpkey);
SORT(ord_posix_data, posix_strcoll_null);
SORT(ord_posix_key, posix_cmpkey);
SORT(ord_win_data, win_cmp_len);
SORT(ord_win_key, win_cmpkey);
SORT(ord_win_wcscmp, win_wcscmp);
SORT(ord_icu_strcmp, icu_strcmp);
SORT(ord_icu_cmpcpo, icu_cmpcpo);
}
};
int main(int argc, const char *argv[])
{
UErrorCode status = U_ZERO_ERROR;
CollPerfTest test(argc, argv, status);
if (U_FAILURE(status)){
printf("The error is %s\n", u_errorName(status));
//TODO: print usage here
return status;
}
if (test.run() == FALSE){
fprintf(stderr, "FAILED: Tests could not be run please check the "
"arguments.\n");
return -1;
}
return 0;
}

View File

@ -0,0 +1,179 @@
<?xml version="1.0" encoding="gb2312"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="7.10"
Name="collperf"
ProjectGUID="{01807B4A-E3B5-4B97-A7F3-207746DCD71E}"
SccProjectName=""
SccLocalPath="">
<Platforms>
<Platform
Name="Win32"/>
</Platforms>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory=".\Debug"
IntermediateDirectory=".\Debug"
ConfigurationType="1"
UseOfMFC="0"
ATLMinimizesCRunTimeLibraryUsage="FALSE"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
OptimizeForProcessor="2"
AdditionalIncludeDirectories="..\..\..\..\include;..\..\..\tools\toolutil;..\..\..\common;..\..\..\tools\ctestfw"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
PrecompiledHeaderFile=".\Debug/collperf.pch"
AssemblerListingLocation=".\Debug/"
ObjectFile=".\Debug/"
ProgramDataBaseFileName=".\Debug/"
BrowseInformation="1"
WarningLevel="3"
SuppressStartupBanner="TRUE"
DebugInformationFormat="4"
CompileAs="0"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="icuucd.lib icuind.lib icutud.lib winmm.lib icutestd.lib "
OutputFile=".\Debug/collperf.exe"
LinkIncremental="1"
SuppressStartupBanner="TRUE"
AdditionalLibraryDirectories="..\..\..\..\lib\"
GenerateDebugInformation="TRUE"
ProgramDatabaseFile=".\Debug/collperf.pdb"
SubSystem="1"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"
TypeLibraryName=".\Debug/collperf.tlb"
HeaderFileName=""/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="_DEBUG"
Culture="1033"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory=".\Release"
IntermediateDirectory=".\Release"
ConfigurationType="1"
UseOfMFC="0"
ATLMinimizesCRunTimeLibraryUsage="FALSE"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
InlineFunctionExpansion="2"
OptimizeForProcessor="2"
AdditionalIncludeDirectories="..\..\..\..\include;..\..\..\tools\toolutil;..\..\..\common;..\..\..\tools\ctestfw"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
StringPooling="TRUE"
RuntimeLibrary="2"
EnableFunctionLevelLinking="TRUE"
PrecompiledHeaderFile=".\Release/collperf.pch"
AssemblerListingLocation=".\Release/"
ObjectFile=".\Release/"
ProgramDataBaseFileName=".\Release/"
WarningLevel="3"
SuppressStartupBanner="TRUE"
CompileAs="0"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="icuuc.lib icuin.lib ctestfw.lib icutu.lib winmm.lib"
OutputFile=".\Release/collperf.exe"
LinkIncremental="1"
SuppressStartupBanner="TRUE"
AdditionalLibraryDirectories="..\..\..\lib\"
ProgramDatabaseFile=".\Release/collperf.pdb"
SubSystem="1"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"
TypeLibraryName=".\Release/collperf.tlb"
HeaderFileName=""/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="NDEBUG"
Culture="1033"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat">
<File
RelativePath="collperf.cpp">
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
BasicRuntimeChecks="3"
BrowseInformation="1"/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""/>
</FileConfiguration>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl">
</Filter>
<Filter
Name="Resource Files"
Filter="ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@ -19,6 +19,18 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ubrkperf", "ubrkperf\ubrkpe
ProjectSection(ProjectDependencies) = postProject
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "utfperf", "utfperf\utfperf.vcproj", "{E7728E98-0469-43F4-AF37-4529A3D52C6B}"
ProjectSection(ProjectDependencies) = postProject
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "collperf", "collperf\collperf.vcproj", "{01807B4A-E3B5-4B97-A7F3-207746DCD71E}"
ProjectSection(ProjectDependencies) = postProject
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "usetperf", "usetperf\usetperf.vcproj", "{EC5DF28A-D789-4C46-A55D-0AD55B50ECE8}"
ProjectSection(ProjectDependencies) = postProject
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfiguration) = preSolution
Debug = Debug
@ -45,6 +57,18 @@ Global
{7E280294-49BD-43D1-9903-CF29648D88CA}.Debug.Build.0 = Debug|Win32
{7E280294-49BD-43D1-9903-CF29648D88CA}.Release.ActiveCfg = Release|Win32
{7E280294-49BD-43D1-9903-CF29648D88CA}.Release.Build.0 = Release|Win32
{E7728E98-0469-43F4-AF37-4529A3D52C6B}.Debug.ActiveCfg = Debug|Win32
{E7728E98-0469-43F4-AF37-4529A3D52C6B}.Debug.Build.0 = Debug|Win32
{E7728E98-0469-43F4-AF37-4529A3D52C6B}.Release.ActiveCfg = Release|Win32
{E7728E98-0469-43F4-AF37-4529A3D52C6B}.Release.Build.0 = Release|Win32
{01807B4A-E3B5-4B97-A7F3-207746DCD71E}.Debug.ActiveCfg = Debug|Win32
{01807B4A-E3B5-4B97-A7F3-207746DCD71E}.Debug.Build.0 = Debug|Win32
{01807B4A-E3B5-4B97-A7F3-207746DCD71E}.Release.ActiveCfg = Release|Win32
{01807B4A-E3B5-4B97-A7F3-207746DCD71E}.Release.Build.0 = Release|Win32
{EC5DF28A-D789-4C46-A55D-0AD55B50ECE8}.Debug.ActiveCfg = Debug|Win32
{EC5DF28A-D789-4C46-A55D-0AD55B50ECE8}.Debug.Build.0 = Debug|Win32
{EC5DF28A-D789-4C46-A55D-0AD55B50ECE8}.Release.ActiveCfg = Release|Win32
{EC5DF28A-D789-4C46-A55D-0AD55B50ECE8}.Release.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
EndGlobalSection

View File

@ -0,0 +1,89 @@
## Makefile.in for ICU - test/usetperf
## Copyright (c) 2001-2005, International Business Machines Corporation and
## others. All Rights Reserved.
## Source directory information
srcdir = @srcdir@
top_srcdir = @top_srcdir@
top_builddir = ../../..
include $(top_builddir)/icudefs.mk
## Platform-specific setup
include @platform_make_fragment@
## Build directory information
subdir = test/usetperf
## Extra files to remove for 'make clean'
CLEANFILES = *~ $(DEPS)
## Target information
TARGET = usetperf
DEFS = @DEFS@
CPPFLAGS = @CPPFLAGS@ -I$(top_builddir)/common -I$(top_srcdir)/common -I$(top_srcdir)/tools/toolutil
CFLAGS = @CFLAGS@
CXXFLAGS = @CXXFLAGS@
ENABLE_RPATH = @ENABLE_RPATH@
ifeq ($(ENABLE_RPATH),YES)
RPATHLDFLAGS = $(LD_RPATH)$(LD_RPATH_PRE)$(libdir)
endif
LDFLAGS = @LDFLAGS@ $(RPATHLDFLAGS)
LIBS = $(LIBICUUC) $(LIBICUI18N) $(LIBICUTOOLUTIL) @LIBS@ @LIB_M@
OBJECTS = usetperf.o bitset.o
DEPS = $(OBJECTS:.o=.d)
## List of phony targets
.PHONY : all all-local install install-local clean clean-local \
distclean distclean-local dist dist-local check check-local
## Clear suffix list
.SUFFIXES :
## List of standard targets
all: all-local
install: install-local
clean: clean-local
distclean : distclean-local
dist: dist-local
check: all check-local
all-local: $(TARGET)
install-local:
dist-local:
clean-local:
test -z "$(CLEANFILES)" || $(RMV) $(CLEANFILES)
$(RMV) $(OBJECTS) $(TARGET)
distclean-local: clean-local
$(RMV) Makefile
check-local: all-local
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
cd $(top_builddir) \
&& CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status
$(TARGET) : $(OBJECTS)
$(LINK.cc) -o $@ $^ $(LIBS)
invoke:
ICU_DATA=$${ICU_DATA:-$(top_builddir)/data/} TZ=PST8PDT $(INVOKE) $(INVOCATION)
ifeq (,$(MAKECMDGOALS))
-include $(DEPS)
else
ifneq ($(patsubst %clean,,$(MAKECMDGOALS)),)
ifneq ($(patsubst %install,,$(MAKECMDGOALS)),)
-include $(DEPS)
endif
endif
endif

View File

@ -0,0 +1,45 @@
#!/usr/bin/perl -w
# ********************************************************************
# * COPYRIGHT:
# * Copyright (c) 2005, International Business Machines Corporation and
# * others. All Rights Reserved.
# ********************************************************************
use strict;
use lib '../perldriver';
use PerfFramework;
my $options = {
"title"=>"Uset performance: ICU",
"headers"=>"ICU",
"operationIs"=>"unicode string",
"passes"=>"1",
"time"=>"2",
#"outputType"=>"HTML",
"dataDir"=>"../data",
"outputDir"=>"../results"
};
# programs
# tests will be done for all the programs. Results will be stored and connected
my $p = "debug/usetperf.exe ";
my $tests = {
"titlecase_letter/add", ["$p titlecase_letter_add"],
"titlecase_letter/contains", ["$p titlecase_letter_contains"],
"titlecase_letter/iterator", ["$p titlecase_letter_iterator"],
"unassigned/add", ["$p unassigned_add"],
"unassigned/contains", ["$p unassigned_contains"],
"unassigned/iterator", ["$p unassigned_iterator"],
"pattern1", ["$p pattern1"],
"pattern2", ["$p pattern2"],
"pattern3", ["$p pattern3"],
};
my $dataFiles = {
};
runTests($options, $tests, $dataFiles);

View File

@ -0,0 +1,63 @@
/*
**********************************************************************
* Copyright (c) 2002-2005, International Business Machines
* Corporation and others. All Rights Reserved.
**********************************************************************
* 2002-09-20 aliu Created.
*/
#include "unicode/utypes.h"
#include "cmemory.h"
#include "bitset.h"
// TODO: have a separate capacity, so the len can just be set to
// zero in the clearAll() method, and growth can be smarter.
const int32_t SLOP = 8;
const int32_t BYTES_PER_WORD = sizeof(int32_t);
BitSet::BitSet() {
len = SLOP;
data = (int32_t*) uprv_malloc(len * BYTES_PER_WORD);
clearAll();
}
BitSet::~BitSet() {
uprv_free(data);
}
UBool BitSet::get(int32_t bitIndex) const {
uint32_t longIndex = bitIndex >> 5;
int32_t bitInLong = bitIndex & 0x1F;
return (longIndex < len) ? (((data[longIndex] >> bitInLong) & 1) != 0)
: FALSE;
}
void BitSet::set(int32_t bitIndex) {
uint32_t longIndex = bitIndex >> 5;
int32_t bitInLong = bitIndex & 0x1F;
if (longIndex >= len) {
ensureCapacity(longIndex+1);
}
data[longIndex] |= (1 << bitInLong);
}
void BitSet::clearAll() {
for (uint32_t i=0; i<len; ++i) data[i] = 0;
}
void BitSet::ensureCapacity(uint32_t minLen) {
uint32_t newLen = len;
while (newLen < minLen) newLen <<= 1; // grow exponentially
int32_t* newData = (int32_t*) uprv_malloc(newLen * BYTES_PER_WORD);
uprv_memcpy(newData, data, len * BYTES_PER_WORD);
uprv_free(data);
data = newData;
int32_t* p = data + len;
int32_t* limit = data + newLen;
while (p < limit) *p++ = 0;
len = newLen;
}
//eof

View File

@ -0,0 +1,38 @@
/*
**********************************************************************
* Copyright (c) 2002-2005, International Business Machines
* Corporation and others. All Rights Reserved.
**********************************************************************
* 2002-09-20 aliu Created.
*/
#ifndef __BITSET_H__
#define __BITSET_H__
#include "unicode/utypes.h"
/**
* A simple, limited clone of the java.util.BitSet.
*/
class BitSet {
uint32_t len;
int32_t* data;
void ensureCapacity(uint32_t minLen);
public:
BitSet();
~BitSet();
UBool get(int32_t bitIndex) const;
void set(int32_t bitIndex);
// Non-java
void clearAll();
// TODO add other methods as needed.
};
#endif

View File

@ -0,0 +1,143 @@
/*
**********************************************************************
* Copyright (c) 2002-2005, International Business Machines
* Corporation and others. All Rights Reserved.
**********************************************************************
* 2005Nov22 Raymond Yang
*
* migrate old test created by aliu to perf test framework.
*/
#include <stdio.h>
#include "unicode/utypes.h"
#include "unicode/uniset.h"
#include "unicode/uchar.h"
#include "unicode/usetiter.h"
#include "bitset.h"
#include "unicode/uperf.h"
static const char* PAT[] = {
"['A-Za-z\\u00C0-\\u00C5\\u00C7-\\u00CF\\u00D1-\\u00D6\\u00D9-\\u00DD\\u00E0-\\u00E5\\u00E7-\\u00EF\\u00F1-\\u00F6\\u00F9-\\u00FD\\u00FF-\\u010F\\u0112-\\u0125\\u0128-\\u0130\\u0134-\\u0137\\u0139-\\u013E\\u0143-\\u0148\\u014C-\\u0151\\u0154-\\u0165\\u0168-\\u017E\\u01A0-\\u01A1\\u01AF-\\u01B0\\u01CD-\\u01DC\\u01DE-\\u01E1\\u01E6-\\u01ED\\u01F0\\u01F4-\\u01F5\\u01F8-\\u01FB\\u0200-\\u021B\\u021E-\\u021F\\u0226-\\u0233\\u1E00-\\u1E99\\u1EA0-\\u1EF9\\u212A-\\u212B]",
"['.0-9A-Za-z~\\u00C0-\\u00C5\\u00C7-\\u00CF\\u00D1-\\u00D6\\u00D9-\\u00DD\\u00E0-\\u00E5\\u00E7-\\u00EF\\u00F1-\\u00F6\\u00F9-\\u00FD\\u00FF-\\u010F\\u0112-\\u0125\\u0128-\\u0130\\u0134-\\u0137\\u0139-\\u013E\\u0143-\\u0148\\u014C-\\u0151\\u0154-\\u0165\\u0168-\\u017E\\u01A0-\\u01A1\\u01AF-\\u01B0\\u01CD-\\u01DC\\u01DE-\\u01E3\\u01E6-\\u01ED\\u01F0\\u01F4-\\u01F5\\u01F8-\\u021B\\u021E-\\u021F\\u0226-\\u0233\\u0301\\u0303-\\u0304\\u0306-\\u0307\\u0310\\u0314-\\u0315\\u0323\\u0325\\u0331\\u0341\\u0344\\u0385-\\u0386\\u0388-\\u038A\\u038C\\u038E-\\u0390\\u03AC-\\u03B0\\u03CC-\\u03CE\\u03D3\\u0403\\u040C\\u040E\\u0419\\u0439\\u0453\\u045C\\u045E\\u04C1-\\u04C2\\u04D0-\\u04D1\\u04D6-\\u04D7\\u04E2-\\u04E3\\u04EE-\\u04EF\\u1E00-\\u1E99\\u1EA0-\\u1EF9\\u1F01\\u1F03-\\u1F05\\u1F07\\u1F09\\u1F0B-\\u1F0D\\u1F0F\\u1F11\\u1F13-\\u1F15\\u1F19\\u1F1B-\\u1F1D\\u1F21\\u1F23-\\u1F25\\u1F27\\u1F29\\u1F2B-\\u1F2D\\u1F2F\\u1F31\\u1F33-\\u1F35\\u1F37\\u1F39\\u1F3B-\\u1F3D\\u1F3F\\u1F41\\u1F43-\\u1F45\\u1F49\\u1F4B-\\u1F4D\\u1F51\\u1F53-\\u1F55\\u1F57\\u1F59\\u1F5B\\u1F5D\\u1F5F\\u1F61\\u1F63-\\u1F65\\u1F67\\u1F69\\u1F6B-\\u1F6D\\u1F6F\\u1F71\\u1F73\\u1F75\\u1F77\\u1F79\\u1F7B\\u1F7D\\u1F81\\u1F83-\\u1F85\\u1F87\\u1F89\\u1F8B-\\u1F8D\\u1F8F\\u1F91\\u1F93-\\u1F95\\u1F97\\u1F99\\u1F9B-\\u1F9D\\u1F9F\\u1FA1\\u1FA3-\\u1FA5\\u1FA7\\u1FA9\\u1FAB-\\u1FAD\\u1FAF-\\u1FB1\\u1FB4\\u1FB8-\\u1FB9\\u1FBB\\u1FC4\\u1FC9\\u1FCB\\u1FCE\\u1FD0-\\u1FD1\\u1FD3\\u1FD8-\\u1FD9\\u1FDB\\u1FDE\\u1FE0-\\u1FE1\\u1FE3\\u1FE5\\u1FE8-\\u1FE9\\u1FEB-\\u1FEC\\u1FEE\\u1FF4\\u1FF9\\u1FFB\\u212A-\\u212B\\uE04D\\uE064]",
"[\\u0901-\\u0903\\u0905-\\u0939\\u093C-\\u094D\\u0950-\\u0954\\u0958-\\u096F]",
};
class CmdPattern : public UPerfFunction {
private:
UnicodeString pat;
UnicodeSet set;
public:
CmdPattern(const char * pattern):pat(pattern,""){
}
virtual long getOperationsPerIteration(){
return 1;
}
virtual void call(UErrorCode* pErrorCode){
set.applyPattern(pat, *pErrorCode);
}
};
class CmdOp : public UPerfFunction {
private:
UnicodeSet us;
BitSet bs;
int32_t total;
void (CmdOp::*op) ();
public:
CmdOp(UCharCategory prop, void (CmdOp::*op)()):op(op){
total = 0;
bs.clearAll();
for (UChar32 cp=0; cp<0x110000; ++cp) {
if (u_charType(cp) == prop) {
bs.set((int32_t) cp);
++total;
}
}
}
virtual long getOperationsPerIteration(){
return total;
}
virtual void call(UErrorCode* pErrorCode){
(this->*op)();
}
void add (void){
us.clear();
for (UChar32 cp=0; cp<0x110000; ++cp) {
if (bs.get((int32_t) cp)) {
us.add(cp);
}
}
}
void contains(void){
int32_t temp = 0;
us.clear();
for (UChar32 cp=0; cp<0x110000; ++cp) {
if (us.contains(cp)) {
temp += cp;
}
}
}
void iterator(void){
int32_t temp = 0;
UnicodeSetIterator uit(us);
while (uit.next()) {
temp += uit.getCodepoint();
}
}
};
class UsetPerformanceTest : public UPerfTest{
public:
UsetPerformanceTest(int32_t argc, const char *argv[], UErrorCode &status) :UPerfTest(argc,argv,status){
}
virtual UPerfFunction* runIndexedTest( int32_t index, UBool exec, const char* &name, char* par = NULL ){
switch (index) {
case 0: name = "titlecase_letter_add";
if (exec) return new CmdOp(U_TITLECASE_LETTER, CmdOp::add) ; break;
case 1: name = "titlecase_letter_contains";
if (exec) return new CmdOp(U_TITLECASE_LETTER, CmdOp::contains) ; break;
case 2: name = "titlecase_letter_iterator";
if (exec) return new CmdOp(U_TITLECASE_LETTER, CmdOp::iterator) ; break;
case 3: name = "unassigned_add";
if (exec) return new CmdOp(U_UNASSIGNED, CmdOp::add) ; break;
case 4: name = "unassigned_contains";
if (exec) return new CmdOp(U_UNASSIGNED, CmdOp::contains) ; break;
case 5: name = "unassigned_iterator";
if (exec) return new CmdOp(U_UNASSIGNED, CmdOp::iterator) ; break;
case 6: name = "pattern1";
if (exec) return new CmdPattern(PAT[0]) ; break;
case 7: name = "pattern2";
if (exec) return new CmdPattern(PAT[1]) ; break;
case 8: name = "pattern3";
if (exec) return new CmdPattern(PAT[2]) ; break;
default: name = ""; break;
}
return NULL;
}
};
int main(int argc, const char *argv[])
{
UErrorCode status = U_ZERO_ERROR;
UsetPerformanceTest test(argc, argv, status);
if (U_FAILURE(status)){
printf("The error is %s\n", u_errorName(status));
return status;
}
if (test.run() == FALSE){
fprintf(stderr, "FAILED: Tests could not be run please check the "
"arguments.\n");
return -1;
}
return 0;
}

View File

@ -0,0 +1,203 @@
<?xml version="1.0" encoding="gb2312"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="7.10"
Name="usetperf"
ProjectGUID="{EC5DF28A-D789-4C46-A55D-0AD55B50ECE8}"
SccProjectName=""
SccLocalPath="">
<Platforms>
<Platform
Name="Win32"/>
</Platforms>
<Configurations>
<Configuration
Name="Release|Win32"
OutputDirectory=".\Release"
IntermediateDirectory=".\Release"
ConfigurationType="1"
UseOfMFC="0"
ATLMinimizesCRunTimeLibraryUsage="FALSE"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
InlineFunctionExpansion="1"
OptimizeForProcessor="2"
AdditionalIncludeDirectories="..\..\..\..\include;..\..\..\tools\toolutil;..\..\..\common;..\..\..\tools\ctestfw"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
StringPooling="TRUE"
RuntimeLibrary="2"
EnableFunctionLevelLinking="TRUE"
PrecompiledHeaderFile=".\Release/usetperf.pch"
AssemblerListingLocation=".\Release/"
ObjectFile=".\Release/"
ProgramDataBaseFileName=".\Release/"
WarningLevel="3"
SuppressStartupBanner="TRUE"
CompileAs="0"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="icuuc.lib icutu.lib winmm.lib icutest.lib"
OutputFile=".\Release/usetperf.exe"
LinkIncremental="1"
SuppressStartupBanner="TRUE"
AdditionalLibraryDirectories="..\..\..\..\lib"
ProgramDatabaseFile=".\Release/usetperf.pdb"
SubSystem="1"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"
TypeLibraryName=".\Release/usetperf.tlb"
HeaderFileName=""/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="NDEBUG"
Culture="1033"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
<Configuration
Name="Debug|Win32"
OutputDirectory=".\Debug"
IntermediateDirectory=".\Debug"
ConfigurationType="1"
UseOfMFC="0"
ATLMinimizesCRunTimeLibraryUsage="FALSE"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
OptimizeForProcessor="2"
AdditionalIncludeDirectories="..\..\..\..\include;..\..\..\tools\toolutil;..\..\..\common;..\..\..\tools\ctestfw"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
PrecompiledHeaderFile=".\Debug/usetperf.pch"
AssemblerListingLocation=".\Debug/"
ObjectFile=".\Debug/"
ProgramDataBaseFileName=".\Debug/"
WarningLevel="3"
SuppressStartupBanner="TRUE"
DebugInformationFormat="4"
CompileAs="0"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="icuucd.lib icutud.lib winmm.lib icutestd.lib"
OutputFile=".\Debug/usetperf.exe"
LinkIncremental="1"
SuppressStartupBanner="TRUE"
AdditionalLibraryDirectories="..\..\..\..\lib"
GenerateDebugInformation="TRUE"
ProgramDatabaseFile=".\Debug/usetperf.pdb"
SubSystem="1"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"
TypeLibraryName=".\Debug/usetperf.tlb"
HeaderFileName=""/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="_DEBUG"
Culture="1033"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat">
<File
RelativePath="bitset.cpp">
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
AdditionalIncludeDirectories="..\..\common"
PreprocessorDefinitions=""/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="..\..\common"
PreprocessorDefinitions=""
BasicRuntimeChecks="3"/>
</FileConfiguration>
</File>
<File
RelativePath="usetperf.cpp">
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
AdditionalIncludeDirectories="..\..\common"
PreprocessorDefinitions=""/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="..\..\common"
PreprocessorDefinitions=""
BasicRuntimeChecks="3"/>
</FileConfiguration>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl">
<File
RelativePath=".\bitset.h">
</File>
<File
RelativePath=".\timer.h">
</File>
</Filter>
<Filter
Name="Resource Files"
Filter="ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@ -102,7 +102,7 @@
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="icuuc.lib icutu.lib icutest.lib winmm.lib"
AdditionalDependencies="icuucd.lib icutud.lib icutestd.lib winmm.lib"
OutputFile=".\Debug/stringperf.exe"
LinkIncremental="1"
SuppressStartupBanner="TRUE"

View File

@ -0,0 +1,89 @@
## Makefile.in for ICU - test/utfperf
## Copyright (c) 2001-2005, International Business Machines Corporation and
## others. All Rights Reserved.
## Source directory information
srcdir = @srcdir@
top_srcdir = @top_srcdir@
top_builddir = ../../..
include $(top_builddir)/icudefs.mk
## Platform-specific setup
include @platform_make_fragment@
## Build directory information
subdir = test/utfperf
## Extra files to remove for 'make clean'
CLEANFILES = *~ $(DEPS)
## Target information
TARGET = utfperf
DEFS = @DEFS@
CPPFLAGS = @CPPFLAGS@ -I$(top_builddir)/common -I$(top_srcdir)/common -I$(top_srcdir)/tools/toolutil
CFLAGS = @CFLAGS@
CXXFLAGS = @CXXFLAGS@
ENABLE_RPATH = @ENABLE_RPATH@
ifeq ($(ENABLE_RPATH),YES)
RPATHLDFLAGS = $(LD_RPATH)$(LD_RPATH_PRE)$(libdir)
endif
LDFLAGS = @LDFLAGS@ $(RPATHLDFLAGS)
LIBS = $(LIBICUUC) $(LIBICUI18N) $(LIBICUTOOLUTIL) @LIBS@ @LIB_M@
OBJECTS = utfperf.o
DEPS = $(OBJECTS:.o=.d)
## List of phony targets
.PHONY : all all-local install install-local clean clean-local \
distclean distclean-local dist dist-local check check-local
## Clear suffix list
.SUFFIXES :
## List of standard targets
all: all-local
install: install-local
clean: clean-local
distclean : distclean-local
dist: dist-local
check: all check-local
all-local: $(TARGET)
install-local:
dist-local:
clean-local:
test -z "$(CLEANFILES)" || $(RMV) $(CLEANFILES)
$(RMV) $(OBJECTS) $(TARGET)
distclean-local: clean-local
$(RMV) Makefile
check-local: all-local
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
cd $(top_builddir) \
&& CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status
$(TARGET) : $(OBJECTS)
$(LINK.cc) -o $@ $^ $(LIBS)
invoke:
ICU_DATA=$${ICU_DATA:-$(top_builddir)/data/} TZ=PST8PDT $(INVOKE) $(INVOCATION)
ifeq (,$(MAKECMDGOALS))
-include $(DEPS)
else
ifneq ($(patsubst %clean,,$(MAKECMDGOALS)),)
ifneq ($(patsubst %install,,$(MAKECMDGOALS)),)
-include $(DEPS)
endif
endif
endif

View File

@ -0,0 +1,46 @@
#!/usr/bin/perl -w
# ********************************************************************
# * COPYRIGHT:
# * Copyright (c) 2005, International Business Machines Corporation and
# * others. All Rights Reserved.
# ********************************************************************
use strict;
use lib '../perldriver';
use PerfFramework;
my $options = {
"title"=>"Utf performance: ICU",
"headers"=>"ICU",
"operationIs"=>"gb18030 encoding string",
"passes"=>"1",
"time"=>"2",
#"outputType"=>"HTML",
"dataDir"=>"../data",
"outputDir"=>"../results"
};
# programs
# tests will be done for all the programs. Results will be stored and connected
my $p = "debug/utfperf.exe -e gb18030";
my $tests = {
"UTF-8", ["$p UTF_8"],
"UTF-8 small buffer", ["$p UTF_8_SB"],
"SCSU", ["$p SCSU"],
"SCSU small buffer", ["$p SCSU_SB"],
"BOCU_1", ["$p BOCU_1"],
"BOCU_1 small buffer", ["$p BOCU_1_SB"],
};
my $dataFiles = {
"",
[
"four.txt"
]
};
runTests($options, $tests, $dataFiles);

View File

@ -0,0 +1,156 @@
/*
**********************************************************************
* Copyright (C) 2002-2005, International Business Machines
* Corporation and others. All Rights Reserved.
**********************************************************************
* file name: utfperf.cpp
* encoding: US-ASCII
* tab size: 8 (not used)
* indentation:4
*
* created on: 2005Nov17
* created by: Raymond Yang
*
* Ported from utfper.c created by Markus W. Scherer
* Performance test program for Unicode converters
*/
#include <stdio.h>
#include "unicode/uperf.h"
/* definitions and text buffers */
#define INPUT_CAPACITY (1024*1024)
#define INTERMEDIATE_CAPACITY 4096
#define INTERMEDIATE_SMALL_CAPACITY 20
#define OUTPUT_CAPACITY INPUT_CAPACITY
static UChar input[INPUT_CAPACITY];
static UChar output[OUTPUT_CAPACITY];
static char intermediate[INTERMEDIATE_CAPACITY];
static int32_t inputLength, encodedLength, outputLength, countInputCodePoints;
class Command : public UPerfFunction {
private:
Command(const char * name, int32_t buf_cap):name(name),buf_cap(buf_cap){
errorCode=U_ZERO_ERROR;
cnv=ucnv_open(name, &errorCode);
}
public:
static UPerfFunction* get(const char * name, int32_t buf_cap){
Command * t = new Command(name, buf_cap);
if (U_SUCCESS(t->errorCode)){
return t;
} else {
//fprintf(stderr, "error opening converter for \"%s\" - %s\n", name, u_errorName(errorCode));
delete t;
return NULL;
}
}
virtual ~Command(){
if(U_SUCCESS(errorCode)) {
ucnv_close(cnv);
}
}
virtual void call(UErrorCode* pErrorCode){
const UChar *pIn, *pInLimit;
UChar *pOut, *pOutLimit;
char *pInter, *pInterLimit;
const char *p;
UBool flush;
ucnv_reset(cnv);
pIn=input;
pInLimit=input+inputLength;
pOut=output;
pOutLimit=output+OUTPUT_CAPACITY;
pInterLimit=intermediate+buf_cap;
encodedLength=outputLength=0;
flush=FALSE;
while(pIn<pInLimit || !flush) {
/* convert a block of [pIn..pInLimit[ to the encoding in intermediate[] */
pInter=intermediate;
flush=(UBool)(pIn==pInLimit);
ucnv_fromUnicode(cnv, &pInter, pInterLimit, &pIn, pInLimit, NULL, flush, pErrorCode);
encodedLength+=(int32_t)(pInter-intermediate);
if(*pErrorCode==U_BUFFER_OVERFLOW_ERROR) {
/* in case flush was TRUE make sure that we convert once more to really flush */
flush=FALSE;
*pErrorCode=U_ZERO_ERROR;
} else if(U_FAILURE(*pErrorCode)) {
return;
}
/* convert the block [intermediate..pInter[ back to UTF-16 */
p=intermediate;
ucnv_toUnicode(cnv, &pOut, pOutLimit,&p, pInter,NULL, flush,pErrorCode);
if(U_FAILURE(*pErrorCode)) {
return;
}
/* intermediate must have been consumed (p==pInter) because of the converter semantics */
}
outputLength=pOut-output;
if(inputLength!=outputLength) {
fprintf(stderr, "error: roundtrip failed, inputLength %d!=outputLength %d\n", inputLength, outputLength);
*pErrorCode=U_INTERNAL_PROGRAM_ERROR;
}
}
virtual long getOperationsPerIteration(){
return countInputCodePoints;
}
const char * name;
int32_t buf_cap;
UErrorCode errorCode;
UConverter *cnv;
};
class UtfPerformanceTest : public UPerfTest{
public:
UtfPerformanceTest(int32_t argc, const char *argv[], UErrorCode &status) :UPerfTest(argc,argv,status){
getBuffer(inputLength, status);
u_strncpy(input, buffer, inputLength);
countInputCodePoints = u_countChar32(input, inputLength);
}
virtual UPerfFunction* runIndexedTest( int32_t index, UBool exec, const char* &name, char* par = NULL ){
switch (index) {
case 0: name = "UTF_8"; if (exec) return Command::get("UTF-8", INTERMEDIATE_CAPACITY); break;
case 1: name = "UTF_8_SB"; if (exec) return Command::get("UTF-8",INTERMEDIATE_SMALL_CAPACITY); break;
case 2: name = "SCSU"; if (exec) return Command::get("SCSU", INTERMEDIATE_CAPACITY); break;
case 3: name = "SCSU_SB"; if (exec) return Command::get("SCSU", INTERMEDIATE_SMALL_CAPACITY); break;
case 4: name = "BOCU_1"; if (exec) return Command::get("BOCU-1", INTERMEDIATE_CAPACITY); break;
case 5: name = "BOCU_1_SB"; if (exec) return Command::get("BOCU-1",INTERMEDIATE_SMALL_CAPACITY); break;
default: name = ""; break;
}
return NULL;
}
};
int main(int argc, const char *argv[])
{
UErrorCode status = U_ZERO_ERROR;
UtfPerformanceTest test(argc, argv, status);
if (U_FAILURE(status)){
printf("The error is %s\n", u_errorName(status));
return status;
}
if (test.run() == FALSE){
fprintf(stderr, "FAILED: Tests could not be run please check the "
"arguments.\n");
return -1;
}
return 0;
}

View File

@ -0,0 +1,160 @@
<?xml version="1.0" encoding="gb2312"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="7.10"
Name="utfperf"
ProjectGUID="{E7728E98-0469-43F4-AF37-4529A3D52C6B}"
SccProjectName=""
SccLocalPath="">
<Platforms>
<Platform
Name="Win32"/>
</Platforms>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory=".\Debug"
IntermediateDirectory=".\Debug"
ConfigurationType="1"
UseOfMFC="0"
ATLMinimizesCRunTimeLibraryUsage="FALSE"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
OptimizeForProcessor="2"
AdditionalIncludeDirectories="..\..\..\..\include;..\..\..\tools\toolutil;..\..\..\common;..\..\..\tools\ctestfw"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
PrecompiledHeaderFile=".\Debug/utfperf.pch"
AssemblerListingLocation=".\Debug/"
ObjectFile=".\Debug/"
ProgramDataBaseFileName=".\Debug/"
WarningLevel="3"
SuppressStartupBanner="TRUE"
DebugInformationFormat="4"
CompileAs="0"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="icuucd.lib icutud.lib winmm.lib icutestd.lib"
OutputFile=".\Debug/utfperf.exe"
LinkIncremental="1"
SuppressStartupBanner="TRUE"
AdditionalLibraryDirectories="..\..\..\..\lib\"
GenerateDebugInformation="TRUE"
ProgramDatabaseFile=".\Debug/utfperf.pdb"
SubSystem="1"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"
TypeLibraryName=".\Debug/utfperf.tlb"
HeaderFileName=""/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="_DEBUG"
Culture="1033"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory=".\Release"
IntermediateDirectory=".\Release"
ConfigurationType="1"
UseOfMFC="0"
ATLMinimizesCRunTimeLibraryUsage="FALSE"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
InlineFunctionExpansion="1"
OptimizeForProcessor="2"
AdditionalIncludeDirectories="..\..\..\..\include;..\..\..\tools\toolutil;..\..\..\common;..\..\..\tools\ctestfw"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
StringPooling="TRUE"
RuntimeLibrary="2"
EnableFunctionLevelLinking="TRUE"
PrecompiledHeaderFile=".\Release/utfperf.pch"
AssemblerListingLocation=".\Release/"
ObjectFile=".\Release/"
ProgramDataBaseFileName=".\Release/"
WarningLevel="3"
SuppressStartupBanner="TRUE"
CompileAs="0"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="icuuc.lib icutu.lib icutest.lib winmm.lib "
OutputFile=".\Release/utfperf.exe"
LinkIncremental="1"
SuppressStartupBanner="TRUE"
AdditionalLibraryDirectories="..\..\..\..\lib\"
ProgramDatabaseFile=".\Release/utfperf.pdb"
SubSystem="1"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"
TypeLibraryName=".\Release/utfperf.tlb"
HeaderFileName=""/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="NDEBUG"
Culture="1033"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat">
<File
RelativePath=".\utfperf.cpp">
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl">
</Filter>
<Filter
Name="Resource Files"
Filter="ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@ -82,6 +82,10 @@ public:
virtual long getEventsPerIteration(){
return -1;
}
/**
* destructor
*/
virtual ~UPerfFunction() {}
/**
* Call call() n times in a tight loop and return the elapsed