os/security/crypto/weakcryptospi/test/tbigint/tprimevectorperformance.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/security/crypto/weakcryptospi/test/tbigint/tprimevectorperformance.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 "tprimevectorperformance.h"
    1.23 +#include "t_input.h"
    1.24 +#include "t_output.h"
    1.25 +#include <bigint.h>
    1.26 +
    1.27 +_LIT(KPrimeVectorFormat, "\tPrime Vector Primality Test Time\t%f");
    1.28 +
    1.29 +CTestAction* CPrimeVectorPerformance::NewL(RFs& aFs, CConsoleBase& aConsole, 
    1.30 +	Output& aOut, const TTestActionSpec& aTestActionSpec)
    1.31 +	{
    1.32 +	CTestAction* self = CPrimeVectorPerformance::NewLC(aFs, aConsole,
    1.33 +		aOut, aTestActionSpec);
    1.34 +	CleanupStack::Pop();
    1.35 +	return self;
    1.36 +	}
    1.37 +
    1.38 +CTestAction* CPrimeVectorPerformance::NewLC(RFs& aFs, CConsoleBase& aConsole, 
    1.39 +	Output& aOut, const TTestActionSpec& aTestActionSpec)
    1.40 +	{
    1.41 +	CPrimeVectorPerformance* self = new(ELeave) CPrimeVectorPerformance(aFs, aConsole, aOut);
    1.42 +	CleanupStack::PushL(self);
    1.43 +	self->ConstructL(aTestActionSpec);
    1.44 +	return self;
    1.45 +	}
    1.46 +
    1.47 +CPrimeVectorPerformance::~CPrimeVectorPerformance()
    1.48 +	{
    1.49 +	delete iBody;
    1.50 +	}
    1.51 +
    1.52 +CPrimeVectorPerformance::CPrimeVectorPerformance(RFs& aFs, CConsoleBase& aConsole, 
    1.53 +	Output& aOut) : CTestAction(aConsole, aOut), iFs(aFs)
    1.54 +	{
    1.55 +	}
    1.56 +
    1.57 +void CPrimeVectorPerformance::ConstructL(const TTestActionSpec& aTestActionSpec)
    1.58 +	{
    1.59 +	CTestAction::ConstructL(aTestActionSpec);
    1.60 +	iBody = HBufC8::NewL(aTestActionSpec.iActionBody.Length());
    1.61 +	iBody->Des().Copy(aTestActionSpec.iActionBody);
    1.62 +
    1.63 +	HBufC8* buf = Input::ParseElementHexL(*iBody, _L8("<prime>"));
    1.64 +	CleanupStack::PushL(buf);
    1.65 +	iPrime = RInteger::NewL(*buf);
    1.66 +	CleanupStack::PopAndDestroy(buf);
    1.67 +	iIterations = Input::ParseIntElement(*iBody, _L8("<iterations>"), _L8("</iterations>"));	
    1.68 +	}
    1.69 +
    1.70 +void CPrimeVectorPerformance::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 CPrimeVectorPerformance::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 CPrimeVectorPerformance::DoReportAction(void)
    1.85 +	{
    1.86 +	}
    1.87 +
    1.88 +void CPrimeVectorPerformance::DoCheckResult(TInt)
    1.89 +	{
    1.90 +	}
    1.91 +
    1.92 +void CPrimeVectorPerformance::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 +	iResult = ETrue;
   1.102 +
   1.103 +	start.UniversalTime();
   1.104 +	while (diff < iterationTime)
   1.105 +		{
   1.106 +		iResult = iPrime.IsPrimeL();
   1.107 +		if(!iResult)
   1.108 +			break;
   1.109 +		iterations++;
   1.110 +		end.UniversalTime();
   1.111 +		end.SecondsFrom(start, diff);
   1.112 +		}
   1.113 +	end.UniversalTime();
   1.114 +
   1.115 +	TTimeIntervalMicroSeconds time = end.MicroSecondsFrom(start);
   1.116 +	TReal rate = I64REAL(time.Int64()) / iterations;
   1.117 +	TReal rtime = I64REAL(time.Int64());
   1.118 +
   1.119 +	HBufC* realbuf = HBufC::NewLC(128);
   1.120 +	TPtr buf = realbuf->Des();
   1.121 +	buf.Format(KPrimeVectorFormat, rate, iterations, rtime);
   1.122 +	iOut.writeString(buf);
   1.123 +	iConsole.Printf(_L("."));
   1.124 +	CleanupStack::PopAndDestroy(realbuf);
   1.125 +
   1.126 +	User::RequestComplete(status, KErrNone);
   1.127 +	iActionState = CTestAction::EPostrequisite;
   1.128 +	__UHEAP_MARKEND;
   1.129 +	}
   1.130 +