1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259
|
/***********************************************************************
* © 2016 and later: Unicode, Inc. and others.
* License & terms of use: http://www.unicode.org/copyright.html
***********************************************************************
***********************************************************************
* COPYRIGHT:
* Copyright (C) 2002-2016 IBM, Inc. All Rights Reserved.
*
***********************************************************************/
/*****************************************************************************
* File charperf.cpp
*
* Modification History:
* Name Description
* Syn Wee Quek First Version
******************************************************************************
*/
/**
* This program tests character properties performance.
* APIs tested:
* ICU4C
* Windows
*/
#include "charperf.h"
#include "cmemory.h"
#include "uoptions.h"
UOption options[] = {
UOPTION_DEF("min", 'n', UOPT_REQUIRES_ARG),
UOPTION_DEF("min", 'x', UOPT_REQUIRES_ARG),
};
int MIN_OPTION_ = 0;
int MAX_OPTION_ = 1;
int main(int argc, const char *argv[])
{
UErrorCode status = U_ZERO_ERROR;
CharPerformanceTest test(argc, argv, status);
if (U_FAILURE(status)){
return status;
}
if (test.run() == false){
fprintf(stderr, "FAILED: Tests could not be run please check the "
"arguments.\n");
return -1;
}
return 0;
}
CharPerformanceTest::CharPerformanceTest(int32_t argc, const char *argv[],
UErrorCode &status)
: UPerfTest(argc, argv, status)
{
if (status== U_ILLEGAL_ARGUMENT_ERROR){
fprintf(stderr,gUsageString, "charperf");
return;
}
if (U_FAILURE(status)){
fprintf(stderr, "FAILED to create UPerfTest object. Error: %s\n",
u_errorName(status));
return;
}
if (_remainingArgc < 0) {
// that means there are some -names not matched in the super class
// first tag is always skipped in u_parseArgs
int size = - _remainingArgc;
argv += argc - size;
argc = size;
_remainingArgc = u_parseArgs(argc, const_cast<char**>(argv),
UPRV_LENGTHOF(options), options);
}
MIN_ = 0;
if (sizeof(wchar_t) > 2) {
// for stdlibs like glibc that supports 32 bits wchar
// we test for the whole unicode character set by default
MAX_ = 0x10ffff;
}
else {
MAX_ = 0xffff;
}
if (options[MIN_OPTION_].doesOccur) {
MIN_ = atoi(options[MIN_OPTION_].value);
}
if (options[MAX_OPTION_].doesOccur) {
MAX_ = atoi(options[MAX_OPTION_].value);
}
}
CharPerformanceTest::~CharPerformanceTest()
{
}
UPerfFunction* CharPerformanceTest::runIndexedTest(int32_t index, UBool exec,
const char *&name,
char* par)
{
switch (index) {
TESTCASE(0, TestIsAlpha);
TESTCASE(1, TestIsUpper);
TESTCASE(2, TestIsLower);
TESTCASE(3, TestIsDigit);
TESTCASE(4, TestIsSpace);
TESTCASE(5, TestIsAlphaNumeric);
TESTCASE(6, TestIsPrint);
TESTCASE(7, TestIsControl);
TESTCASE(8, TestToLower);
TESTCASE(9, TestToUpper);
TESTCASE(10, TestIsWhiteSpace);
TESTCASE(11, TestStdLibIsAlpha);
TESTCASE(12, TestStdLibIsUpper);
TESTCASE(13, TestStdLibIsLower);
TESTCASE(14, TestStdLibIsDigit);
TESTCASE(15, TestStdLibIsSpace);
TESTCASE(16, TestStdLibIsAlphaNumeric);
TESTCASE(17, TestStdLibIsPrint);
TESTCASE(18, TestStdLibIsControl);
TESTCASE(19, TestStdLibToLower);
TESTCASE(20, TestStdLibToUpper);
TESTCASE(21, TestStdLibIsWhiteSpace);
default:
name = "";
return nullptr;
}
return nullptr;
}
UPerfFunction* CharPerformanceTest::TestIsAlpha()
{
return new CharPerfFunction(isAlpha, MIN_, MAX_);
}
UPerfFunction* CharPerformanceTest::TestIsUpper()
{
return new CharPerfFunction(isUpper, MIN_, MAX_);
}
UPerfFunction* CharPerformanceTest::TestIsLower()
{
return new CharPerfFunction(isLower, MIN_, MAX_);
}
UPerfFunction* CharPerformanceTest::TestIsDigit()
{
return new CharPerfFunction(isDigit, MIN_, MAX_);
}
UPerfFunction* CharPerformanceTest::TestIsSpace()
{
return new CharPerfFunction(isSpace, MIN_, MAX_);
}
UPerfFunction* CharPerformanceTest::TestIsAlphaNumeric()
{
return new CharPerfFunction(isAlphaNumeric, MIN_, MAX_);
}
/**
* This test may be different since c lib has a type PUNCT and it is printable.
* iswgraph is not used for testing since it is a subset of iswprint with the
* exception of returning true for white spaces. no match found in icu4c.
*/
UPerfFunction* CharPerformanceTest::TestIsPrint()
{
return new CharPerfFunction(isPrint, MIN_, MAX_);
}
UPerfFunction* CharPerformanceTest::TestIsControl()
{
return new CharPerfFunction(isControl, MIN_, MAX_);
}
UPerfFunction* CharPerformanceTest::TestToLower()
{
return new CharPerfFunction(toLower, MIN_, MAX_);
}
UPerfFunction* CharPerformanceTest::TestToUpper()
{
return new CharPerfFunction(toUpper, MIN_, MAX_);
}
UPerfFunction* CharPerformanceTest::TestIsWhiteSpace()
{
return new CharPerfFunction(isWhiteSpace, MIN_, MAX_);
}
UPerfFunction* CharPerformanceTest::TestStdLibIsAlpha()
{
return new StdLibCharPerfFunction(StdLibIsAlpha, static_cast<wchar_t>(MIN_),
static_cast<wchar_t>(MAX_));
}
UPerfFunction* CharPerformanceTest::TestStdLibIsUpper()
{
return new StdLibCharPerfFunction(StdLibIsUpper, static_cast<wchar_t>(MIN_),
static_cast<wchar_t>(MAX_));
}
UPerfFunction* CharPerformanceTest::TestStdLibIsLower()
{
return new StdLibCharPerfFunction(StdLibIsLower, static_cast<wchar_t>(MIN_),
static_cast<wchar_t>(MAX_));
}
UPerfFunction* CharPerformanceTest::TestStdLibIsDigit()
{
return new StdLibCharPerfFunction(StdLibIsDigit, static_cast<wchar_t>(MIN_),
static_cast<wchar_t>(MAX_));
}
UPerfFunction* CharPerformanceTest::TestStdLibIsSpace()
{
return new StdLibCharPerfFunction(StdLibIsSpace, static_cast<wchar_t>(MIN_),
static_cast<wchar_t>(MAX_));
}
UPerfFunction* CharPerformanceTest::TestStdLibIsAlphaNumeric()
{
return new StdLibCharPerfFunction(StdLibIsAlphaNumeric, static_cast<wchar_t>(MIN_),
static_cast<wchar_t>(MAX_));
}
/**
* This test may be different since c lib has a type PUNCT and it is printable.
* iswgraph is not used for testing since it is a subset of iswprint with the
* exception of returning true for white spaces. no match found in icu4c.
*/
UPerfFunction* CharPerformanceTest::TestStdLibIsPrint()
{
return new StdLibCharPerfFunction(StdLibIsPrint, static_cast<wchar_t>(MIN_),
static_cast<wchar_t>(MAX_));
}
UPerfFunction* CharPerformanceTest::TestStdLibIsControl()
{
return new StdLibCharPerfFunction(StdLibIsControl, static_cast<wchar_t>(MIN_),
static_cast<wchar_t>(MAX_));
}
UPerfFunction* CharPerformanceTest::TestStdLibToLower()
{
return new StdLibCharPerfFunction(StdLibToLower, static_cast<wchar_t>(MIN_),
static_cast<wchar_t>(MAX_));
}
UPerfFunction* CharPerformanceTest::TestStdLibToUpper()
{
return new StdLibCharPerfFunction(StdLibToUpper, static_cast<wchar_t>(MIN_),
static_cast<wchar_t>(MAX_));
}
UPerfFunction* CharPerformanceTest::TestStdLibIsWhiteSpace()
{
return new StdLibCharPerfFunction(StdLibIsWhiteSpace, static_cast<wchar_t>(MIN_),
static_cast<wchar_t>(MAX_));
}
|