2 **********************************************************************
3 * Copyright (c) 2002-2011, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 **********************************************************************
6 **********************************************************************
11 #include "unicode/uperf.h"
13 #include <unicode/brkiter.h>
15 class ICUBreakFunction
: public UPerfFunction
{
17 BreakIterator
*m_brkIt_
;
23 ICUBreakFunction(const char *locale
, const char *mode
, const UChar
*file
, int32_t file_len
) :
28 m_status_(U_ZERO_ERROR
)
32 m_brkIt_
= BreakIterator::createCharacterInstance(locale
, m_status_
);
35 m_brkIt_
= BreakIterator::createWordInstance(locale
, m_status_
);
38 m_brkIt_
= BreakIterator::createLineInstance(locale
, m_status_
);
41 m_brkIt_
= BreakIterator::createSentenceInstance(locale
, m_status_
);
44 // should not happen as we already check for this in the caller
45 m_status_
= U_ILLEGAL_ARGUMENT_ERROR
;
50 ~ICUBreakFunction() { delete m_brkIt_
; }
51 virtual void call(UErrorCode
*status
) = 0;
52 virtual long getOperationsPerIteration() { return m_fileLen_
; }
53 virtual long getEventsPerIteration() { return m_noBreaks_
; }
54 virtual UErrorCode
getStatus() { return m_status_
; }
57 class ICUIsBound
: public ICUBreakFunction
{
59 ICUIsBound(const char *locale
, const char *mode
, const UChar
*file
, int32_t file_len
) :
60 ICUBreakFunction(locale
, mode
, file
, file_len
)
63 m_brkIt_
->setText(UnicodeString(m_file_
, m_fileLen_
));
66 for(j
= 0; j
< m_fileLen_
; j
++) {
67 if(m_brkIt_
->isBoundary(j
)) {
72 virtual void call(UErrorCode
*status
)
76 for(j
= 0; j
< m_fileLen_
; j
++) {
77 if(m_brkIt_
->isBoundary(j
)) {
84 class ICUForward
: public ICUBreakFunction
{
86 ICUForward(const char *locale
, const char *mode
, const UChar
*file
, int32_t file_len
) :
87 ICUBreakFunction(locale
, mode
, file
, file_len
)
90 m_brkIt_
->setText(UnicodeString(m_file_
, m_fileLen_
));
92 while(m_brkIt_
->next() != BreakIterator::DONE
) {
96 virtual void call(UErrorCode
*status
)
100 while(m_brkIt_
->next() != BreakIterator::DONE
) {
106 class DarwinBreakFunction
: public UPerfFunction
{
108 virtual void call(UErrorCode
*status
) {};
111 class BreakIteratorPerformanceTest
: public UPerfTest
{
114 const UChar
* m_file_
;
118 BreakIteratorPerformanceTest(int32_t argc
, const char* argv
[], UErrorCode
& status
);
119 ~BreakIteratorPerformanceTest();
121 virtual UPerfFunction
* runIndexedTest(int32_t index
, UBool exec
,
122 const char* &name
, char* par
= NULL
);
124 UPerfFunction
* TestICUForward();
125 UPerfFunction
* TestICUIsBound();
127 UPerfFunction
* TestDarwinForward();
128 UPerfFunction
* TestDarwinIsBound();