]>
git.saurik.com Git - apple/icu.git/blob - icuSources/test/perf/leperf/letrperf.cpp
1 /***************************************************************************
3 * Copyright (C) 2013, International Business Machines
4 * Corporation and others. All Rights Reserved.
6 ************************************************************************/
9 * build against a configured (but not built) ICU.
10 * example: cc -O2 test_LETableReference.cpp -I. -I/xsrl/II/include -I/xsrl/E/icu/source/tools/ctestfw
12 #include "unicode/utimer.h"
13 #include "LETableReference.h"
17 #define ITEM_COUNT 10000
22 long items
[ITEM_COUNT
];
30 Long items
[ITEM_COUNT
];
34 void time_null(void * /*ref*/) {
35 for(int i
=0;i
<ITEM_COUNT
;i
++) {
44 void time_obj(void * ref
) {
45 OneObject
&obj
= *((OneObject
*)ref
);
46 for(int i
=0;i
<ITEM_COUNT
;i
++) {
54 void time_obj2(void * ref
) {
55 long *items2
= ((OneObject
*)ref
)->items
;
56 for(int i
=0;i
<ITEM_COUNT
;i
++) {
65 void time_letr1(void * ref
) {
66 OneObject
&obj
= *((OneObject
*)ref
);
67 LETableReference
data((const le_uint8
*)ref
, sizeof(OneObject
));
68 LEErrorCode success
= LE_NO_ERROR
;
70 LEReferenceTo
<OneObject
> stuff(data
, success
);
71 if(LE_FAILURE(success
)) {
75 long *items2
= ((OneObject
*)ref
)->items
;
76 for(int i
=0;i
<ITEM_COUNT
;i
++) {
86 void time_letr2(void * ref
) {
87 OneObject
&obj
= *((OneObject
*)ref
);
88 LETableReference
data((const le_uint8
*)ref
, sizeof(OneObject
));
89 LEErrorCode success
= LE_NO_ERROR
;
91 long *items2
= ((OneObject
*)ref
)->items
;
92 for(int i
=0;i
<ITEM_COUNT
;i
++) {
93 LEReferenceTo
<OneObject
> stuff(data
, success
);
94 if(LE_FAILURE(success
)) {
106 static void time_letr3(void * ref
) {
107 LETableReference
data((const le_uint8
*)ref
, sizeof(OneObject
));
108 LEErrorCode success
= LE_NO_ERROR
;
109 LEReferenceTo
<CompObject
> comp(data
, success
);
110 LEReferenceToArrayOf
<Long
> longs(comp
, success
, (size_t)0, ITEM_COUNT
);
111 if(LE_FAILURE(success
)) {
116 for(int i
=0;i
<ITEM_COUNT
;i
++) {
117 const Long
&item
= longs
.getObject(i
, success
);
118 if(LE_FAILURE(success
)) {
132 double runTime
= 2.0;
133 printf("Test of LETableReference<> timing. %.1fs per run.\n", runTime
);
134 items
= new long[ITEM_COUNT
];
135 OneObject
*oo
= new OneObject();
136 CompObject
*oo2
= new CompObject();
137 for(int i
=0;i
<ITEM_COUNT
-1;i
++) {
138 items
[i
] = oo
->items
[i
] = oo2
->items
[i
].v
= (i%1024
)+3;
140 items
[ITEM_COUNT
-1] = oo
->items
[ITEM_COUNT
-1] = oo2
->items
[ITEM_COUNT
-1].v
= 2; // last one
142 puts("will call once..");
143 time_letr3((void*)oo2
);
144 puts("testing all..");
149 #define showTime(x,y) printf("%s:\ttesting...\r", #x); fflush(stdout); \
150 time_taken = utimer_loopUntilDone(runTime, &loopCount, x, y); \
151 printf("%s:\t%.1fs\t#%d\t%.1f/s\n", #x, time_taken, loopCount, loopCount/(double)time_taken);
155 double oldTime
= runTime
;
157 showTime(time_null
, NULL
);
158 showTime(time_null
, NULL
);
159 showTime(time_null
, NULL
);
160 showTime(time_null
, NULL
);
163 puts("-- ready to start --");
166 showTime(time_null
, NULL
);
167 showTime(time_obj
, (void*)oo
);
168 showTime(time_obj2
, (void*)oo
);
169 showTime(time_letr1
, (void*)oo2
);
170 showTime(time_letr2
, (void*)oo2
);
171 showTime(time_letr3
, (void*)oo2
);
172 showTime(time_null
, NULL
);