1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/buffer/tarraysp.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,517 @@
1.4 +// Copyright (c) 1994-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// e32test\buffer\tarraysp.cpp
1.18 +//
1.19 +//
1.20 +
1.21 +#include <e32test.h>
1.22 +#include <e32math.h>
1.23 +
1.24 +GLREF_D RTest test;
1.25 +GLREF_C TInt Random();
1.26 +
1.27 +LOCAL_D TInt Count=0;
1.28 +
1.29 +GLREF_D TLinearOrder<TInt64> Int64Order;
1.30 +
1.31 +volatile TReal Absorber;
1.32 +volatile TInt DummyFlag = 1;
1.33 +
1.34 +#undef FOREVER
1.35 +#define FOREVER while (DummyFlag)
1.36 +
1.37 +
1.38 +LOCAL_C TInt VerySlowInt64Order(const TInt64& a, const TInt64& b)
1.39 + {
1.40 + TReal x;
1.41 + Math::Ln(x, 2.0);
1.42 + Absorber = x;
1.43 + if (a < b)
1.44 + return -1;
1.45 + if (a == b)
1.46 + return 0;
1.47 + return 1;
1.48 + }
1.49 +
1.50 +
1.51 +LOCAL_C TInt SpeedTest1(TAny* aSem)
1.52 + {
1.53 + RSemaphore *pS=(RSemaphore*)aSem;
1.54 + pS->Signal();
1.55 + FOREVER
1.56 + {
1.57 + TInt i;
1.58 + RArray<TInt> a;
1.59 + for (i=0; i<1000; i++)
1.60 + a.Append(Count++);
1.61 + a.Close();
1.62 + }
1.63 + return KErrNone;
1.64 + }
1.65 +
1.66 +LOCAL_C TInt SpeedTest2(TAny* aSem)
1.67 + {
1.68 + RSemaphore *pS=(RSemaphore*)aSem;
1.69 + CArrayFixFlat<TInt>* pA=new CArrayFixFlat<TInt>(8);
1.70 + pS->Signal();
1.71 + FOREVER
1.72 + {
1.73 + TInt i;
1.74 + for (i=0; i<1000; i++)
1.75 + {
1.76 + pA->AppendL(Count++);
1.77 + }
1.78 + pA->Reset();
1.79 + }
1.80 + delete pA;
1.81 + return KErrNone;
1.82 + }
1.83 +
1.84 +TInt Total;
1.85 +LOCAL_C TInt SpeedTest3(TAny* aSem)
1.86 + {
1.87 + RSemaphore *pS=(RSemaphore*)aSem;
1.88 + TInt i;
1.89 + RArray<TInt> a;
1.90 + for (i=0; i<1000; i++)
1.91 + a.Append(i);
1.92 + pS->Signal();
1.93 + FOREVER
1.94 + {
1.95 + TInt total=0;
1.96 + for (i=0; i<1000; i++)
1.97 + {
1.98 + total+=a[i];
1.99 + Count++;
1.100 + }
1.101 + Total=total;
1.102 + }
1.103 + return KErrNone;
1.104 + }
1.105 +
1.106 +LOCAL_C TInt SpeedTest4(TAny* aSem)
1.107 + {
1.108 + RSemaphore *pS=(RSemaphore*)aSem;
1.109 + CArrayFixFlat<TInt>* pA=new CArrayFixFlat<TInt>(8);
1.110 + TInt i;
1.111 + for (i=0; i<1000; i++)
1.112 + {
1.113 + pA->AppendL(i);
1.114 + }
1.115 + pS->Signal();
1.116 + FOREVER
1.117 + {
1.118 + TInt total=0;
1.119 + for (i=0; i<1000; i++)
1.120 + {
1.121 + total+=(*pA)[i];
1.122 + Count++;
1.123 + }
1.124 + Total=total;
1.125 + }
1.126 + delete pA;
1.127 + return KErrNone;
1.128 + }
1.129 +
1.130 +LOCAL_C TInt SpeedTest5(TAny* aSem)
1.131 + {
1.132 + RSemaphore *pS=(RSemaphore*)aSem;
1.133 + pS->Signal();
1.134 + FOREVER
1.135 + {
1.136 + TInt i;
1.137 + RArray<TInt> a;
1.138 + for (i=999; i>=0; i--, Count++)
1.139 + a.InsertInOrder(i);
1.140 + a.Close();
1.141 + }
1.142 + return KErrNone;
1.143 + }
1.144 +
1.145 +LOCAL_C TInt SpeedTest5a(TAny* aSem)
1.146 + {
1.147 + RSemaphore *pS=(RSemaphore*)aSem;
1.148 + pS->Signal();
1.149 + FOREVER
1.150 + {
1.151 + TInt i;
1.152 + RArray<TInt> a;
1.153 + for (i=999; i>=0; i--, Count++)
1.154 + a.InsertInOrderAllowRepeats(0);
1.155 + a.Close();
1.156 + }
1.157 + return KErrNone;
1.158 + }
1.159 +
1.160 +LOCAL_C TInt SpeedTest6(TAny* aSem)
1.161 + {
1.162 + RSemaphore *pS=(RSemaphore*)aSem;
1.163 + CArrayFixFlat<TInt>* pA=new CArrayFixFlat<TInt>(8);
1.164 + TKeyArrayFix key(0,ECmpTInt);
1.165 + pS->Signal();
1.166 + FOREVER
1.167 + {
1.168 + TInt i;
1.169 + for (i=999; i>=0; i--, Count++)
1.170 + {
1.171 + pA->InsertIsqL(i,key);
1.172 + }
1.173 + pA->Reset();
1.174 + }
1.175 + delete pA;
1.176 + return KErrNone;
1.177 + }
1.178 +
1.179 +LOCAL_C TInt SpeedTest7(TAny* aSem)
1.180 + {
1.181 + RSemaphore *pS=(RSemaphore*)aSem;
1.182 + TInt i;
1.183 + RArray<TInt> a(1024);
1.184 + for (i=0; i<1000; i++)
1.185 + a.Append(Random());
1.186 + pS->Signal();
1.187 + FOREVER
1.188 + {
1.189 + a.Sort();
1.190 + for (i=0; i<1000; i++)
1.191 + a[i]=Random();
1.192 + Count++;
1.193 + }
1.194 + return KErrNone;
1.195 + }
1.196 +
1.197 +LOCAL_C TInt SpeedTest7b(TAny* aSem)
1.198 + {
1.199 + RSemaphore *pS=(RSemaphore*)aSem;
1.200 + TInt i;
1.201 + RArray<TInt64> a(1024);
1.202 + for (i=0; i<1000; i++)
1.203 + a.Append(MAKE_TINT64(Random(),Random()));
1.204 + pS->Signal();
1.205 + FOREVER
1.206 + {
1.207 + a.Sort(Int64Order);
1.208 + for (i=0; i<1000; i++)
1.209 + a[i]=MAKE_TINT64(Random(),Random());
1.210 + Count++;
1.211 + }
1.212 + return KErrNone;
1.213 + }
1.214 +
1.215 +LOCAL_C TInt SpeedTest8(TAny* aSem)
1.216 + {
1.217 + RSemaphore *pS=(RSemaphore*)aSem;
1.218 + CArrayFixFlat<TInt>* pA=new CArrayFixFlat<TInt>(1024);
1.219 + TKeyArrayFix key(0,ECmpTInt);
1.220 + TInt i;
1.221 + for (i=0; i<1000; i++)
1.222 + pA->AppendL(Random());
1.223 + pS->Signal();
1.224 + FOREVER
1.225 + {
1.226 + pA->Sort(key);
1.227 + for (i=0; i<1000; i++)
1.228 + (*pA)[i]=Random();
1.229 + Count++;
1.230 + }
1.231 + delete pA;
1.232 + return KErrNone;
1.233 + }
1.234 +
1.235 +LOCAL_C TInt SpeedTest8a(TAny* aSem)
1.236 + {
1.237 + RSemaphore *pS=(RSemaphore*)aSem;
1.238 + CArrayFixFlat<TInt64>* pA=new CArrayFixFlat<TInt64>(1024);
1.239 + TKeyArrayFix key(0,ECmpTInt64);
1.240 + TInt i;
1.241 + for (i=0; i<1000; i++)
1.242 + pA->AppendL(MAKE_TINT64(Random(),Random()));
1.243 + pS->Signal();
1.244 + FOREVER
1.245 + {
1.246 + pA->Sort(key);
1.247 + for (i=0; i<1000; i++)
1.248 + (*pA)[i]=MAKE_TINT64(Random(),Random());
1.249 + Count++;
1.250 + }
1.251 + delete pA;
1.252 + return KErrNone;
1.253 + }
1.254 +
1.255 +LOCAL_C TInt SpeedTest9(TAny* aSem)
1.256 + {
1.257 + RSemaphore *pS=(RSemaphore*)aSem;
1.258 + pS->Signal();
1.259 + FOREVER
1.260 + {
1.261 + TInt i;
1.262 + RArray<TInt> a;
1.263 + for (i=0; i<1000; i++, Count++)
1.264 + a.InsertInOrder(Random());
1.265 + a.Close();
1.266 + }
1.267 + return KErrNone;
1.268 + }
1.269 +
1.270 +LOCAL_C TInt SpeedTest9b(TAny* aSem)
1.271 + {
1.272 + RSemaphore *pS=(RSemaphore*)aSem;
1.273 + pS->Signal();
1.274 + FOREVER
1.275 + {
1.276 + TInt i;
1.277 + RArray<TInt64> a;
1.278 + for (i=0; i<1000; i++, Count++)
1.279 + a.InsertInOrder(MAKE_TINT64(Random(),Random()),Int64Order);
1.280 + a.Close();
1.281 + }
1.282 + return KErrNone;
1.283 + }
1.284 +
1.285 +LOCAL_C TInt SpeedTest9q(TAny* aSem)
1.286 + {
1.287 + RSemaphore *pS=(RSemaphore*)aSem;
1.288 + pS->Signal();
1.289 + FOREVER
1.290 + {
1.291 + TInt i;
1.292 + RArray<TInt64> a;
1.293 + for (i=0; i<1000; i++, Count++)
1.294 + a.InsertInOrderAllowRepeats(MAKE_TINT64(0,i), &VerySlowInt64Order);
1.295 + a.Close();
1.296 + }
1.297 + return KErrNone;
1.298 + }
1.299 +
1.300 +LOCAL_C TInt SpeedTest9r(TAny* aSem)
1.301 + {
1.302 + RSemaphore *pS=(RSemaphore*)aSem;
1.303 + pS->Signal();
1.304 + FOREVER
1.305 + {
1.306 + TInt i;
1.307 + RArray<TInt64> a;
1.308 + for (i=0; i<1000; i++, Count++)
1.309 + a.InsertInOrderAllowRepeats(MAKE_TINT64(0,0), &VerySlowInt64Order);
1.310 + a.Close();
1.311 + }
1.312 + return KErrNone;
1.313 + }
1.314 +
1.315 +LOCAL_C TInt SpeedTest10(TAny* aSem)
1.316 + {
1.317 + RSemaphore *pS=(RSemaphore*)aSem;
1.318 + CArrayFixFlat<TInt>* pA=new CArrayFixFlat<TInt>(8);
1.319 + TKeyArrayFix key(0,ECmpTInt);
1.320 + pS->Signal();
1.321 + FOREVER
1.322 + {
1.323 + TInt i;
1.324 + for (i=0; i<1000; i++, Count++)
1.325 + {
1.326 + pA->InsertIsqAllowDuplicatesL(Random(),key);
1.327 + }
1.328 + pA->Reset();
1.329 + }
1.330 + delete pA;
1.331 + return KErrNone;
1.332 + }
1.333 +
1.334 +LOCAL_C TInt SpeedTest10a(TAny* aSem)
1.335 + {
1.336 + RSemaphore *pS=(RSemaphore*)aSem;
1.337 + CArrayFixFlat<TInt64>* pA=new CArrayFixFlat<TInt64>(8);
1.338 + TKeyArrayFix key(0,ECmpTInt64);
1.339 + pS->Signal();
1.340 + FOREVER
1.341 + {
1.342 + TInt i;
1.343 + for (i=0; i<1000; i++, Count++)
1.344 + {
1.345 + pA->InsertIsqAllowDuplicatesL(MAKE_TINT64(Random(),Random()),key);
1.346 + }
1.347 + pA->Reset();
1.348 + }
1.349 + delete pA;
1.350 + return KErrNone;
1.351 + }
1.352 +
1.353 +LOCAL_C TInt SpeedTest11(TAny* aSem)
1.354 + {
1.355 + RSemaphore *pS=(RSemaphore*)aSem;
1.356 + TInt i;
1.357 + RArray<TInt> a(1024);
1.358 + for (i=0; i<1024; i++)
1.359 + a.Append(i);
1.360 + pS->Signal();
1.361 + FOREVER
1.362 + {
1.363 + for (i=0; i<1024; i++)
1.364 + {
1.365 + a.FindInOrder(i^0x2b9);
1.366 + Count++;
1.367 + }
1.368 + }
1.369 + return KErrNone;
1.370 + }
1.371 +
1.372 +LOCAL_C TInt SpeedTest11b(TAny* aSem)
1.373 + {
1.374 + RSemaphore *pS=(RSemaphore*)aSem;
1.375 + TInt i;
1.376 + RArray<TInt64> a(1024);
1.377 + for (i=0; i<1024; i++)
1.378 + a.Append(MAKE_TINT64(i>>6,i));
1.379 + pS->Signal();
1.380 + FOREVER
1.381 + {
1.382 + for (i=0; i<1024; i++)
1.383 + {
1.384 + TInt j=i^0x2b9;
1.385 + TInt64 x = MAKE_TINT64(j>>6,j);
1.386 + a.FindInOrder(x,Int64Order);
1.387 + Count++;
1.388 + }
1.389 + }
1.390 + return KErrNone;
1.391 + }
1.392 +
1.393 +LOCAL_C TInt SpeedTest12(TAny* aSem)
1.394 + {
1.395 + RSemaphore *pS=(RSemaphore*)aSem;
1.396 + CArrayFixFlat<TInt>* pA=new CArrayFixFlat<TInt>(8);
1.397 + TKeyArrayFix key(0,ECmpTInt);
1.398 + TInt i;
1.399 + for (i=0; i<1024; i++)
1.400 + {
1.401 + pA->AppendL(i);
1.402 + }
1.403 + pS->Signal();
1.404 + FOREVER
1.405 + {
1.406 + for (i=0; i<1024; i++)
1.407 + {
1.408 + TInt j;
1.409 + TInt k=i^0x2b9;
1.410 + pA->FindIsq(k,key,j);
1.411 + Count++;
1.412 + }
1.413 + }
1.414 + delete pA;
1.415 + return KErrNone;
1.416 + }
1.417 +
1.418 +LOCAL_C TInt SpeedTest12a(TAny* aSem)
1.419 + {
1.420 + RSemaphore *pS=(RSemaphore*)aSem;
1.421 + CArrayFixFlat<TInt64>* pA=new CArrayFixFlat<TInt64>(8);
1.422 + TKeyArrayFix key(0,ECmpTInt64);
1.423 + TInt i;
1.424 + for (i=0; i<1024; i++)
1.425 + {
1.426 + pA->AppendL(MAKE_TINT64(i>>6,i));
1.427 + }
1.428 + pS->Signal();
1.429 + FOREVER
1.430 + {
1.431 + for (i=0; i<1024; i++)
1.432 + {
1.433 + TInt j;
1.434 + TInt k=i^0x2b9;
1.435 + TInt64 x = MAKE_TINT64(k>>6,k);
1.436 + pA->FindIsq(x,key,j);
1.437 + Count++;
1.438 + }
1.439 + }
1.440 + delete pA;
1.441 + return KErrNone;
1.442 + }
1.443 +
1.444 +const TInt KHeapSize=16384;
1.445 +LOCAL_C TInt DoSpeedTest(TThreadFunction f)
1.446 + {
1.447 + RSemaphore sem;
1.448 + sem.CreateLocal(0);
1.449 + RThread t;
1.450 + t.Create(_L("Speedy"),f,KDefaultStackSize,KHeapSize,KHeapSize,&sem);
1.451 + t.SetPriority(EPriorityLess);
1.452 + Count=0;
1.453 + TRequestStatus s;
1.454 + t.Logon(s);
1.455 + t.Resume();
1.456 + sem.Wait();
1.457 + User::After(2000000);
1.458 + TInt num=Count/2;
1.459 + t.Kill(0);
1.460 + User::WaitForRequest(s);
1.461 + if (t.ExitType()!=EExitKill)
1.462 + {
1.463 + TExitCategoryName aExitCategory = t.ExitCategory();
1.464 + test.Printf(_L("Exit %d %S %d\n"),t.ExitType(),&aExitCategory,t.ExitReason());
1.465 + }
1.466 + CLOSE_AND_WAIT(t);
1.467 + sem.Close();
1.468 + return num;
1.469 + }
1.470 +
1.471 +GLDEF_C void DoSpeedTests()
1.472 + {
1.473 + TInt r;
1.474 + test.Next(_L("Speed Tests"));
1.475 + r=DoSpeedTest(SpeedTest1);
1.476 + test.Printf(_L("RArray<TInt> append, %d in 1 second\n"),r);
1.477 + r=DoSpeedTest(SpeedTest2);
1.478 + test.Printf(_L("CArrayFixFlat<TInt> append, %d in 1 second\n"),r);
1.479 + r=DoSpeedTest(SpeedTest3);
1.480 + test.Printf(_L("RArray<TInt> access, %d in 1 second\n"),r);
1.481 + test(Total==999*1000/2);
1.482 + r=DoSpeedTest(SpeedTest4);
1.483 + test.Printf(_L("CArrayFixFlat<TInt> access, %d in 1 second\n"),r);
1.484 + test(Total==999*1000/2);
1.485 + r=DoSpeedTest(SpeedTest5);
1.486 + test.Printf(_L("RArray<TInt> InsertInOrder, %d in 1 second\n"),r);
1.487 + r=DoSpeedTest(SpeedTest5a);
1.488 + test.Printf(_L("RArray<TInt> InsertInOrder repeats, %d in 1 second\n"),r);
1.489 + r=DoSpeedTest(SpeedTest6);
1.490 + test.Printf(_L("CArrayFixFlat<TInt> InsertIsqL, %d in 1 second\n"),r);
1.491 + r=DoSpeedTest(SpeedTest7);
1.492 + test.Printf(_L("RArray<TInt> Sort 1000, %d in 1 second\n"),r);
1.493 + r=DoSpeedTest(SpeedTest7b);
1.494 + test.Printf(_L("RArray<TInt64> Sort 1000, %d in 1 second\n"),r);
1.495 + r=DoSpeedTest(SpeedTest8);
1.496 + test.Printf(_L("CArrayFixFlat<TInt> Sort 1000, %d in 1 second\n"),r);
1.497 + r=DoSpeedTest(SpeedTest8a);
1.498 + test.Printf(_L("CArrayFixFlat<TInt64> Sort 1000, %d in 1 second\n"),r);
1.499 + r=DoSpeedTest(SpeedTest9);
1.500 + test.Printf(_L("RArray<TInt> InsertInOrder random, %d in 1 second\n"),r);
1.501 + r=DoSpeedTest(SpeedTest9b);
1.502 + test.Printf(_L("RArray<TInt64> InsertInOrder random, %d in 1 second\n"),r);
1.503 + r=DoSpeedTest(SpeedTest9q);
1.504 + test.Printf(_L("RArray<TInt64> InsertInOrder repeat control, %d in 1 second\n"),r);
1.505 + r=DoSpeedTest(SpeedTest9r);
1.506 + test.Printf(_L("RArray<TInt64> InsertInOrder repeats, %d in 1 second\n"),r);
1.507 + r=DoSpeedTest(SpeedTest10);
1.508 + test.Printf(_L("CArrayFixFlat<TInt> InsertIsqL random, %d in 1 second\n"),r);
1.509 + r=DoSpeedTest(SpeedTest10a);
1.510 + test.Printf(_L("CArrayFixFlat<TInt64> InsertIsqL random, %d in 1 second\n"),r);
1.511 + r=DoSpeedTest(SpeedTest11);
1.512 + test.Printf(_L("RArray<TInt> FindInOrder, %d in 1 second\n"),r);
1.513 + r=DoSpeedTest(SpeedTest11b);
1.514 + test.Printf(_L("RArray<TInt64> FindInOrder, %d in 1 second\n"),r);
1.515 + r=DoSpeedTest(SpeedTest12);
1.516 + test.Printf(_L("CArrayFixFlat<TInt> FindIsqL, %d in 1 second\n"),r);
1.517 + r=DoSpeedTest(SpeedTest12a);
1.518 + test.Printf(_L("CArrayFixFlat<TInt64> FindIsqL, %d in 1 second\n"),r);
1.519 + }
1.520 +