2002-10-31 00:37:54 +00:00
|
|
|
/*
|
|
|
|
**********************************************************************
|
2006-08-19 21:27:08 +00:00
|
|
|
* Copyright (c) 2002-2006, International Business Machines
|
2002-10-31 00:37:54 +00:00
|
|
|
* Corporation and others. All Rights Reserved.
|
|
|
|
**********************************************************************
|
|
|
|
**********************************************************************
|
|
|
|
*/
|
|
|
|
#ifndef _CHARPERF_H
|
|
|
|
#define _CHARPERF_H
|
|
|
|
|
|
|
|
#include "unicode/uchar.h"
|
2005-03-03 08:54:57 +00:00
|
|
|
|
|
|
|
#include "unicode/uperf.h"
|
2002-10-31 00:37:54 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <wchar.h>
|
2003-11-21 06:18:48 +00:00
|
|
|
#include <wctype.h>
|
2002-10-31 00:37:54 +00:00
|
|
|
|
|
|
|
typedef void (*CharPerfFn)(UChar32 ch);
|
|
|
|
typedef void (*StdLibCharPerfFn)(wchar_t ch);
|
|
|
|
|
|
|
|
class CharPerfFunction : public UPerfFunction
|
|
|
|
{
|
|
|
|
public:
|
2006-08-19 21:27:08 +00:00
|
|
|
virtual void call(UErrorCode* status)
|
|
|
|
{
|
|
|
|
for (UChar32 i = MIN_; i < MAX_; i ++) {
|
|
|
|
(*m_fn_)(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual long getOperationsPerIteration()
|
|
|
|
{
|
|
|
|
return MAX_ - MIN_;
|
|
|
|
}
|
|
|
|
CharPerfFunction(CharPerfFn func, UChar32 min, UChar32 max)
|
|
|
|
{
|
|
|
|
m_fn_ = func;
|
|
|
|
MIN_ = min;
|
|
|
|
MAX_ = max;
|
|
|
|
}
|
2002-10-31 00:37:54 +00:00
|
|
|
|
|
|
|
private:
|
2006-08-19 21:27:08 +00:00
|
|
|
CharPerfFn m_fn_;
|
|
|
|
UChar32 MIN_;
|
|
|
|
UChar32 MAX_;
|
2002-10-31 00:37:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class StdLibCharPerfFunction : public UPerfFunction
|
|
|
|
{
|
|
|
|
public:
|
2006-08-19 21:27:08 +00:00
|
|
|
virtual void call(UErrorCode* status)
|
|
|
|
{
|
|
|
|
// note wchar_t is unsigned, it will revert to 0 once it reaches
|
|
|
|
// 65535
|
|
|
|
for (wchar_t i = MIN_; i < MAX_; i ++) {
|
|
|
|
(*m_fn_)(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual long getOperationsPerIteration()
|
|
|
|
{
|
|
|
|
return MAX_ - MIN_;
|
|
|
|
}
|
|
|
|
|
|
|
|
StdLibCharPerfFunction(StdLibCharPerfFn func, wchar_t min, wchar_t max)
|
|
|
|
{
|
|
|
|
m_fn_ = func;
|
|
|
|
MIN_ = min;
|
|
|
|
MAX_ = max;
|
|
|
|
}
|
|
|
|
|
|
|
|
~StdLibCharPerfFunction()
|
|
|
|
{
|
|
|
|
}
|
2002-10-31 00:37:54 +00:00
|
|
|
|
|
|
|
private:
|
2006-08-19 21:27:08 +00:00
|
|
|
StdLibCharPerfFn m_fn_;
|
|
|
|
wchar_t MIN_;
|
|
|
|
wchar_t MAX_;
|
2002-10-31 00:37:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class CharPerformanceTest : public UPerfTest
|
|
|
|
{
|
|
|
|
public:
|
2006-08-19 21:27:08 +00:00
|
|
|
CharPerformanceTest(int32_t argc, const char *argv[], UErrorCode &status);
|
|
|
|
~CharPerformanceTest();
|
|
|
|
virtual UPerfFunction* runIndexedTest(int32_t index, UBool exec,
|
|
|
|
const char *&name,
|
|
|
|
char *par = NULL);
|
|
|
|
UPerfFunction* TestIsAlpha();
|
|
|
|
UPerfFunction* TestIsUpper();
|
|
|
|
UPerfFunction* TestIsLower();
|
|
|
|
UPerfFunction* TestIsDigit();
|
|
|
|
UPerfFunction* TestIsSpace();
|
|
|
|
UPerfFunction* TestIsAlphaNumeric();
|
|
|
|
UPerfFunction* TestIsPrint();
|
|
|
|
UPerfFunction* TestIsControl();
|
|
|
|
UPerfFunction* TestToLower();
|
|
|
|
UPerfFunction* TestToUpper();
|
|
|
|
UPerfFunction* TestIsWhiteSpace();
|
|
|
|
UPerfFunction* TestStdLibIsAlpha();
|
|
|
|
UPerfFunction* TestStdLibIsUpper();
|
|
|
|
UPerfFunction* TestStdLibIsLower();
|
|
|
|
UPerfFunction* TestStdLibIsDigit();
|
|
|
|
UPerfFunction* TestStdLibIsSpace();
|
|
|
|
UPerfFunction* TestStdLibIsAlphaNumeric();
|
|
|
|
UPerfFunction* TestStdLibIsPrint();
|
|
|
|
UPerfFunction* TestStdLibIsControl();
|
|
|
|
UPerfFunction* TestStdLibToLower();
|
|
|
|
UPerfFunction* TestStdLibToUpper();
|
|
|
|
UPerfFunction* TestStdLibIsWhiteSpace();
|
2002-10-31 00:37:54 +00:00
|
|
|
|
|
|
|
private:
|
2006-08-19 21:27:08 +00:00
|
|
|
UChar32 MIN_;
|
|
|
|
UChar32 MAX_;
|
2002-10-31 00:37:54 +00:00
|
|
|
};
|
|
|
|
|
2002-11-14 01:24:14 +00:00
|
|
|
inline void isAlpha(UChar32 ch)
|
2002-10-31 00:37:54 +00:00
|
|
|
{
|
|
|
|
u_isalpha(ch);
|
|
|
|
}
|
|
|
|
|
2002-11-14 01:24:14 +00:00
|
|
|
inline void isUpper(UChar32 ch)
|
2002-10-31 00:37:54 +00:00
|
|
|
{
|
2006-08-19 21:27:08 +00:00
|
|
|
u_isupper(ch);
|
2002-10-31 00:37:54 +00:00
|
|
|
}
|
|
|
|
|
2002-11-14 01:24:14 +00:00
|
|
|
inline void isLower(UChar32 ch)
|
2002-10-31 00:37:54 +00:00
|
|
|
{
|
2006-08-19 21:27:08 +00:00
|
|
|
u_islower(ch);
|
2002-10-31 00:37:54 +00:00
|
|
|
}
|
|
|
|
|
2002-11-14 01:24:14 +00:00
|
|
|
inline void isDigit(UChar32 ch)
|
2002-10-31 00:37:54 +00:00
|
|
|
{
|
2006-08-19 21:27:08 +00:00
|
|
|
u_isdigit(ch);
|
2002-10-31 00:37:54 +00:00
|
|
|
}
|
|
|
|
|
2002-11-14 01:24:14 +00:00
|
|
|
inline void isSpace(UChar32 ch)
|
2002-10-31 00:37:54 +00:00
|
|
|
{
|
2006-08-19 21:27:08 +00:00
|
|
|
u_isspace(ch);
|
2002-10-31 00:37:54 +00:00
|
|
|
}
|
|
|
|
|
2002-11-14 01:24:14 +00:00
|
|
|
inline void isAlphaNumeric(UChar32 ch)
|
2002-10-31 00:37:54 +00:00
|
|
|
{
|
2006-08-19 21:27:08 +00:00
|
|
|
u_isalnum(ch);
|
2002-10-31 00:37:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2006-08-19 21:27:08 +00:00
|
|
|
* 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.
|
|
|
|
*/
|
2002-11-14 01:24:14 +00:00
|
|
|
inline void isPrint(UChar32 ch)
|
2002-10-31 00:37:54 +00:00
|
|
|
{
|
2006-08-19 21:27:08 +00:00
|
|
|
u_isprint(ch);
|
2002-10-31 00:37:54 +00:00
|
|
|
}
|
|
|
|
|
2002-11-14 01:24:14 +00:00
|
|
|
inline void isControl(UChar32 ch)
|
2002-10-31 00:37:54 +00:00
|
|
|
{
|
2006-08-19 21:27:08 +00:00
|
|
|
u_iscntrl(ch);
|
2002-10-31 00:37:54 +00:00
|
|
|
}
|
|
|
|
|
2002-11-14 01:24:14 +00:00
|
|
|
inline void toLower(UChar32 ch)
|
2002-10-31 00:37:54 +00:00
|
|
|
{
|
2006-08-19 21:27:08 +00:00
|
|
|
u_tolower(ch);
|
2002-10-31 00:37:54 +00:00
|
|
|
}
|
|
|
|
|
2002-11-14 01:24:14 +00:00
|
|
|
inline void toUpper(UChar32 ch)
|
2002-10-31 00:37:54 +00:00
|
|
|
{
|
2006-08-19 21:27:08 +00:00
|
|
|
u_toupper(ch);
|
2002-10-31 00:37:54 +00:00
|
|
|
}
|
|
|
|
|
2002-11-14 01:24:14 +00:00
|
|
|
inline void isWhiteSpace(UChar32 ch)
|
2002-10-31 00:37:54 +00:00
|
|
|
{
|
2006-08-19 21:27:08 +00:00
|
|
|
u_isWhitespace(ch);
|
2002-10-31 00:37:54 +00:00
|
|
|
}
|
|
|
|
|
2002-11-14 01:24:14 +00:00
|
|
|
inline void StdLibIsAlpha(wchar_t ch)
|
2002-10-31 00:37:54 +00:00
|
|
|
{
|
2006-08-19 21:27:08 +00:00
|
|
|
iswalpha(ch);
|
2002-10-31 00:37:54 +00:00
|
|
|
}
|
|
|
|
|
2002-11-14 01:24:14 +00:00
|
|
|
inline void StdLibIsUpper(wchar_t ch)
|
2002-10-31 00:37:54 +00:00
|
|
|
{
|
2006-08-19 21:27:08 +00:00
|
|
|
iswupper(ch);
|
2002-10-31 00:37:54 +00:00
|
|
|
}
|
|
|
|
|
2002-11-14 01:24:14 +00:00
|
|
|
inline void StdLibIsLower(wchar_t ch)
|
2002-10-31 00:37:54 +00:00
|
|
|
{
|
2006-08-19 21:27:08 +00:00
|
|
|
iswlower(ch);
|
2002-10-31 00:37:54 +00:00
|
|
|
}
|
|
|
|
|
2002-11-14 01:24:14 +00:00
|
|
|
inline void StdLibIsDigit(wchar_t ch)
|
2002-10-31 00:37:54 +00:00
|
|
|
{
|
2006-08-19 21:27:08 +00:00
|
|
|
iswdigit(ch);
|
2002-10-31 00:37:54 +00:00
|
|
|
}
|
|
|
|
|
2002-11-14 01:24:14 +00:00
|
|
|
inline void StdLibIsSpace(wchar_t ch)
|
2002-10-31 00:37:54 +00:00
|
|
|
{
|
2006-08-19 21:27:08 +00:00
|
|
|
iswspace(ch);
|
2002-10-31 00:37:54 +00:00
|
|
|
}
|
|
|
|
|
2002-11-14 01:24:14 +00:00
|
|
|
inline void StdLibIsAlphaNumeric(wchar_t ch)
|
2002-10-31 00:37:54 +00:00
|
|
|
{
|
2006-08-19 21:27:08 +00:00
|
|
|
iswalnum(ch);
|
2002-10-31 00:37:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2006-08-19 21:27:08 +00:00
|
|
|
* 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.
|
|
|
|
*/
|
2002-11-14 01:24:14 +00:00
|
|
|
inline void StdLibIsPrint(wchar_t ch)
|
2002-10-31 00:37:54 +00:00
|
|
|
{
|
2006-08-19 21:27:08 +00:00
|
|
|
iswprint(ch);
|
2002-10-31 00:37:54 +00:00
|
|
|
}
|
|
|
|
|
2002-11-14 01:24:14 +00:00
|
|
|
inline void StdLibIsControl(wchar_t ch)
|
2002-10-31 00:37:54 +00:00
|
|
|
{
|
2006-08-19 21:27:08 +00:00
|
|
|
iswcntrl(ch);
|
2002-10-31 00:37:54 +00:00
|
|
|
}
|
|
|
|
|
2002-11-14 01:24:14 +00:00
|
|
|
inline void StdLibToLower(wchar_t ch)
|
2002-10-31 00:37:54 +00:00
|
|
|
{
|
2006-08-19 21:27:08 +00:00
|
|
|
towlower(ch);
|
2002-10-31 00:37:54 +00:00
|
|
|
}
|
|
|
|
|
2002-11-14 01:24:14 +00:00
|
|
|
inline void StdLibToUpper(wchar_t ch)
|
2002-10-31 00:37:54 +00:00
|
|
|
{
|
2006-08-19 21:27:08 +00:00
|
|
|
towupper(ch);
|
2002-10-31 00:37:54 +00:00
|
|
|
}
|
|
|
|
|
2002-11-14 01:24:14 +00:00
|
|
|
inline void StdLibIsWhiteSpace(wchar_t ch)
|
2002-10-31 00:37:54 +00:00
|
|
|
{
|
2006-08-19 21:27:08 +00:00
|
|
|
iswspace(ch);
|
2002-10-31 00:37:54 +00:00
|
|
|
}
|
|
|
|
|
2003-11-21 06:18:48 +00:00
|
|
|
#endif // CHARPERF_H
|