|
1 // Copyright (c) 1994-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of the License "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // e32test\buffer\tarraysp.cpp |
|
15 // |
|
16 // |
|
17 |
|
18 #include <e32test.h> |
|
19 #include <e32math.h> |
|
20 |
|
21 GLREF_D RTest test; |
|
22 GLREF_C TInt Random(); |
|
23 |
|
24 LOCAL_D TInt Count=0; |
|
25 |
|
26 GLREF_D TLinearOrder<TInt64> Int64Order; |
|
27 |
|
28 volatile TReal Absorber; |
|
29 volatile TInt DummyFlag = 1; |
|
30 |
|
31 #undef FOREVER |
|
32 #define FOREVER while (DummyFlag) |
|
33 |
|
34 |
|
35 LOCAL_C TInt VerySlowInt64Order(const TInt64& a, const TInt64& b) |
|
36 { |
|
37 TReal x; |
|
38 Math::Ln(x, 2.0); |
|
39 Absorber = x; |
|
40 if (a < b) |
|
41 return -1; |
|
42 if (a == b) |
|
43 return 0; |
|
44 return 1; |
|
45 } |
|
46 |
|
47 |
|
48 LOCAL_C TInt SpeedTest1(TAny* aSem) |
|
49 { |
|
50 RSemaphore *pS=(RSemaphore*)aSem; |
|
51 pS->Signal(); |
|
52 FOREVER |
|
53 { |
|
54 TInt i; |
|
55 RArray<TInt> a; |
|
56 for (i=0; i<1000; i++) |
|
57 a.Append(Count++); |
|
58 a.Close(); |
|
59 } |
|
60 return KErrNone; |
|
61 } |
|
62 |
|
63 LOCAL_C TInt SpeedTest2(TAny* aSem) |
|
64 { |
|
65 RSemaphore *pS=(RSemaphore*)aSem; |
|
66 CArrayFixFlat<TInt>* pA=new CArrayFixFlat<TInt>(8); |
|
67 pS->Signal(); |
|
68 FOREVER |
|
69 { |
|
70 TInt i; |
|
71 for (i=0; i<1000; i++) |
|
72 { |
|
73 pA->AppendL(Count++); |
|
74 } |
|
75 pA->Reset(); |
|
76 } |
|
77 delete pA; |
|
78 return KErrNone; |
|
79 } |
|
80 |
|
81 TInt Total; |
|
82 LOCAL_C TInt SpeedTest3(TAny* aSem) |
|
83 { |
|
84 RSemaphore *pS=(RSemaphore*)aSem; |
|
85 TInt i; |
|
86 RArray<TInt> a; |
|
87 for (i=0; i<1000; i++) |
|
88 a.Append(i); |
|
89 pS->Signal(); |
|
90 FOREVER |
|
91 { |
|
92 TInt total=0; |
|
93 for (i=0; i<1000; i++) |
|
94 { |
|
95 total+=a[i]; |
|
96 Count++; |
|
97 } |
|
98 Total=total; |
|
99 } |
|
100 return KErrNone; |
|
101 } |
|
102 |
|
103 LOCAL_C TInt SpeedTest4(TAny* aSem) |
|
104 { |
|
105 RSemaphore *pS=(RSemaphore*)aSem; |
|
106 CArrayFixFlat<TInt>* pA=new CArrayFixFlat<TInt>(8); |
|
107 TInt i; |
|
108 for (i=0; i<1000; i++) |
|
109 { |
|
110 pA->AppendL(i); |
|
111 } |
|
112 pS->Signal(); |
|
113 FOREVER |
|
114 { |
|
115 TInt total=0; |
|
116 for (i=0; i<1000; i++) |
|
117 { |
|
118 total+=(*pA)[i]; |
|
119 Count++; |
|
120 } |
|
121 Total=total; |
|
122 } |
|
123 delete pA; |
|
124 return KErrNone; |
|
125 } |
|
126 |
|
127 LOCAL_C TInt SpeedTest5(TAny* aSem) |
|
128 { |
|
129 RSemaphore *pS=(RSemaphore*)aSem; |
|
130 pS->Signal(); |
|
131 FOREVER |
|
132 { |
|
133 TInt i; |
|
134 RArray<TInt> a; |
|
135 for (i=999; i>=0; i--, Count++) |
|
136 a.InsertInOrder(i); |
|
137 a.Close(); |
|
138 } |
|
139 return KErrNone; |
|
140 } |
|
141 |
|
142 LOCAL_C TInt SpeedTest5a(TAny* aSem) |
|
143 { |
|
144 RSemaphore *pS=(RSemaphore*)aSem; |
|
145 pS->Signal(); |
|
146 FOREVER |
|
147 { |
|
148 TInt i; |
|
149 RArray<TInt> a; |
|
150 for (i=999; i>=0; i--, Count++) |
|
151 a.InsertInOrderAllowRepeats(0); |
|
152 a.Close(); |
|
153 } |
|
154 return KErrNone; |
|
155 } |
|
156 |
|
157 LOCAL_C TInt SpeedTest6(TAny* aSem) |
|
158 { |
|
159 RSemaphore *pS=(RSemaphore*)aSem; |
|
160 CArrayFixFlat<TInt>* pA=new CArrayFixFlat<TInt>(8); |
|
161 TKeyArrayFix key(0,ECmpTInt); |
|
162 pS->Signal(); |
|
163 FOREVER |
|
164 { |
|
165 TInt i; |
|
166 for (i=999; i>=0; i--, Count++) |
|
167 { |
|
168 pA->InsertIsqL(i,key); |
|
169 } |
|
170 pA->Reset(); |
|
171 } |
|
172 delete pA; |
|
173 return KErrNone; |
|
174 } |
|
175 |
|
176 LOCAL_C TInt SpeedTest7(TAny* aSem) |
|
177 { |
|
178 RSemaphore *pS=(RSemaphore*)aSem; |
|
179 TInt i; |
|
180 RArray<TInt> a(1024); |
|
181 for (i=0; i<1000; i++) |
|
182 a.Append(Random()); |
|
183 pS->Signal(); |
|
184 FOREVER |
|
185 { |
|
186 a.Sort(); |
|
187 for (i=0; i<1000; i++) |
|
188 a[i]=Random(); |
|
189 Count++; |
|
190 } |
|
191 return KErrNone; |
|
192 } |
|
193 |
|
194 LOCAL_C TInt SpeedTest7b(TAny* aSem) |
|
195 { |
|
196 RSemaphore *pS=(RSemaphore*)aSem; |
|
197 TInt i; |
|
198 RArray<TInt64> a(1024); |
|
199 for (i=0; i<1000; i++) |
|
200 a.Append(MAKE_TINT64(Random(),Random())); |
|
201 pS->Signal(); |
|
202 FOREVER |
|
203 { |
|
204 a.Sort(Int64Order); |
|
205 for (i=0; i<1000; i++) |
|
206 a[i]=MAKE_TINT64(Random(),Random()); |
|
207 Count++; |
|
208 } |
|
209 return KErrNone; |
|
210 } |
|
211 |
|
212 LOCAL_C TInt SpeedTest8(TAny* aSem) |
|
213 { |
|
214 RSemaphore *pS=(RSemaphore*)aSem; |
|
215 CArrayFixFlat<TInt>* pA=new CArrayFixFlat<TInt>(1024); |
|
216 TKeyArrayFix key(0,ECmpTInt); |
|
217 TInt i; |
|
218 for (i=0; i<1000; i++) |
|
219 pA->AppendL(Random()); |
|
220 pS->Signal(); |
|
221 FOREVER |
|
222 { |
|
223 pA->Sort(key); |
|
224 for (i=0; i<1000; i++) |
|
225 (*pA)[i]=Random(); |
|
226 Count++; |
|
227 } |
|
228 delete pA; |
|
229 return KErrNone; |
|
230 } |
|
231 |
|
232 LOCAL_C TInt SpeedTest8a(TAny* aSem) |
|
233 { |
|
234 RSemaphore *pS=(RSemaphore*)aSem; |
|
235 CArrayFixFlat<TInt64>* pA=new CArrayFixFlat<TInt64>(1024); |
|
236 TKeyArrayFix key(0,ECmpTInt64); |
|
237 TInt i; |
|
238 for (i=0; i<1000; i++) |
|
239 pA->AppendL(MAKE_TINT64(Random(),Random())); |
|
240 pS->Signal(); |
|
241 FOREVER |
|
242 { |
|
243 pA->Sort(key); |
|
244 for (i=0; i<1000; i++) |
|
245 (*pA)[i]=MAKE_TINT64(Random(),Random()); |
|
246 Count++; |
|
247 } |
|
248 delete pA; |
|
249 return KErrNone; |
|
250 } |
|
251 |
|
252 LOCAL_C TInt SpeedTest9(TAny* aSem) |
|
253 { |
|
254 RSemaphore *pS=(RSemaphore*)aSem; |
|
255 pS->Signal(); |
|
256 FOREVER |
|
257 { |
|
258 TInt i; |
|
259 RArray<TInt> a; |
|
260 for (i=0; i<1000; i++, Count++) |
|
261 a.InsertInOrder(Random()); |
|
262 a.Close(); |
|
263 } |
|
264 return KErrNone; |
|
265 } |
|
266 |
|
267 LOCAL_C TInt SpeedTest9b(TAny* aSem) |
|
268 { |
|
269 RSemaphore *pS=(RSemaphore*)aSem; |
|
270 pS->Signal(); |
|
271 FOREVER |
|
272 { |
|
273 TInt i; |
|
274 RArray<TInt64> a; |
|
275 for (i=0; i<1000; i++, Count++) |
|
276 a.InsertInOrder(MAKE_TINT64(Random(),Random()),Int64Order); |
|
277 a.Close(); |
|
278 } |
|
279 return KErrNone; |
|
280 } |
|
281 |
|
282 LOCAL_C TInt SpeedTest9q(TAny* aSem) |
|
283 { |
|
284 RSemaphore *pS=(RSemaphore*)aSem; |
|
285 pS->Signal(); |
|
286 FOREVER |
|
287 { |
|
288 TInt i; |
|
289 RArray<TInt64> a; |
|
290 for (i=0; i<1000; i++, Count++) |
|
291 a.InsertInOrderAllowRepeats(MAKE_TINT64(0,i), &VerySlowInt64Order); |
|
292 a.Close(); |
|
293 } |
|
294 return KErrNone; |
|
295 } |
|
296 |
|
297 LOCAL_C TInt SpeedTest9r(TAny* aSem) |
|
298 { |
|
299 RSemaphore *pS=(RSemaphore*)aSem; |
|
300 pS->Signal(); |
|
301 FOREVER |
|
302 { |
|
303 TInt i; |
|
304 RArray<TInt64> a; |
|
305 for (i=0; i<1000; i++, Count++) |
|
306 a.InsertInOrderAllowRepeats(MAKE_TINT64(0,0), &VerySlowInt64Order); |
|
307 a.Close(); |
|
308 } |
|
309 return KErrNone; |
|
310 } |
|
311 |
|
312 LOCAL_C TInt SpeedTest10(TAny* aSem) |
|
313 { |
|
314 RSemaphore *pS=(RSemaphore*)aSem; |
|
315 CArrayFixFlat<TInt>* pA=new CArrayFixFlat<TInt>(8); |
|
316 TKeyArrayFix key(0,ECmpTInt); |
|
317 pS->Signal(); |
|
318 FOREVER |
|
319 { |
|
320 TInt i; |
|
321 for (i=0; i<1000; i++, Count++) |
|
322 { |
|
323 pA->InsertIsqAllowDuplicatesL(Random(),key); |
|
324 } |
|
325 pA->Reset(); |
|
326 } |
|
327 delete pA; |
|
328 return KErrNone; |
|
329 } |
|
330 |
|
331 LOCAL_C TInt SpeedTest10a(TAny* aSem) |
|
332 { |
|
333 RSemaphore *pS=(RSemaphore*)aSem; |
|
334 CArrayFixFlat<TInt64>* pA=new CArrayFixFlat<TInt64>(8); |
|
335 TKeyArrayFix key(0,ECmpTInt64); |
|
336 pS->Signal(); |
|
337 FOREVER |
|
338 { |
|
339 TInt i; |
|
340 for (i=0; i<1000; i++, Count++) |
|
341 { |
|
342 pA->InsertIsqAllowDuplicatesL(MAKE_TINT64(Random(),Random()),key); |
|
343 } |
|
344 pA->Reset(); |
|
345 } |
|
346 delete pA; |
|
347 return KErrNone; |
|
348 } |
|
349 |
|
350 LOCAL_C TInt SpeedTest11(TAny* aSem) |
|
351 { |
|
352 RSemaphore *pS=(RSemaphore*)aSem; |
|
353 TInt i; |
|
354 RArray<TInt> a(1024); |
|
355 for (i=0; i<1024; i++) |
|
356 a.Append(i); |
|
357 pS->Signal(); |
|
358 FOREVER |
|
359 { |
|
360 for (i=0; i<1024; i++) |
|
361 { |
|
362 a.FindInOrder(i^0x2b9); |
|
363 Count++; |
|
364 } |
|
365 } |
|
366 return KErrNone; |
|
367 } |
|
368 |
|
369 LOCAL_C TInt SpeedTest11b(TAny* aSem) |
|
370 { |
|
371 RSemaphore *pS=(RSemaphore*)aSem; |
|
372 TInt i; |
|
373 RArray<TInt64> a(1024); |
|
374 for (i=0; i<1024; i++) |
|
375 a.Append(MAKE_TINT64(i>>6,i)); |
|
376 pS->Signal(); |
|
377 FOREVER |
|
378 { |
|
379 for (i=0; i<1024; i++) |
|
380 { |
|
381 TInt j=i^0x2b9; |
|
382 TInt64 x = MAKE_TINT64(j>>6,j); |
|
383 a.FindInOrder(x,Int64Order); |
|
384 Count++; |
|
385 } |
|
386 } |
|
387 return KErrNone; |
|
388 } |
|
389 |
|
390 LOCAL_C TInt SpeedTest12(TAny* aSem) |
|
391 { |
|
392 RSemaphore *pS=(RSemaphore*)aSem; |
|
393 CArrayFixFlat<TInt>* pA=new CArrayFixFlat<TInt>(8); |
|
394 TKeyArrayFix key(0,ECmpTInt); |
|
395 TInt i; |
|
396 for (i=0; i<1024; i++) |
|
397 { |
|
398 pA->AppendL(i); |
|
399 } |
|
400 pS->Signal(); |
|
401 FOREVER |
|
402 { |
|
403 for (i=0; i<1024; i++) |
|
404 { |
|
405 TInt j; |
|
406 TInt k=i^0x2b9; |
|
407 pA->FindIsq(k,key,j); |
|
408 Count++; |
|
409 } |
|
410 } |
|
411 delete pA; |
|
412 return KErrNone; |
|
413 } |
|
414 |
|
415 LOCAL_C TInt SpeedTest12a(TAny* aSem) |
|
416 { |
|
417 RSemaphore *pS=(RSemaphore*)aSem; |
|
418 CArrayFixFlat<TInt64>* pA=new CArrayFixFlat<TInt64>(8); |
|
419 TKeyArrayFix key(0,ECmpTInt64); |
|
420 TInt i; |
|
421 for (i=0; i<1024; i++) |
|
422 { |
|
423 pA->AppendL(MAKE_TINT64(i>>6,i)); |
|
424 } |
|
425 pS->Signal(); |
|
426 FOREVER |
|
427 { |
|
428 for (i=0; i<1024; i++) |
|
429 { |
|
430 TInt j; |
|
431 TInt k=i^0x2b9; |
|
432 TInt64 x = MAKE_TINT64(k>>6,k); |
|
433 pA->FindIsq(x,key,j); |
|
434 Count++; |
|
435 } |
|
436 } |
|
437 delete pA; |
|
438 return KErrNone; |
|
439 } |
|
440 |
|
441 const TInt KHeapSize=16384; |
|
442 LOCAL_C TInt DoSpeedTest(TThreadFunction f) |
|
443 { |
|
444 RSemaphore sem; |
|
445 sem.CreateLocal(0); |
|
446 RThread t; |
|
447 t.Create(_L("Speedy"),f,KDefaultStackSize,KHeapSize,KHeapSize,&sem); |
|
448 t.SetPriority(EPriorityLess); |
|
449 Count=0; |
|
450 TRequestStatus s; |
|
451 t.Logon(s); |
|
452 t.Resume(); |
|
453 sem.Wait(); |
|
454 User::After(2000000); |
|
455 TInt num=Count/2; |
|
456 t.Kill(0); |
|
457 User::WaitForRequest(s); |
|
458 if (t.ExitType()!=EExitKill) |
|
459 { |
|
460 TExitCategoryName aExitCategory = t.ExitCategory(); |
|
461 test.Printf(_L("Exit %d %S %d\n"),t.ExitType(),&aExitCategory,t.ExitReason()); |
|
462 } |
|
463 CLOSE_AND_WAIT(t); |
|
464 sem.Close(); |
|
465 return num; |
|
466 } |
|
467 |
|
468 GLDEF_C void DoSpeedTests() |
|
469 { |
|
470 TInt r; |
|
471 test.Next(_L("Speed Tests")); |
|
472 r=DoSpeedTest(SpeedTest1); |
|
473 test.Printf(_L("RArray<TInt> append, %d in 1 second\n"),r); |
|
474 r=DoSpeedTest(SpeedTest2); |
|
475 test.Printf(_L("CArrayFixFlat<TInt> append, %d in 1 second\n"),r); |
|
476 r=DoSpeedTest(SpeedTest3); |
|
477 test.Printf(_L("RArray<TInt> access, %d in 1 second\n"),r); |
|
478 test(Total==999*1000/2); |
|
479 r=DoSpeedTest(SpeedTest4); |
|
480 test.Printf(_L("CArrayFixFlat<TInt> access, %d in 1 second\n"),r); |
|
481 test(Total==999*1000/2); |
|
482 r=DoSpeedTest(SpeedTest5); |
|
483 test.Printf(_L("RArray<TInt> InsertInOrder, %d in 1 second\n"),r); |
|
484 r=DoSpeedTest(SpeedTest5a); |
|
485 test.Printf(_L("RArray<TInt> InsertInOrder repeats, %d in 1 second\n"),r); |
|
486 r=DoSpeedTest(SpeedTest6); |
|
487 test.Printf(_L("CArrayFixFlat<TInt> InsertIsqL, %d in 1 second\n"),r); |
|
488 r=DoSpeedTest(SpeedTest7); |
|
489 test.Printf(_L("RArray<TInt> Sort 1000, %d in 1 second\n"),r); |
|
490 r=DoSpeedTest(SpeedTest7b); |
|
491 test.Printf(_L("RArray<TInt64> Sort 1000, %d in 1 second\n"),r); |
|
492 r=DoSpeedTest(SpeedTest8); |
|
493 test.Printf(_L("CArrayFixFlat<TInt> Sort 1000, %d in 1 second\n"),r); |
|
494 r=DoSpeedTest(SpeedTest8a); |
|
495 test.Printf(_L("CArrayFixFlat<TInt64> Sort 1000, %d in 1 second\n"),r); |
|
496 r=DoSpeedTest(SpeedTest9); |
|
497 test.Printf(_L("RArray<TInt> InsertInOrder random, %d in 1 second\n"),r); |
|
498 r=DoSpeedTest(SpeedTest9b); |
|
499 test.Printf(_L("RArray<TInt64> InsertInOrder random, %d in 1 second\n"),r); |
|
500 r=DoSpeedTest(SpeedTest9q); |
|
501 test.Printf(_L("RArray<TInt64> InsertInOrder repeat control, %d in 1 second\n"),r); |
|
502 r=DoSpeedTest(SpeedTest9r); |
|
503 test.Printf(_L("RArray<TInt64> InsertInOrder repeats, %d in 1 second\n"),r); |
|
504 r=DoSpeedTest(SpeedTest10); |
|
505 test.Printf(_L("CArrayFixFlat<TInt> InsertIsqL random, %d in 1 second\n"),r); |
|
506 r=DoSpeedTest(SpeedTest10a); |
|
507 test.Printf(_L("CArrayFixFlat<TInt64> InsertIsqL random, %d in 1 second\n"),r); |
|
508 r=DoSpeedTest(SpeedTest11); |
|
509 test.Printf(_L("RArray<TInt> FindInOrder, %d in 1 second\n"),r); |
|
510 r=DoSpeedTest(SpeedTest11b); |
|
511 test.Printf(_L("RArray<TInt64> FindInOrder, %d in 1 second\n"),r); |
|
512 r=DoSpeedTest(SpeedTest12); |
|
513 test.Printf(_L("CArrayFixFlat<TInt> FindIsqL, %d in 1 second\n"),r); |
|
514 r=DoSpeedTest(SpeedTest12a); |
|
515 test.Printf(_L("CArrayFixFlat<TInt64> FindIsqL, %d in 1 second\n"),r); |
|
516 } |
|
517 |