Update contrib.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32test\buffer\tarraysp.cpp
22 GLREF_C TInt Random();
26 GLREF_D TLinearOrder<TInt64> Int64Order;
28 volatile TReal Absorber;
29 volatile TInt DummyFlag = 1;
32 #define FOREVER while (DummyFlag)
35 LOCAL_C TInt VerySlowInt64Order(const TInt64& a, const TInt64& b)
48 LOCAL_C TInt SpeedTest1(TAny* aSem)
50 RSemaphore *pS=(RSemaphore*)aSem;
56 for (i=0; i<1000; i++)
63 LOCAL_C TInt SpeedTest2(TAny* aSem)
65 RSemaphore *pS=(RSemaphore*)aSem;
66 CArrayFixFlat<TInt>* pA=new CArrayFixFlat<TInt>(8);
71 for (i=0; i<1000; i++)
82 LOCAL_C TInt SpeedTest3(TAny* aSem)
84 RSemaphore *pS=(RSemaphore*)aSem;
87 for (i=0; i<1000; i++)
93 for (i=0; i<1000; i++)
103 LOCAL_C TInt SpeedTest4(TAny* aSem)
105 RSemaphore *pS=(RSemaphore*)aSem;
106 CArrayFixFlat<TInt>* pA=new CArrayFixFlat<TInt>(8);
108 for (i=0; i<1000; i++)
116 for (i=0; i<1000; i++)
127 LOCAL_C TInt SpeedTest5(TAny* aSem)
129 RSemaphore *pS=(RSemaphore*)aSem;
135 for (i=999; i>=0; i--, Count++)
142 LOCAL_C TInt SpeedTest5a(TAny* aSem)
144 RSemaphore *pS=(RSemaphore*)aSem;
150 for (i=999; i>=0; i--, Count++)
151 a.InsertInOrderAllowRepeats(0);
157 LOCAL_C TInt SpeedTest6(TAny* aSem)
159 RSemaphore *pS=(RSemaphore*)aSem;
160 CArrayFixFlat<TInt>* pA=new CArrayFixFlat<TInt>(8);
161 TKeyArrayFix key(0,ECmpTInt);
166 for (i=999; i>=0; i--, Count++)
168 pA->InsertIsqL(i,key);
176 LOCAL_C TInt SpeedTest7(TAny* aSem)
178 RSemaphore *pS=(RSemaphore*)aSem;
180 RArray<TInt> a(1024);
181 for (i=0; i<1000; i++)
187 for (i=0; i<1000; i++)
194 LOCAL_C TInt SpeedTest7b(TAny* aSem)
196 RSemaphore *pS=(RSemaphore*)aSem;
198 RArray<TInt64> a(1024);
199 for (i=0; i<1000; i++)
200 a.Append(MAKE_TINT64(Random(),Random()));
205 for (i=0; i<1000; i++)
206 a[i]=MAKE_TINT64(Random(),Random());
212 LOCAL_C TInt SpeedTest8(TAny* aSem)
214 RSemaphore *pS=(RSemaphore*)aSem;
215 CArrayFixFlat<TInt>* pA=new CArrayFixFlat<TInt>(1024);
216 TKeyArrayFix key(0,ECmpTInt);
218 for (i=0; i<1000; i++)
219 pA->AppendL(Random());
224 for (i=0; i<1000; i++)
232 LOCAL_C TInt SpeedTest8a(TAny* aSem)
234 RSemaphore *pS=(RSemaphore*)aSem;
235 CArrayFixFlat<TInt64>* pA=new CArrayFixFlat<TInt64>(1024);
236 TKeyArrayFix key(0,ECmpTInt64);
238 for (i=0; i<1000; i++)
239 pA->AppendL(MAKE_TINT64(Random(),Random()));
244 for (i=0; i<1000; i++)
245 (*pA)[i]=MAKE_TINT64(Random(),Random());
252 LOCAL_C TInt SpeedTest9(TAny* aSem)
254 RSemaphore *pS=(RSemaphore*)aSem;
260 for (i=0; i<1000; i++, Count++)
261 a.InsertInOrder(Random());
267 LOCAL_C TInt SpeedTest9b(TAny* aSem)
269 RSemaphore *pS=(RSemaphore*)aSem;
275 for (i=0; i<1000; i++, Count++)
276 a.InsertInOrder(MAKE_TINT64(Random(),Random()),Int64Order);
282 LOCAL_C TInt SpeedTest9q(TAny* aSem)
284 RSemaphore *pS=(RSemaphore*)aSem;
290 for (i=0; i<1000; i++, Count++)
291 a.InsertInOrderAllowRepeats(MAKE_TINT64(0,i), &VerySlowInt64Order);
297 LOCAL_C TInt SpeedTest9r(TAny* aSem)
299 RSemaphore *pS=(RSemaphore*)aSem;
305 for (i=0; i<1000; i++, Count++)
306 a.InsertInOrderAllowRepeats(MAKE_TINT64(0,0), &VerySlowInt64Order);
312 LOCAL_C TInt SpeedTest10(TAny* aSem)
314 RSemaphore *pS=(RSemaphore*)aSem;
315 CArrayFixFlat<TInt>* pA=new CArrayFixFlat<TInt>(8);
316 TKeyArrayFix key(0,ECmpTInt);
321 for (i=0; i<1000; i++, Count++)
323 pA->InsertIsqAllowDuplicatesL(Random(),key);
331 LOCAL_C TInt SpeedTest10a(TAny* aSem)
333 RSemaphore *pS=(RSemaphore*)aSem;
334 CArrayFixFlat<TInt64>* pA=new CArrayFixFlat<TInt64>(8);
335 TKeyArrayFix key(0,ECmpTInt64);
340 for (i=0; i<1000; i++, Count++)
342 pA->InsertIsqAllowDuplicatesL(MAKE_TINT64(Random(),Random()),key);
350 LOCAL_C TInt SpeedTest11(TAny* aSem)
352 RSemaphore *pS=(RSemaphore*)aSem;
354 RArray<TInt> a(1024);
355 for (i=0; i<1024; i++)
360 for (i=0; i<1024; i++)
362 a.FindInOrder(i^0x2b9);
369 LOCAL_C TInt SpeedTest11b(TAny* aSem)
371 RSemaphore *pS=(RSemaphore*)aSem;
373 RArray<TInt64> a(1024);
374 for (i=0; i<1024; i++)
375 a.Append(MAKE_TINT64(i>>6,i));
379 for (i=0; i<1024; i++)
382 TInt64 x = MAKE_TINT64(j>>6,j);
383 a.FindInOrder(x,Int64Order);
390 LOCAL_C TInt SpeedTest12(TAny* aSem)
392 RSemaphore *pS=(RSemaphore*)aSem;
393 CArrayFixFlat<TInt>* pA=new CArrayFixFlat<TInt>(8);
394 TKeyArrayFix key(0,ECmpTInt);
396 for (i=0; i<1024; i++)
403 for (i=0; i<1024; i++)
407 pA->FindIsq(k,key,j);
415 LOCAL_C TInt SpeedTest12a(TAny* aSem)
417 RSemaphore *pS=(RSemaphore*)aSem;
418 CArrayFixFlat<TInt64>* pA=new CArrayFixFlat<TInt64>(8);
419 TKeyArrayFix key(0,ECmpTInt64);
421 for (i=0; i<1024; i++)
423 pA->AppendL(MAKE_TINT64(i>>6,i));
428 for (i=0; i<1024; i++)
432 TInt64 x = MAKE_TINT64(k>>6,k);
433 pA->FindIsq(x,key,j);
441 const TInt KHeapSize=16384;
442 LOCAL_C TInt DoSpeedTest(TThreadFunction f)
447 t.Create(_L("Speedy"),f,KDefaultStackSize,KHeapSize,KHeapSize,&sem);
448 t.SetPriority(EPriorityLess);
454 User::After(2000000);
457 User::WaitForRequest(s);
458 if (t.ExitType()!=EExitKill)
460 TExitCategoryName aExitCategory = t.ExitCategory();
461 test.Printf(_L("Exit %d %S %d\n"),t.ExitType(),&aExitCategory,t.ExitReason());
468 GLDEF_C void DoSpeedTests()
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);