|
1 /* |
|
2 * Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "tprimegenperformance.h" |
|
20 #include "t_input.h" |
|
21 #include "t_output.h" |
|
22 #include <bigint.h> |
|
23 |
|
24 _LIT(KPrimeGenFormat, "\tPrime Generation Time: %f us/iteration (%i iterations in %f us)\r\n"); |
|
25 |
|
26 const TUint KMaxIterations=100; |
|
27 |
|
28 CTestAction* CPrimeGenPerformance::NewL(RFs& aFs, CConsoleBase& aConsole, |
|
29 Output& aOut, const TTestActionSpec& aTestActionSpec) |
|
30 { |
|
31 CTestAction* self = CPrimeGenPerformance::NewLC(aFs, aConsole, |
|
32 aOut, aTestActionSpec); |
|
33 CleanupStack::Pop(); |
|
34 return self; |
|
35 } |
|
36 |
|
37 CTestAction* CPrimeGenPerformance::NewLC(RFs& aFs, CConsoleBase& aConsole, |
|
38 Output& aOut, const TTestActionSpec& aTestActionSpec) |
|
39 { |
|
40 CPrimeGenPerformance* self = new(ELeave) CPrimeGenPerformance(aFs, aConsole, aOut); |
|
41 CleanupStack::PushL(self); |
|
42 self->ConstructL(aTestActionSpec); |
|
43 return self; |
|
44 } |
|
45 |
|
46 CPrimeGenPerformance::~CPrimeGenPerformance() |
|
47 { |
|
48 delete iBody; |
|
49 } |
|
50 |
|
51 CPrimeGenPerformance::CPrimeGenPerformance(RFs& aFs, CConsoleBase& aConsole, |
|
52 Output& aOut) : CTestAction(aConsole, aOut), iFs(aFs) |
|
53 { |
|
54 } |
|
55 |
|
56 void CPrimeGenPerformance::ConstructL(const TTestActionSpec& aTestActionSpec) |
|
57 { |
|
58 CTestAction::ConstructL(aTestActionSpec); |
|
59 iBody = HBufC8::NewL(aTestActionSpec.iActionBody.Length()); |
|
60 iBody->Des().Copy(aTestActionSpec.iActionBody); |
|
61 |
|
62 iBits = Input::ParseIntElement(*iBody, _L8("<bits>"), _L8("</bits>")); |
|
63 iIterations = Input::ParseIntElement(*iBody, _L8("<iterations>"), _L8("</iterations>")); |
|
64 __ASSERT_ALWAYS(iIterations < KMaxIterations, User::Panic(_L("Iterations too large"), 1)); |
|
65 } |
|
66 |
|
67 void CPrimeGenPerformance::DoPerformPrerequisite(TRequestStatus& aStatus) |
|
68 { |
|
69 TRequestStatus* status = &aStatus; |
|
70 User::RequestComplete(status, KErrNone); |
|
71 iActionState = CTestAction::EAction; |
|
72 } |
|
73 |
|
74 void CPrimeGenPerformance::DoPerformPostrequisite(TRequestStatus& aStatus) |
|
75 { |
|
76 TRequestStatus* status = &aStatus; |
|
77 iFinished = ETrue; |
|
78 User::RequestComplete(status, KErrNone); |
|
79 } |
|
80 |
|
81 void CPrimeGenPerformance::DoReportAction(void) |
|
82 { |
|
83 } |
|
84 |
|
85 void CPrimeGenPerformance::DoCheckResult(TInt) |
|
86 { |
|
87 } |
|
88 |
|
89 void CPrimeGenPerformance::PerformAction(TRequestStatus& aStatus) |
|
90 { |
|
91 __UHEAP_MARK; |
|
92 TRequestStatus* status = &aStatus; |
|
93 TTime start, end; |
|
94 TTimeIntervalSeconds diff(0); |
|
95 const TTimeIntervalSeconds iterationTime(iIterations); |
|
96 TUint iterations=0; |
|
97 |
|
98 RInteger prime; |
|
99 |
|
100 start.UniversalTime(); |
|
101 while (diff < iterationTime) |
|
102 { |
|
103 prime = RInteger::NewPrimeL(iBits, TInteger::ETopBitSet); |
|
104 prime.Close(); |
|
105 iterations++; |
|
106 end.UniversalTime(); |
|
107 end.SecondsFrom(start, diff); |
|
108 } |
|
109 end.UniversalTime(); |
|
110 |
|
111 TTimeIntervalMicroSeconds time = end.MicroSecondsFrom(start); |
|
112 TReal rate = I64REAL(time.Int64()) / iterations; |
|
113 TReal rtime = I64REAL(time.Int64()); |
|
114 HBufC* realbuf = HBufC::NewLC(128); |
|
115 TPtr buf = realbuf->Des(); |
|
116 |
|
117 buf.Format(KPrimeGenFormat, rate, iterations, rtime); |
|
118 iOut.writeString(buf); |
|
119 iConsole.Printf(_L(".")); |
|
120 CleanupStack::PopAndDestroy(realbuf); |
|
121 |
|
122 User::RequestComplete(status, KErrNone); |
|
123 iActionState = CTestAction::EPostrequisite; |
|
124 iResult = ETrue; |
|
125 __UHEAP_MARKEND; |
|
126 } |
|
127 |