1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/bench/t_userasmfnc.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,520 @@
1.4 +// Copyright (c) 2005-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\bench\t_userasmfnc.cpp
1.18 +//
1.19 +//
1.20 +
1.21 +#include "t_userbm.h"
1.22 +#include <e32huffman.h>
1.23 +#include <e32math.h>
1.24 +#include <e32base.h>
1.25 +#include <e32base_private.h>
1.26 +#include <e32std.h>
1.27 +#include <e32std_private.h>
1.28 +#include <e32svr.h>
1.29 +
1.30 +TBool PointsEqual(const TPoint& a, const TPoint& b)
1.31 + {
1.32 + return a.iX == b.iX && a.iY == b.iY;
1.33 + }
1.34 +
1.35 +TInt ComparePoints(const TPoint& a, const TPoint& b)
1.36 + {
1.37 + if (a.iX < b.iX)
1.38 + return -1;
1.39 + else if (a.iX > b.iX)
1.40 + return 1;
1.41 + else if (a.iY < b.iY)
1.42 + return -1;
1.43 + else
1.44 + return a.iY < b.iY;
1.45 + }
1.46 +
1.47 +RArray<TInt> ArrayTInt; // RArrayPointerBase derived
1.48 +RArray<TUint> ArrayTUint; // RArrayPointerBase derived
1.49 +RPointerArray<TPoint> ArrayTPointPtr;
1.50 +RArray<TPoint> ArrayTPoint;
1.51 +
1.52 +TPoint Point(6, 13);
1.53 +TIdentityRelation<TPoint> PointIdentity(PointsEqual);
1.54 +TLinearOrder<TPoint> PointOrder(ComparePoints);
1.55 +
1.56 +CObjectConIx* ObjectConIx;
1.57 +CObjectIx* ObjectIx;
1.58 +CObjectCon* ObjectCon;
1.59 +TInt ObjectHandle;
1.60 +
1.61 +TUint32 HuffmanTable[] = { 0, 1, 3, 8, 10, 3, 1, 0 };
1.62 +TBitInput BitInput;
1.63 +TUint8 BitData[] = { 0, 0, 0, 0 };
1.64 +
1.65 +RRegion Region, Region2, Region3;
1.66 +TRect Rect1(20, 20, 40, 40);
1.67 +
1.68 +SPoly* Poly;
1.69 +TRealX PolyXCoeffs[] = { 1.0, 3.0, 5.0 };
1.70 +
1.71 +RHeap* Heap;
1.72 +const TInt HeapSize = 32768;
1.73 +const TInt SmallAlloc = 4;
1.74 +const TInt Allocs = HeapSize / 2 / (SmallAlloc + RHeap::EAllocCellSize) / 2 * 2;
1.75 +
1.76 +void InitDataL()
1.77 + {
1.78 + TInt array1Data[] = { 1, 2, 3, 5, 7, 11, 13, 17, 23 };
1.79 + for (TUint i = 0 ; i < sizeof(array1Data) / sizeof(TInt) ; ++i)
1.80 + {
1.81 + User::LeaveIfError(ArrayTInt.Append(array1Data[i]));
1.82 + User::LeaveIfError(ArrayTUint.Append(array1Data[i]));
1.83 + TPoint* p = new (ELeave) TPoint(i, array1Data[i]);
1.84 + CleanupStack::PushL(p);
1.85 + User::LeaveIfError(ArrayTPointPtr.Append(p));
1.86 + CleanupStack::Pop(p);
1.87 + User::LeaveIfError(ArrayTPoint.Append(*p));
1.88 + }
1.89 +
1.90 + ObjectConIx = CObjectConIx::NewL();
1.91 + ObjectCon = ObjectConIx->CreateL();
1.92 + ObjectIx = CObjectIx::NewL();
1.93 + CObject* o = new (ELeave) CObject;
1.94 + ObjectCon->AddL(o);
1.95 + ObjectHandle = ObjectIx->AddL(o);
1.96 +
1.97 + Huffman::HuffmanL(HuffmanTable, sizeof(HuffmanTable) / sizeof(TUint32), HuffmanTable);
1.98 + Huffman::Decoding(HuffmanTable, sizeof(HuffmanTable) / sizeof(TUint32), HuffmanTable);
1.99 +
1.100 + Region.AddRect(TRect(10, 10, 30, 30));
1.101 + Region.AddRect(TRect(30, 20, 50, 50));
1.102 + Region.AddRect(TRect(10, 50, 50, 60));
1.103 +
1.104 + Region2.AddRect(TRect(0, 40, 100, 60));
1.105 + Region2.AddRect(TRect(40, 0, 60, 100));
1.106 + Region2.AddRect(TRect(30, 30, 70, 70));
1.107 +
1.108 + Region3.AddRect(TRect(0, 30, 100, 40));
1.109 + Region3.AddRect(TRect(0, 0, 100, 10));
1.110 + Region3.AddRect(TRect(0, 20, 100, 30));
1.111 + Region3.AddRect(TRect(0, 10, 100, 20));
1.112 + Region3.AddRect(TRect(0, 40, 100, 50));
1.113 +
1.114 + Poly = (SPoly*) User::AllocL(sizeof(SPoly) + (3 - 1) * sizeof(TReal));
1.115 + Poly->num = 3;
1.116 + Poly->c[0] = 3;
1.117 + Poly->c[1] = 6;
1.118 + Poly->c[2] = 9;
1.119 +
1.120 + Heap = (RHeap*)User::LeaveIfNull(UserHeap::ChunkHeap(NULL, HeapSize, HeapSize));
1.121 + TInt x;
1.122 + TAny* cells[Allocs];
1.123 + for (x=0; x<Allocs; ++x)
1.124 + cells[x] = Heap->Alloc(4);
1.125 + for (x=0; x<Allocs; x += 2)
1.126 + Heap->Free(cells[x]);
1.127 + }
1.128 +
1.129 +// Define benchmarks for assembler-coded euser functions. Note that these are
1.130 +// named after the function we're trying to test, which is not necessarily the
1.131 +// one we call.
1.132 +
1.133 +// RPointerArrayBase
1.134 +DEFINE_USER_BENCHMARK(RPointerArrayBase_At,
1.135 + ,
1.136 + ArrayTInt[4]);
1.137 +
1.138 +DEFINE_USER_BENCHMARK(RPointerArrayBase_Append,
1.139 + RArray<TInt> a,
1.140 + a.Reset(); a.Append(1));
1.141 +
1.142 +DEFINE_USER_BENCHMARK(RPointerArrayBase_Find1,
1.143 + ,
1.144 + ArrayTInt.Find(5));
1.145 +
1.146 +DEFINE_USER_BENCHMARK(RPointerArrayBase_Find2,
1.147 + ,
1.148 + ArrayTPointPtr.Find(&Point, PointIdentity));
1.149 +
1.150 +DEFINE_USER_BENCHMARK(RPointerArrayBase_BinarySearchSigned,
1.151 + TInt i,
1.152 + ArrayTInt.SpecificFindInOrder(13, i, EArrayFindMode_Any));
1.153 +
1.154 +DEFINE_USER_BENCHMARK(RPointerArrayBase_BinarySearchUnsigned,
1.155 + TInt i,
1.156 + ArrayTUint.SpecificFindInOrder(13, i, EArrayFindMode_Any));
1.157 +
1.158 +DEFINE_USER_BENCHMARK(RPointerArrayBase_BinarySearch,
1.159 + ,
1.160 + ArrayTPointPtr.SpecificFindInOrder(&Point, PointOrder, EArrayFindMode_Any));
1.161 +
1.162 +DEFINE_USER_BENCHMARK(RPointerArrayBase_FindIsqSigned,
1.163 + ,
1.164 + ArrayTInt.SpecificFindInOrder(5, EArrayFindMode_Any));
1.165 +
1.166 +DEFINE_USER_BENCHMARK(RPointerArrayBase_FindIsqUnsigned,
1.167 + ,
1.168 + ArrayTUint.SpecificFindInOrder(5, EArrayFindMode_Any));
1.169 +
1.170 +DEFINE_USER_BENCHMARK(RPointerArrayBase_FindIsq,
1.171 + ,
1.172 + ArrayTPointPtr.SpecificFindInOrder(&Point, PointOrder, EArrayFindMode_Any));
1.173 +
1.174 +DEFINE_USER_BENCHMARK(RPointerArrayBase_HeapSortSigned,
1.175 + ,
1.176 + ArrayTInt.Sort());
1.177 +
1.178 +DEFINE_USER_BENCHMARK(RPointerArrayBase_HeapSortUnsigned,
1.179 + ,
1.180 + ArrayTUint.Sort());
1.181 +
1.182 +DEFINE_USER_BENCHMARK(RPointerArrayBase_HeapSort,
1.183 + ,
1.184 + ArrayTPointPtr.Sort(PointOrder));
1.185 +
1.186 +// RArrayBase
1.187 +DEFINE_USER_BENCHMARK(RArrayBase_At,
1.188 + ,
1.189 + ArrayTPoint[4]);
1.190 +
1.191 +DEFINE_USER_BENCHMARK(RArrayBase_Append,
1.192 + RArray<TPoint> a,
1.193 + a.Reset(); a.Append(Point));
1.194 +
1.195 +DEFINE_USER_BENCHMARK(RArrayBase_Find1,
1.196 + ,
1.197 + ArrayTPoint.Find(Point));
1.198 +
1.199 +DEFINE_USER_BENCHMARK(RArrayBase_Find2,
1.200 + ,
1.201 + ArrayTPoint.Find(Point, PointIdentity));
1.202 +
1.203 +DEFINE_USER_BENCHMARK(RArrayBase_BinarySearchSigned,
1.204 + TInt i,
1.205 + ArrayTPoint.SpecificFindInSignedKeyOrder(Point, i, EArrayFindMode_Any));
1.206 +
1.207 +DEFINE_USER_BENCHMARK(RArrayBase_BinarySearchUnsigned,
1.208 + TInt i,
1.209 + ArrayTPoint.SpecificFindInUnsignedKeyOrder(Point, i, EArrayFindMode_Any));
1.210 +
1.211 +DEFINE_USER_BENCHMARK(RArrayBase_BinarySearch,
1.212 + TInt i,
1.213 + ArrayTPoint.FindInOrder(Point, i, PointOrder));
1.214 +
1.215 +DEFINE_USER_BENCHMARK(RArrayBase_FindIsqSigned,
1.216 + ,
1.217 + ArrayTPoint.SpecificFindInSignedKeyOrder(Point, EArrayFindMode_Any));
1.218 +
1.219 +DEFINE_USER_BENCHMARK(RArrayBase_FindIsqUnsigned,
1.220 + ,
1.221 + ArrayTPoint.SpecificFindInUnsignedKeyOrder(Point, EArrayFindMode_Any));
1.222 +
1.223 +DEFINE_USER_BENCHMARK(RArrayBase_HeapSortSigned,
1.224 + ,
1.225 + ArrayTPoint.SortSigned());
1.226 +
1.227 +DEFINE_USER_BENCHMARK(RArrayBase_HeapSortUnsigned,
1.228 + ,
1.229 + ArrayTPoint.SortUnsigned());
1.230 +
1.231 +DEFINE_USER_BENCHMARK(RArrayBase_HeapSort,
1.232 + ,
1.233 + ArrayTPointPtr.Sort(PointOrder));
1.234 +
1.235 +// CObject related
1.236 +DEFINE_USER_BENCHMARK(CObjectIx_At1,
1.237 + ,
1.238 + ObjectIx->At(ObjectHandle));
1.239 +
1.240 +DEFINE_USER_BENCHMARK(CObjectIx_At2,
1.241 + ,
1.242 + ObjectIx->At(ObjectHandle, 0));
1.243 +
1.244 +DEFINE_USER_BENCHMARK(CObjectIx_ArrayOperator,
1.245 + ,
1.246 + (*ObjectIx)[0]);
1.247 +
1.248 +DEFINE_USER_BENCHMARK(CObjectCon_ArrayOperator,
1.249 + ,
1.250 + (*ObjectCon)[0]);
1.251 +
1.252 +DEFINE_USER_BENCHMARK(CObjectCon_At,
1.253 + ,
1.254 + ObjectCon->At(ObjectHandle));
1.255 +
1.256 +DEFINE_USER_BENCHMARK(CObjectCon_AtL,
1.257 + ,
1.258 + ObjectCon->AtL(ObjectHandle));
1.259 +
1.260 +// Huffman coding
1.261 +DEFINE_USER_BENCHMARK(TBitInput_ReadL1,
1.262 + ,
1.263 + BitInput.Set(BitData, 128); BitInput.ReadL());
1.264 +
1.265 +DEFINE_USER_BENCHMARK(TBitInput_ReadL2,
1.266 + ,
1.267 + BitInput.Set(BitData, 128); BitInput.ReadL(7));
1.268 +
1.269 +DEFINE_USER_BENCHMARK(TBitInput_HuffmanL,
1.270 + ,
1.271 + BitInput.Set(BitData, 128); BitInput.HuffmanL(HuffmanTable));
1.272 +
1.273 +// Regions
1.274 +DEFINE_USER_BENCHMARK(TRegion_BoundingRect,
1.275 + ,
1.276 + Region.BoundingRect());
1.277 +
1.278 +DEFINE_USER_BENCHMARK(TRegion_IsContainedBy,
1.279 + TRect r(0,0,90,90),
1.280 + Region.IsContainedBy(r));
1.281 +
1.282 +DEFINE_USER_BENCHMARK(TRegion_Copy,
1.283 + RRegion r,
1.284 + r.Copy(Region));
1.285 +
1.286 +DEFINE_USER_BENCHMARK(TRegion_Offset1,
1.287 + ,
1.288 + Region.Offset(0, 0));
1.289 +
1.290 +DEFINE_USER_BENCHMARK(TRegion_Contains,
1.291 + TPoint p(0, 0),
1.292 + Region.Contains(p));
1.293 +
1.294 +DEFINE_USER_BENCHMARK(TRegion_Intersects,
1.295 + TRect r(0, 0, 10, 10),
1.296 + Region2.Intersects(r));
1.297 +
1.298 +DEFINE_USER_BENCHMARK(TRegion_SubRect,
1.299 + RRegion r,
1.300 + r.Copy(Region); r.SubRect(Rect1));
1.301 +
1.302 +DEFINE_USER_BENCHMARK(TRegion_Intersection,
1.303 + RRegion r,
1.304 + r.Intersection(Region, Region2));
1.305 +
1.306 +DEFINE_USER_BENCHMARK(TRegion_ClipRect,
1.307 + RRegion r,
1.308 + r.Copy(Region); r.ClipRect(Rect1));
1.309 +
1.310 +DEFINE_USER_BENCHMARK(TRegion_Tidy,
1.311 + RRegion r,
1.312 + r.Copy(Region3); r.Tidy());
1.313 +
1.314 +// Maths
1.315 +DEFINE_USER_BENCHMARK(Math_Frac,
1.316 + TReal t,
1.317 + Math::Frac(t, KPi));
1.318 +
1.319 +DEFINE_USER_BENCHMARK(Math_Int1,
1.320 + TReal t,
1.321 + Math::Int(t, KPi));
1.322 +
1.323 +DEFINE_USER_BENCHMARK(Math_Int2,
1.324 + TInt16 t,
1.325 + Math::Int(t, KPi));
1.326 +
1.327 +DEFINE_USER_BENCHMARK(Math_Int3,
1.328 + TInt32 t,
1.329 + Math::Int(t, KPi));
1.330 +
1.331 +DEFINE_USER_BENCHMARK(Math_IsZero,
1.332 + ,
1.333 + Math::IsZero(KPi));
1.334 +
1.335 +DEFINE_USER_BENCHMARK(Math_IsNaN,
1.336 + ,
1.337 + Math::IsNaN(KPi));
1.338 +
1.339 +DEFINE_USER_BENCHMARK(Math_IsInfinite,
1.340 + ,
1.341 + Math::IsInfinite(KPi));
1.342 +
1.343 +DEFINE_USER_BENCHMARK(Math_IsFinite,
1.344 + ,
1.345 + Math::IsFinite(KPi));
1.346 +
1.347 +DEFINE_USER_BENCHMARK(Math_Sqrt,
1.348 + TReal t,
1.349 + Math::Sqrt(t, KPi));
1.350 +
1.351 +DEFINE_USER_BENCHMARK(Math_Poly,
1.352 + TRealX t,
1.353 + Math::PolyX(t, KPi, 3, PolyXCoeffs));
1.354 +
1.355 +// Not tested due to not being exported:
1.356 +// Math::SetZero
1.357 +// Math::SetNan
1.358 +// Math::SetInfinite
1.359 +
1.360 +// TRealX
1.361 +DEFINE_USER_BENCHMARK(TRealX_Cons1,
1.362 + TRealX t,
1.363 + new (&t) TRealX);
1.364 +
1.365 +DEFINE_USER_BENCHMARK(TRealX_Cons2,
1.366 + TRealX t,
1.367 + new (&t) TRealX(0, 0, 0));
1.368 +
1.369 +// covers TRealX::Set(TInt), TRealX::TRealX(TInt) and TRealX::operator=(TInt)
1.370 +DEFINE_USER_BENCHMARK(TRealX_SetInt,
1.371 + TRealX t,
1.372 + t = (TInt) 23);
1.373 +
1.374 +// covers TRealX::Set(TUint), TRealX::TRealX(TUint) and TRealX::operator=(TUint)
1.375 +DEFINE_USER_BENCHMARK(TRealX_SetUint,
1.376 + TRealX t,
1.377 + t = (TUint) 23);
1.378 +
1.379 +// covers TRealX::Set(TInt64), TRealX::TRealX(TInt64) and TRealX::operator=(TInt64)
1.380 +DEFINE_USER_BENCHMARK(TRealX_SetInt64,
1.381 + TRealX t,
1.382 + t = (TInt64) 23);
1.383 +
1.384 +// covers TRealX::Set(TReal32), TRealX::TRealX(TReal32) and TRealX::operator=(TReal32)
1.385 +DEFINE_USER_BENCHMARK(TRealX_SetReal32,
1.386 + TRealX t; TReal32 v = 23,
1.387 + t = v);
1.388 +
1.389 +// covers TRealX::Set(TReal64), TRealX::TRealX(TReal64) and TRealX::operator=(TReal64)
1.390 +DEFINE_USER_BENCHMARK(TRealX_SetReal64,
1.391 + TRealX t; TReal64 v = 23,
1.392 + t = v);
1.393 +
1.394 +DEFINE_USER_BENCHMARK(TRealX_SetZero,
1.395 + TRealX t,
1.396 + t.SetZero(EFalse));
1.397 +
1.398 +DEFINE_USER_BENCHMARK(TRealX_SetNaN,
1.399 + TRealX t,
1.400 + t.SetNaN());
1.401 +
1.402 +DEFINE_USER_BENCHMARK(TRealX_SetInfinite,
1.403 + TRealX t,
1.404 + t.SetInfinite(EFalse));
1.405 +
1.406 +DEFINE_USER_BENCHMARK(TRealX_IsZero,
1.407 + TRealX t,
1.408 + t.IsZero());
1.409 +
1.410 +DEFINE_USER_BENCHMARK(TRealX_IsNaN,
1.411 + TRealX t; t.SetNaN(),
1.412 + t.IsNaN());
1.413 +
1.414 +DEFINE_USER_BENCHMARK(TRealX_IsInfinite,
1.415 + TRealX t; t.SetInfinite(EFalse),
1.416 + t.IsInfinite());
1.417 +
1.418 +DEFINE_USER_BENCHMARK(TRealX_IsFinite,
1.419 + TRealX t,
1.420 + t.IsFinite());
1.421 +
1.422 +DEFINE_USER_BENCHMARK(TRealX_Int,
1.423 + TRealX t = 2.3,
1.424 + (TInt) t);
1.425 +
1.426 +DEFINE_USER_BENCHMARK(TRealX_Uint,
1.427 + TRealX t = 2.3,
1.428 + (TUint) t);
1.429 +
1.430 +DEFINE_USER_BENCHMARK(TRealX_Int64,
1.431 + TRealX t = 2.3,
1.432 + (TInt64) t);
1.433 +
1.434 +DEFINE_USER_BENCHMARK(TRealX_Real32,
1.435 + TRealX t = 2.3,
1.436 + (TReal32) t);
1.437 +
1.438 +DEFINE_USER_BENCHMARK(TRealX_Real64,
1.439 + TRealX t = 2.3,
1.440 + (TReal64) t);
1.441 +
1.442 +DEFINE_USER_BENCHMARK(TRealX_GetReal32,
1.443 + TRealX t = 2.3; TReal32 out,
1.444 + t.GetTReal(out));
1.445 +
1.446 +DEFINE_USER_BENCHMARK(TRealX_GetReal64,
1.447 + TRealX t = 2.3; TReal64 out,
1.448 + t.GetTReal(out));
1.449 +
1.450 +DEFINE_USER_BENCHMARK(TRealX_UnaryPlus,
1.451 + TRealX t,
1.452 + +t);
1.453 +
1.454 +DEFINE_USER_BENCHMARK(TRealX_UnaryMinus,
1.455 + TRealX t,
1.456 + -t);
1.457 +
1.458 +DEFINE_USER_BENCHMARK(TRealX_Compare,
1.459 + TRealX a = 0.2; TRealX b = 0.21,
1.460 + a.Compare(b));
1.461 +
1.462 +DEFINE_USER_BENCHMARK(TRealX_Sub,
1.463 + TRealX a = 1.0; TRealX b = 0.2,
1.464 + a - b);
1.465 +
1.466 +DEFINE_USER_BENCHMARK(TRealX_Add,
1.467 + TRealX a = 1.0; TRealX b = 0.2,
1.468 + a + b);
1.469 +
1.470 +DEFINE_USER_BENCHMARK(TRealX_Mult,
1.471 + TRealX a = 1.0; TRealX b = 0.2,
1.472 + a * b);
1.473 +
1.474 +DEFINE_USER_BENCHMARK(TRealX_Div,
1.475 + TRealX a = 1.0; TRealX b = 0.2,
1.476 + a / b);
1.477 +
1.478 +DEFINE_USER_BENCHMARK(TRealX_Mod,
1.479 + TRealX a = 1.1; TRealX b = 0.2,
1.480 + a % b);
1.481 +
1.482 +DEFINE_USER_BENCHMARK(TRealX_PreInc,
1.483 + TRealX t = 0.0,
1.484 + ++t);
1.485 +
1.486 +DEFINE_USER_BENCHMARK(TRealX_PostInc,
1.487 + TRealX t = 0.0,
1.488 + t++);
1.489 +
1.490 +DEFINE_USER_BENCHMARK(TRealX_PreDec,
1.491 + TRealX t = 0.0,
1.492 + --t);
1.493 +
1.494 +DEFINE_USER_BENCHMARK(TRealX_PostDec,
1.495 + TRealX t = 0.0,
1.496 + t--);
1.497 +
1.498 +DEFINE_USER_BENCHMARK(RHeap_AllocFree,
1.499 + TAny* mem,
1.500 + mem = Heap->Alloc(8);
1.501 + Heap->Free(mem));
1.502 +
1.503 +// The following were added for timing functions affected by user-side thread data.
1.504 +
1.505 +DEFINE_USER_BENCHMARK(User_Heap,
1.506 + ,
1.507 + User::Heap());
1.508 +
1.509 +DEFINE_USER_BENCHMARK(CActiveScheduler_Current,
1.510 + ,
1.511 + CActiveScheduler::Current());
1.512 +
1.513 +DEFINE_USER_BENCHMARK(User_TrapHandler,
1.514 + ,
1.515 + User::TrapHandler());
1.516 +
1.517 +DEFINE_USER_BENCHMARK(UserSvr_DllSetTls,
1.518 + ,
1.519 + UserSvr::DllSetTls(0, 0, 0));
1.520 +
1.521 +DEFINE_USER_BENCHMARK(UserSvr_DllTls,
1.522 + ,
1.523 + UserSvr::DllTls(0));