2 ***********************************************************************
3 * Copyright (C) 2016 and later: Unicode, Inc. and others.
4 * License & terms of use: http://www.unicode.org/copyright.html#License
5 ***********************************************************************
6 **********************************************************************
7 * Copyright (c) 2002-2011, International Business Machines
8 * Corporation and others. All Rights Reserved.
9 **********************************************************************
10 **********************************************************************
15 #include "unicode/uperf.h"
17 #include <unicode/brkiter.h>
19 class ICUBreakFunction : public UPerfFunction {
21 BreakIterator *m_brkIt_;
27 ICUBreakFunction(const char *locale, const char *mode, const UChar *file, int32_t file_len) :
32 m_status_(U_ZERO_ERROR)
36 m_brkIt_ = BreakIterator::createCharacterInstance(locale, m_status_);
39 m_brkIt_ = BreakIterator::createWordInstance(locale, m_status_);
42 m_brkIt_ = BreakIterator::createLineInstance(locale, m_status_);
45 m_brkIt_ = BreakIterator::createSentenceInstance(locale, m_status_);
48 // should not happen as we already check for this in the caller
49 m_status_ = U_ILLEGAL_ARGUMENT_ERROR;
54 ~ICUBreakFunction() { delete m_brkIt_; }
55 virtual void call(UErrorCode *status) = 0;
56 virtual long getOperationsPerIteration() { return m_fileLen_; }
57 virtual long getEventsPerIteration() { return m_noBreaks_; }
58 virtual UErrorCode getStatus() { return m_status_; }
61 class ICUIsBound : public ICUBreakFunction {
63 ICUIsBound(const char *locale, const char *mode, const UChar *file, int32_t file_len) :
64 ICUBreakFunction(locale, mode, file, file_len)
67 m_brkIt_->setText(UnicodeString(m_file_, m_fileLen_));
70 for(j = 0; j < m_fileLen_; j++) {
71 if(m_brkIt_->isBoundary(j)) {
76 virtual void call(UErrorCode *status)
80 for(j = 0; j < m_fileLen_; j++) {
81 if(m_brkIt_->isBoundary(j)) {
88 class ICUForward : public ICUBreakFunction {
90 ICUForward(const char *locale, const char *mode, const UChar *file, int32_t file_len) :
91 ICUBreakFunction(locale, mode, file, file_len)
94 m_brkIt_->setText(UnicodeString(m_file_, m_fileLen_));
96 while(m_brkIt_->next() != BreakIterator::DONE) {
100 virtual void call(UErrorCode *status)
104 while(m_brkIt_->next() != BreakIterator::DONE) {
110 class DarwinBreakFunction : public UPerfFunction {
112 virtual void call(UErrorCode *status) {};
115 class BreakIteratorPerformanceTest : public UPerfTest {
118 const UChar* m_file_;
122 BreakIteratorPerformanceTest(int32_t argc, const char* argv[], UErrorCode& status);
123 ~BreakIteratorPerformanceTest();
125 virtual UPerfFunction* runIndexedTest(int32_t index, UBool exec,
126 const char* &name, char* par = NULL);
128 UPerfFunction* TestICUForward();
129 UPerfFunction* TestICUIsBound();
131 UPerfFunction* TestDarwinForward();
132 UPerfFunction* TestDarwinIsBound();