1 /**************************************************************************
3 * Copyright (C) 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 ************************************************************************/
15 * build against a configured (but not built) ICU.
16 * example: cc -O2 test_LETableReference.cpp -I. -I/xsrl/II/include -I/xsrl/E/icu/source/tools/ctestfw
18 #include "unicode/utimer.h"
19 #include "LETableReference.h"
23 #define ITEM_COUNT 10000
28 long items[ITEM_COUNT];
36 Long items[ITEM_COUNT];
40 void time_null(void * /*ref*/) {
41 for(int i=0;i<ITEM_COUNT;i++) {
50 void time_obj(void * ref) {
51 OneObject &obj = *((OneObject*)ref);
52 for(int i=0;i<ITEM_COUNT;i++) {
60 void time_obj2(void * ref) {
61 long *items2 = ((OneObject*)ref)->items;
62 for(int i=0;i<ITEM_COUNT;i++) {
71 void time_letr1(void * ref) {
72 OneObject &obj = *((OneObject*)ref);
73 LETableReference data((const le_uint8*)ref, sizeof(OneObject));
74 LEErrorCode success = LE_NO_ERROR;
76 LEReferenceTo<OneObject> stuff(data, success);
77 if(LE_FAILURE(success)) {
81 long *items2 = ((OneObject*)ref)->items;
82 for(int i=0;i<ITEM_COUNT;i++) {
92 void time_letr2(void * ref) {
93 OneObject &obj = *((OneObject*)ref);
94 LETableReference data((const le_uint8*)ref, sizeof(OneObject));
95 LEErrorCode success = LE_NO_ERROR;
97 long *items2 = ((OneObject*)ref)->items;
98 for(int i=0;i<ITEM_COUNT;i++) {
99 LEReferenceTo<OneObject> stuff(data, success);
100 if(LE_FAILURE(success)) {
112 static void time_letr3(void * ref) {
113 LETableReference data((const le_uint8*)ref, sizeof(OneObject));
114 LEErrorCode success = LE_NO_ERROR;
115 LEReferenceTo<CompObject> comp(data, success);
116 LEReferenceToArrayOf<Long> longs(comp, success, (size_t)0, ITEM_COUNT);
117 if(LE_FAILURE(success)) {
122 for(int i=0;i<ITEM_COUNT;i++) {
123 const Long &item = longs.getObject(i, success);
124 if(LE_FAILURE(success)) {
138 double runTime = 2.0;
139 printf("Test of LETableReference<> timing. %.1fs per run.\n", runTime);
140 items = new long[ITEM_COUNT];
141 OneObject *oo = new OneObject();
142 CompObject *oo2 = new CompObject();
143 for(int i=0;i<ITEM_COUNT-1;i++) {
144 items[i] = oo->items[i] = oo2->items[i].v = (i%1024)+3;
146 items[ITEM_COUNT-1] = oo->items[ITEM_COUNT-1] = oo2->items[ITEM_COUNT-1].v = 2; // last one
148 puts("will call once..");
149 time_letr3((void*)oo2);
150 puts("testing all..");
155 #define showTime(x,y) printf("%s:\ttesting...\r", #x); fflush(stdout); \
156 time_taken = utimer_loopUntilDone(runTime, &loopCount, x, y); \
157 printf("%s:\t%.1fs\t#%d\t%.1f/s\n", #x, time_taken, loopCount, loopCount/(double)time_taken);
161 double oldTime = runTime;
163 showTime(time_null, NULL);
164 showTime(time_null, NULL);
165 showTime(time_null, NULL);
166 showTime(time_null, NULL);
169 puts("-- ready to start --");
172 showTime(time_null, NULL);
173 showTime(time_obj, (void*)oo);
174 showTime(time_obj2, (void*)oo);
175 showTime(time_letr1, (void*)oo2);
176 showTime(time_letr2, (void*)oo2);
177 showTime(time_letr3, (void*)oo2);
178 showTime(time_null, NULL);