Update contrib.
1 // Copyright (c) 1996-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\bench\t_membm.cpp
19 #include <e32std_private.h>
21 #include <e32base_private.h>
25 #define ALIGN_UP(x, y) (TInt8*)(_ALIGN_UP((TInt)(x), (y)))
26 #define ALIGN_DOWN(x, y) (TInt8*)(_ALIGN_DOWN((TInt)(x), (y)))
28 const TInt KHeapSize=720*1024;
29 const TInt KAverageOverInMilliseconds=500;
30 const TInt Len64K = 64*1024;
43 RTest test(_L("T_MEMBM"));
45 GLREF_C TInt MemBaseline(TAny*);
46 GLREF_C TInt MemCopy(TAny*);
47 GLREF_C TInt MemMove(TAny*);
48 GLREF_C TInt MemFill(TAny*);
49 GLREF_C TInt MemSwap(TAny*);
50 GLREF_C TInt WordMove(TAny*);
51 GLREF_C TInt MemCopyUncached(TAny*);
52 GLREF_C TInt WordMoveUncached(TAny*);
53 GLREF_C TInt MemFillUncached(TAny*);
54 GLREF_C TInt PurgeCache();
56 TInt nextLen(TInt aTestLength)
63 TInt inc = aTestLength;
64 for (TInt i = len >> 5 ; i ; i >>= 1)
71 * Run benchmarks on the supplied function.
73 * @param aFunction The function to benchmark
74 * @param aTestBackwards Run copy tests with overlapping areas to test backwards copy
75 * @param aTestSrcAlign Run tests for source alignments 0 - 31
76 * @param aTestDestAlign Run tests for destination alignments 0 - 31
77 * @param aTestLength If non-zero, run tests for different lengths starting at aTestLength
79 TInt64 runTest(TThreadFunction aFunction,const TDesC& aTitle, TBool aTestBackwards, TBool aTestSrcAlign, TBool aTestDestAlign, TInt aTestLength)
81 TInt8* buffer = (TInt8*)User::Alloc(640 * 1024 + 32);
84 test(!(aTestLength && aTestBackwards)); // not supported
86 TBool goingforward=ETrue;
91 test.Printf(_L("Running length experiment on %S. Results follow:\n"), &aTitle);
94 while(len = nextLen(aTestLength), len)
96 src = ALIGN_UP(buffer, 32);
98 trg = src + 512 * 1024; // blow half a meg
100 trg = ALIGN_DOWN(src + len - 1, 32); // ensure overlapping, doesn't work for length < 32
103 test.Printf(_L("%d, "), len);
105 test.Printf(_L("Test array bases trg=0x%08x, src=0x%08x. Running experiment on %S. Results follow:\n"), trg, src, &aTitle);
107 const TInt xsquare = aTestDestAlign ? 32 : 1;
108 const TInt ysquare = aTestSrcAlign ? 32 : 1;
110 for (srcoffset = 0 ; srcoffset < ysquare ; srcoffset++)
112 for (trgoffset = 0 ; trgoffset < xsquare ; trgoffset++)
115 TInt r=thread.Create(aTitle,aFunction,KDefaultStackSize,KHeapSize,KHeapSize,NULL);
118 test.Printf(_L("Failed to create thread with error %d\n"),r);
121 thread.SetPriority(EPriorityLess);
123 User::After(50000); // 50 msec is more than enough in EKA2
125 User::After(5000); // even if the second reset fails, max inaccuracy is 5000 usecs
126 count=0; // try and reduce the probability of failing to reset
127 User::After(KAverageOverInMilliseconds*1000);
130 CLOSE_AND_WAIT(thread);
134 result /= KAverageOverInMilliseconds;
136 TInt s = I64INT(result);
137 test.Printf(_L("%d, "),s);
139 test.Printf(_L("\n"));
143 if (aTestBackwards && goingforward)
144 goingforward = EFalse;
161 // Return whether we should run the full alignment benchmarks
162 TTestType ParseCommandLine()
165 User::CommandLine(args);
167 if (args == _L("-f"))
169 else if (args == _L("-l"))
171 else if (args != KNullDesC)
173 test.Printf(_L("usage: t_membm [OPTIONS]\n"));
174 test.Printf(_L(" -f Run full alignment benchmarks\n"));
175 test.Printf(_L(" -l Run memcpy length benchmarks\n"));
184 // Benchmark for Mem functions
189 test.Start(_L("Benchmarks for Mem functions"));
191 TTestType testType = ParseCommandLine();
198 TBool srcAlign = testType == EFullTests;
201 test.Printf(_L("Running full alignment benchmarks (may take a long time)\n"));
203 test.Printf(_L("Not testing source alignment (run with -f if you want this)\n"));
205 runTest(MemBaseline, _L("Processor baseline"), EFalse, EFalse, EFalse, 0);
206 runTest(MemFill, _L("Memory fill"), EFalse, EFalse, ETrue, 0);
207 runTest(MemCopy, _L("Memory copy"), ETrue, srcAlign, ETrue, 0);
208 runTest(MemSwap, _L("Memory swap"), ETrue, srcAlign, ETrue, 0);
212 test.Printf(_L("Running length benchmarks (may take a long time)\n"));
213 runTest(MemFill, _L("Fill length cached"), EFalse, EFalse, EFalse, 1);
214 runTest(MemFillUncached, _L("Fill length uncached"), EFalse, EFalse, EFalse, 1);
215 runTest(MemCopy, _L("Copy length cached"), EFalse, EFalse, EFalse, 1);
216 runTest(MemCopyUncached, _L("Copy length uncached"), EFalse, EFalse, EFalse, 1);
217 runTest(WordMove, _L("Word move length cached"), EFalse, EFalse, EFalse, 4);
218 runTest(WordMoveUncached,_L("Word move length uncached"), EFalse, EFalse, EFalse, 4);