]>
git.saurik.com Git - apple/icu.git/blob - icuSources/test/perf/leperf/leperf.cpp
1 /**************************************************************************
3 * © 2016 and later: Unicode, Inc. and others.
4 * License & terms of use: http://www.unicode.org/copyright.html#License
6 ***************************************************************************
7 ***************************************************************************
9 * Copyright (C) 2013, International Business Machines
10 * Corporation and others. All Rights Reserved.
12 ************************************************************************/
14 #include "unicode/utimer.h"
15 #include "unicode/ustdio.h"
16 #include "layout/LETypes.h"
17 #include "layout/LayoutEngine.h"
18 #include "layout/LEScripts.h"
19 #include "SimpleFontInstance.h"
20 #include "PortableFontInstance.h"
31 LEUnicode ArabChars
[] = {
32 0x0045, 0x006E, 0x0067, 0x006C, 0x0069, 0x0073, 0x0068, 0x0020, // "English "
33 0x0645, 0x0627, 0x0646, 0x062A, 0x0648, 0x0634, // MEM ALIF KAF NOON TEH WAW SHEEN
34 0x0020, 0x0074, 0x0065, 0x0078, 0x0074, 0x02E, 0 // " text."
37 void iterate(void * p
) {
38 Params
* params
= (Params
*) p
;
40 LEErrorCode status
= LE_NO_ERROR
;
41 LEFontInstance
*font
= params
->font
;
42 LayoutEngine
*engine
= LayoutEngine::layoutEngineFactory(font
, params
->script
, -1, status
);
43 LEGlyphID
*glyphs
= NULL
;
44 le_int32
*indices
= NULL
;
45 float *positions
= NULL
;
46 le_int32 glyphCount
= 0;
47 LEUnicode
*chars
= params
->chars
;
48 glyphCount
= engine
->layoutChars(chars
, 0, params
->charLen
, params
->charLen
, TRUE
, 0.0, 0.0, status
);
49 glyphs
= LE_NEW_ARRAY(LEGlyphID
, glyphCount
+ 10);
50 indices
= LE_NEW_ARRAY(le_int32
, glyphCount
+ 10);
51 positions
= LE_NEW_ARRAY(float, glyphCount
+ 10);
52 engine
->getGlyphs(glyphs
, status
);
53 params
->glyphCount
= glyphCount
;
63 int main(int argc
, const char *argv
[]) {
65 for(int i
=1;i
<argc
;i
++) {
69 printf("hit enter-pid=%d", getpid());
71 } else if(argv
[i
][0]>='0' && argv
[i
][0]<='9') {
72 len
= (1.0)*(argv
[i
][0]-'0');
75 u_printf("leperf: Testing %s for %.fs...\n", U_ICU_VERSION
, len
);
76 LEErrorCode status
= LE_NO_ERROR
;
77 //uloc_setDefault("en_US", &status);
81 p
.script
= arabScriptCode
;
83 p
.charLen
= sizeof(ArabChars
)/sizeof(ArabChars
[0]);
85 p
.script
= latnScriptCode
;
86 p
.chars
= new LEUnicode
[257];
87 for(int i
=0;i
<256;i
++) {
98 p
.font
= new SimpleFontInstance(12, status
);
99 u_printf("leperf: Running SFI...\r");
100 timeTaken
= utimer_loopUntilDone(len
, &loopCount
, iterate
, &p
);
101 u_printf("leperf: SFI .. took %.fs %.2fns/ea\nleperf: .. iter= %d\n", timeTaken
, 1000000000.0*(timeTaken
/(double)loopCount
), (int32_t)loopCount
);
104 PortableFontInstance
*font
;
105 LEErrorCode fontStatus
= LE_NO_ERROR
;
106 const char *fontPath
= "myfont.ttf";
108 font
= new PortableFontInstance(fontPath
, 12, fontStatus
);
112 u_printf("leperf: testing %s\n", fontPath
);
113 u_printf("leperf: Running ...\r");
114 timeTaken
= utimer_loopUntilDone(len
, &loopCount
, iterate
, &p
);
115 timeNs
= 1000000000.0*(timeTaken
/(double)loopCount
);
116 u_printf("leperf: PFI .. took %.fs %.2fns/ea\nleperf: .. iter= %d\n", timeTaken
, timeNs
, (int32_t)loopCount
);
117 u_printf("leperf: DATA|\"%s\"|%.2f|\n", U_ICU_VERSION
, timeNs
);
118 u_printf("leperf: glyphs=%d\n", p
.glyphCount
);
122 // hack - #include these for easier build.
123 #include "SimpleFontInstance.cpp"
124 #include "PortableFontInstance.cpp"
126 #include "FontTableCache.cpp"