]>
git.saurik.com Git - apple/icu.git/blob - icuSources/test/perf/leperf/leperf.cpp
1 /***************************************************************************
3 * Copyright (C) 2013, International Business Machines
4 * Corporation and others. All Rights Reserved.
6 ************************************************************************/
8 #include "unicode/utimer.h"
9 #include "unicode/ustdio.h"
10 #include "layout/LETypes.h"
11 #include "layout/LayoutEngine.h"
12 #include "layout/LEScripts.h"
13 #include "SimpleFontInstance.h"
14 #include "PortableFontInstance.h"
25 LEUnicode ArabChars
[] = {
26 0x0045, 0x006E, 0x0067, 0x006C, 0x0069, 0x0073, 0x0068, 0x0020, // "English "
27 0x0645, 0x0627, 0x0646, 0x062A, 0x0648, 0x0634, // MEM ALIF KAF NOON TEH WAW SHEEN
28 0x0020, 0x0074, 0x0065, 0x0078, 0x0074, 0x02E, 0 // " text."
31 void iterate(void * p
) {
32 Params
* params
= (Params
*) p
;
34 LEErrorCode status
= LE_NO_ERROR
;
35 LEFontInstance
*font
= params
->font
;
36 LayoutEngine
*engine
= LayoutEngine::layoutEngineFactory(font
, params
->script
, -1, status
);
37 LEGlyphID
*glyphs
= NULL
;
38 le_int32
*indices
= NULL
;
39 float *positions
= NULL
;
40 le_int32 glyphCount
= 0;
41 LEUnicode
*chars
= params
->chars
;
42 glyphCount
= engine
->layoutChars(chars
, 0, params
->charLen
, params
->charLen
, TRUE
, 0.0, 0.0, status
);
43 glyphs
= LE_NEW_ARRAY(LEGlyphID
, glyphCount
+ 10);
44 indices
= LE_NEW_ARRAY(le_int32
, glyphCount
+ 10);
45 positions
= LE_NEW_ARRAY(float, glyphCount
+ 10);
46 engine
->getGlyphs(glyphs
, status
);
47 params
->glyphCount
= glyphCount
;
57 int main(int argc
, const char *argv
[]) {
59 for(int i
=1;i
<argc
;i
++) {
63 printf("hit enter-pid=%d", getpid());
65 } else if(argv
[i
][0]>='0' && argv
[i
][0]<='9') {
66 len
= (1.0)*(argv
[i
][0]-'0');
69 u_printf("leperf: Testing %s for %.fs...\n", U_ICU_VERSION
, len
);
70 LEErrorCode status
= LE_NO_ERROR
;
71 //uloc_setDefault("en_US", &status);
75 p
.script
= arabScriptCode
;
77 p
.charLen
= sizeof(ArabChars
)/sizeof(ArabChars
[0]);
79 p
.script
= latnScriptCode
;
80 p
.chars
= new LEUnicode
[257];
81 for(int i
=0;i
<256;i
++) {
92 p
.font
= new SimpleFontInstance(12, status
);
93 u_printf("leperf: Running SFI...\r");
94 timeTaken
= utimer_loopUntilDone(len
, &loopCount
, iterate
, &p
);
95 u_printf("leperf: SFI .. took %.fs %.2fns/ea\nleperf: .. iter= %d\n", timeTaken
, 1000000000.0*(timeTaken
/(double)loopCount
), (int32_t)loopCount
);
98 PortableFontInstance
*font
;
99 LEErrorCode fontStatus
= LE_NO_ERROR
;
100 const char *fontPath
= "myfont.ttf";
102 font
= new PortableFontInstance(fontPath
, 12, fontStatus
);
106 u_printf("leperf: testing %s\n", fontPath
);
107 u_printf("leperf: Running ...\r");
108 timeTaken
= utimer_loopUntilDone(len
, &loopCount
, iterate
, &p
);
109 timeNs
= 1000000000.0*(timeTaken
/(double)loopCount
);
110 u_printf("leperf: PFI .. took %.fs %.2fns/ea\nleperf: .. iter= %d\n", timeTaken
, timeNs
, (int32_t)loopCount
);
111 u_printf("leperf: DATA|\"%s\"|%.2f|\n", U_ICU_VERSION
, timeNs
);
112 u_printf("leperf: glyphs=%d\n", p
.glyphCount
);
116 // hack - #include these for easier build.
117 #include "SimpleFontInstance.cpp"
118 #include "PortableFontInstance.cpp"
120 #include "FontTableCache.cpp"