summaryrefslogtreecommitdiff
path: root/Build/source/libs/icu-xetex/test/perf/ubrkperf/ubrkperf.h
blob: 4c55a73976c385b7f9f007579296f26789687245 (plain)
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
/*
**********************************************************************
* Copyright (c) 2002-2005, International Business Machines
* Corporation and others.  All Rights Reserved.
**********************************************************************
**********************************************************************
*/
#ifndef _UBRKPERF_H
#define _UBRKPERF_H

#include "unicode/uperf.h"

#include <unicode/brkiter.h>

class ICUBreakFunction : public UPerfFunction {
protected:
  BreakIterator *m_brkIt_;
  const UChar *m_file_;
  int32_t m_fileLen_;
  int32_t m_noBreaks_;
  UErrorCode m_status_;
public:
  ICUBreakFunction(const char *locale, const char *mode, const UChar *file, int32_t file_len) :
      m_brkIt_(NULL),
      m_file_(file),
      m_fileLen_(file_len),
      m_noBreaks_(-1),
      m_status_(U_ZERO_ERROR)
  {
    switch(mode[0]) {
    case 'c' :
      m_brkIt_ = BreakIterator::createCharacterInstance(locale, m_status_);
      break;
    case 'w' : 
      m_brkIt_ = BreakIterator::createWordInstance(locale, m_status_);
      break;
    case 'l' :
      m_brkIt_ = BreakIterator::createLineInstance(locale, m_status_);
      break;
    case 's' :
      m_brkIt_ = BreakIterator::createSentenceInstance(locale, m_status_);
      break;
    default:
      // should not happen as we already check for this in the caller
      m_status_ = U_ILLEGAL_ARGUMENT_ERROR;
      break;
    }
  }

  ~ICUBreakFunction() {  delete m_brkIt_; }
  virtual void call(UErrorCode *status) = 0;
  virtual long getOperationsPerIteration() { return m_fileLen_; }
  virtual long getEventsPerIteration() { return m_noBreaks_; }
  virtual UErrorCode getStatus() { return m_status_; }
};

class ICUIsBound : public ICUBreakFunction {
public:
  ICUIsBound(const char *locale, const char *mode, const UChar *file, int32_t file_len) :
      ICUBreakFunction(locale, mode, file, file_len)
  {
    m_noBreaks_ = 0;
    m_brkIt_->setText(UnicodeString(m_file_, m_fileLen_));
    m_brkIt_->first();
    int32_t j = 0;
    for(j = 0; j < m_fileLen_; j++) {
      if(m_brkIt_->isBoundary(j)) {
        m_noBreaks_++;
      }
    }    
  }
  virtual void call(UErrorCode *status) 
  {
    m_noBreaks_ = 0;
    int32_t j = 0;
    for(j = 0; j < m_fileLen_; j++) {
      if(m_brkIt_->isBoundary(j)) {
        m_noBreaks_++;
      }
    }
  }
};

class ICUForward : public ICUBreakFunction {
public:
  ICUForward(const char *locale, const char *mode, const UChar *file, int32_t file_len) :
      ICUBreakFunction(locale, mode, file, file_len)
  {
    m_noBreaks_ = 0;
    m_brkIt_->setText(UnicodeString(m_file_, m_fileLen_));
    m_brkIt_->first();
    while(m_brkIt_->next() != BreakIterator::DONE) {
      m_noBreaks_++;
    }
  }
  virtual void call(UErrorCode *status) 
  {
    m_noBreaks_ = 0;
    m_brkIt_->first();
    while(m_brkIt_->next() != BreakIterator::DONE) {
      m_noBreaks_++;
    }
  }
};

class DarwinBreakFunction : public UPerfFunction {
#ifdef U_DARWIN
public:
  virtual void call(UErrorCode *status) {};
#else
public:
  virtual void call(UErrorCode *status) {};
#endif
};

class BreakIteratorPerformanceTest : public UPerfTest {
private:
  const char* m_mode_;
  const UChar* m_file_;
  int32_t m_fileLen_;

public:
  BreakIteratorPerformanceTest(int32_t argc, const char* argv[], UErrorCode& status);
  ~BreakIteratorPerformanceTest();

  virtual UPerfFunction* runIndexedTest(int32_t index, UBool exec,
    const char* &name, char* par = NULL);     

  UPerfFunction* TestICUForward();
  UPerfFunction* TestICUIsBound();

  UPerfFunction* TestDarwinForward();
  UPerfFunction* TestDarwinIsBound();

};

#endif // UBRKPERF_H