1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/security/crypto/weakcryptospi/test/tbigint/tprimegenperformance.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,127 @@
1.4 +/*
1.5 +* Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of the License "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +*
1.19 +*/
1.20 +
1.21 +
1.22 +#include "tprimegenperformance.h"
1.23 +#include "t_input.h"
1.24 +#include "t_output.h"
1.25 +#include <bigint.h>
1.26 +
1.27 +_LIT(KPrimeGenFormat, "\tPrime Generation Time\t%f");
1.28 +
1.29 +const TUint KMaxIterations=100;
1.30 +
1.31 +CTestAction* CPrimeGenPerformance::NewL(RFs& aFs, CConsoleBase& aConsole,
1.32 + Output& aOut, const TTestActionSpec& aTestActionSpec)
1.33 + {
1.34 + CTestAction* self = CPrimeGenPerformance::NewLC(aFs, aConsole,
1.35 + aOut, aTestActionSpec);
1.36 + CleanupStack::Pop();
1.37 + return self;
1.38 + }
1.39 +
1.40 +CTestAction* CPrimeGenPerformance::NewLC(RFs& aFs, CConsoleBase& aConsole,
1.41 + Output& aOut, const TTestActionSpec& aTestActionSpec)
1.42 + {
1.43 + CPrimeGenPerformance* self = new(ELeave) CPrimeGenPerformance(aFs, aConsole, aOut);
1.44 + CleanupStack::PushL(self);
1.45 + self->ConstructL(aTestActionSpec);
1.46 + return self;
1.47 + }
1.48 +
1.49 +CPrimeGenPerformance::~CPrimeGenPerformance()
1.50 + {
1.51 + delete iBody;
1.52 + }
1.53 +
1.54 +CPrimeGenPerformance::CPrimeGenPerformance(RFs& aFs, CConsoleBase& aConsole,
1.55 + Output& aOut) : CTestAction(aConsole, aOut), iFs(aFs)
1.56 + {
1.57 + }
1.58 +
1.59 +void CPrimeGenPerformance::ConstructL(const TTestActionSpec& aTestActionSpec)
1.60 + {
1.61 + CTestAction::ConstructL(aTestActionSpec);
1.62 + iBody = HBufC8::NewL(aTestActionSpec.iActionBody.Length());
1.63 + iBody->Des().Copy(aTestActionSpec.iActionBody);
1.64 +
1.65 + iBits = Input::ParseIntElement(*iBody, _L8("<bits>"), _L8("</bits>"));
1.66 + iIterations = Input::ParseIntElement(*iBody, _L8("<iterations>"), _L8("</iterations>"));
1.67 + __ASSERT_ALWAYS(iIterations < KMaxIterations, User::Panic(_L("Iterations too large"), 1));
1.68 + }
1.69 +
1.70 +void CPrimeGenPerformance::DoPerformPrerequisite(TRequestStatus& aStatus)
1.71 + {
1.72 + TRequestStatus* status = &aStatus;
1.73 + User::RequestComplete(status, KErrNone);
1.74 + iActionState = CTestAction::EAction;
1.75 + }
1.76 +
1.77 +void CPrimeGenPerformance::DoPerformPostrequisite(TRequestStatus& aStatus)
1.78 + {
1.79 + TRequestStatus* status = &aStatus;
1.80 + iFinished = ETrue;
1.81 + User::RequestComplete(status, KErrNone);
1.82 + }
1.83 +
1.84 +void CPrimeGenPerformance::DoReportAction(void)
1.85 + {
1.86 + }
1.87 +
1.88 +void CPrimeGenPerformance::DoCheckResult(TInt)
1.89 + {
1.90 + }
1.91 +
1.92 +void CPrimeGenPerformance::PerformAction(TRequestStatus& aStatus)
1.93 + {
1.94 + __UHEAP_MARK;
1.95 + TRequestStatus* status = &aStatus;
1.96 + TTime start, end;
1.97 + TTimeIntervalSeconds diff(0);
1.98 + const TTimeIntervalSeconds iterationTime(iIterations);
1.99 + TUint iterations=0;
1.100 +
1.101 + RInteger prime;
1.102 +
1.103 + start.UniversalTime();
1.104 + while (diff < iterationTime)
1.105 + {
1.106 + prime = RInteger::NewPrimeL(iBits, TInteger::ETopBitSet);
1.107 + prime.Close();
1.108 + iterations++;
1.109 + end.UniversalTime();
1.110 + end.SecondsFrom(start, diff);
1.111 + }
1.112 + end.UniversalTime();
1.113 +
1.114 + TTimeIntervalMicroSeconds time = end.MicroSecondsFrom(start);
1.115 + TReal rate = I64REAL(time.Int64()) / iterations;
1.116 + TReal rtime = I64REAL(time.Int64());
1.117 + HBufC* realbuf = HBufC::NewLC(128);
1.118 + TPtr buf = realbuf->Des();
1.119 +
1.120 + buf.Format(KPrimeGenFormat, rate, iterations, rtime);
1.121 + iOut.writeString(buf);
1.122 + iConsole.Printf(_L("."));
1.123 + CleanupStack::PopAndDestroy(realbuf);
1.124 +
1.125 + User::RequestComplete(status, KErrNone);
1.126 + iActionState = CTestAction::EPostrequisite;
1.127 + iResult = ETrue;
1.128 + __UHEAP_MARKEND;
1.129 + }
1.130 +