os/persistentdata/persistentstorage/store/TSTRM/t_storstreamperf.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 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 "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".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 //
    15 
    16 #include <e32test.h>
    17 #include <s32file.h>
    18 #include <s32fileiter.h>
    19 #include <s32mem.h>
    20 #include <hal.h>
    21 
    22 RTest TheTest(_L("t_storstreamperf"));
    23 RFs TheFs;
    24 
    25 TFileName TheTestFile;
    26 TFileName TheTestDir;
    27 TFileName TheTestDictFile;
    28 
    29 const TUid KDictFileUid = {19445};
    30 const TUid KDictStrmUid1 = {19446};
    31 const TUid KDictStrmUid2 = {19447};
    32 
    33 const TInt KBufSize = 30000;
    34 const TInt KIterCnt = 1000;
    35 const TInt KTestDataLen = KBufSize / KIterCnt;
    36 const TUint8 KTestData[KTestDataLen] = 
    37 	{
    38 	'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O',
    39 	'P','Q','R','S','T','U','V','W','X','Y','Z','0','1','2','3'
    40 	};
    41 const TPtrC8  KTestDes(KTestData, KTestDataLen);
    42 
    43 ///////////////////////////////////////////////////////////////////////////////////////
    44 
    45 void DestroyTestEnv()
    46 	{
    47 	(void)TheFs.Delete(TheTestDictFile);
    48 	(void)TheFs.Delete(TheTestFile);
    49 	TheFs.Close();
    50 	}
    51 
    52 ///////////////////////////////////////////////////////////////////////////////////////
    53 //Test macros and functions
    54 void Check(TInt aValue, TInt aLine)
    55 	{
    56 	if(!aValue)
    57 		{
    58 		TheTest.Printf(_L("*** Boolean expression evaluated to false\r\n"));
    59 		DestroyTestEnv();
    60 		TheTest(EFalse, aLine);
    61 		}
    62 	}
    63 void Check(TInt aValue, TInt aExpected, TInt aLine)
    64 	{
    65 	if(aValue != aExpected)
    66 		{
    67 		DestroyTestEnv();
    68 		TheTest.Printf(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue);
    69 		TheTest(EFalse, aLine);
    70 		}
    71 	}
    72 #define TEST(arg) ::Check((arg), __LINE__)
    73 #define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__)
    74 
    75 ///////////////////////////////////////////////////////////////////////////////////////
    76 
    77 void CreateTestEnv()
    78     {
    79 	TInt err = TheFs.Connect();
    80 	TheTest(err == KErrNone);
    81 	
    82 	err = TheFs.MkDirAll(TheTestFile);
    83 	TEST(err == KErrNone || err == KErrAlreadyExists);
    84 	}
    85 
    86 ///////////////////////////////////////////////////////////////////////////////////////
    87 
    88 static TInt TheCounterFreq = -10000000;
    89 const TInt KMicroSecIn1Sec = 1000000;
    90 
    91 TUint32 CalcTickDiff(TUint32 aStartTicks, TUint32 aEndTicks)
    92 	{
    93 	TInt64 diffTicks = (TInt64)aEndTicks - (TInt64)aStartTicks;
    94 	if(diffTicks < 0)
    95 		{
    96 		diffTicks = KMaxTUint32 + diffTicks + 1;
    97 		}
    98 	return (TUint32)diffTicks;
    99 	}
   100 
   101 //Prints aFastCount parameter (converted to us)
   102 void PrintFcDiffAsUs(const TDesC& aFormatStr, TUint32 aFastCount)
   103 	{
   104 	double v = ((double)aFastCount * KMicroSecIn1Sec) / (double)TheCounterFreq;
   105 	TInt v2 = (TInt)v;
   106 	TheTest.Printf(aFormatStr, v2);
   107 	}
   108 
   109 ///////////////////////////////////////////////////////////////////////////////////////
   110 
   111 //Testing RWriteStream performance.
   112 void StreamWriteTestL(RWriteStream& aStream, TUint32& aWriteFc, TUint32& aCommitFc)
   113 	{
   114 	TUint32 fc = User::FastCounter();
   115 	for(TInt i=0;i<KIterCnt;++i)
   116 		{
   117 		aStream.WriteL(KTestDes);
   118 		}
   119 	TUint32 fc2 = User::FastCounter();
   120 	aStream.CommitL();
   121 	TUint32 fc3 = User::FastCounter();
   122 	
   123 	aWriteFc = CalcTickDiff(fc, fc2);
   124 	aCommitFc = CalcTickDiff(fc2, fc3);
   125 	}
   126 
   127 void DoStreamWriteTestL(RWriteStream& aStream)
   128 	{
   129 	TUint32 writeFc = 0, commitFc = 0;
   130 	StreamWriteTestL(aStream, writeFc, commitFc);
   131 	PrintFcDiffAsUs(_L("###     RWriteStream::WriteL(),  Time=%d us\r\n"), writeFc);
   132 	PrintFcDiffAsUs(_L("###     RWriteStream::CommitL(), Time=%d us\r\n"), commitFc);
   133 	}
   134 
   135 //Testing RReadStream performance.
   136 void StreamReadTestL(RReadStream& aStream, TUint32& aReadFc)
   137 	{
   138 	TBuf8<KTestDataLen> buf;
   139 	TUint32 fc = User::FastCounter();
   140 	for(TInt i=0;i<KIterCnt;++i)
   141 		{
   142 		aStream.ReadL(buf);
   143 		}
   144 	TUint32 fc2 = User::FastCounter();
   145 	TEST(buf == KTestDes);
   146 
   147 	aReadFc = CalcTickDiff(fc, fc2);
   148 	}
   149 
   150 void DoStreamReadTestL(RReadStream& aStream)
   151 	{
   152 	TUint32 readFc = 0;
   153 	StreamReadTestL(aStream, readFc);
   154 	PrintFcDiffAsUs(_L("###     RReadStream::ReadL(),   Time=%d us\r\n"), readFc);
   155 	}
   156 
   157 ///////////////////////////////////////////////////////////////////////////////////////
   158 
   159 void GetFastCounterFrequency()
   160 	{
   161 	TEST2(HAL::Get(HAL::EFastCounterFrequency, TheCounterFreq), KErrNone);
   162 	TheTest.Printf(_L("Counter frequency=%d Hz\r\n"), TheCounterFreq);
   163 	}
   164 
   165 /**
   166 @SYMTestCaseID			PDS-STORE-UT-4053
   167 @SYMTestCaseDesc		Test for DEF141471 - STORE, new stream performance tests.
   168 						PREQ2505 Insturmentation of PDS.
   169 						RDictionaryWriteStream & RDictionaryReadStream performance tests.
   170 @SYMTestPriority		High
   171 @SYMTestActions			Test for DEF141471 - STORE, new stream performance tests.
   172 @SYMTestExpectedResults Test must not fail
   173 @SYMDEF					DEF141471
   174 */
   175 void DictionaryStreamTestL()
   176 	{
   177 	(void)TheFs.Delete(TheTestDictFile);
   178 	CDictionaryFileStore* store = CDictionaryFileStore::OpenLC(TheFs, TheTestDictFile, KDictFileUid);
   179 	
   180 	//RDictionaryWriteStream::AssignL()
   181 	RDictionaryWriteStream strm1;
   182 	CleanupClosePushL(strm1);
   183 	TUint32 fc = User::FastCounter();
   184 	strm1.AssignL(*store, KDictStrmUid1);
   185 	TUint32 assignFc = CalcTickDiff(fc, User::FastCounter());
   186 	PrintFcDiffAsUs(_L("###  RDictionaryWriteStream::AssignL(), Time=%d us\r\n"), assignFc);
   187 	DoStreamWriteTestL(strm1);
   188 	CleanupStack::PopAndDestroy(&strm1);
   189 	
   190 	//RDictionaryWriteStream::AssignLC()
   191 	RDictionaryWriteStream strm2;
   192 	fc = User::FastCounter();
   193 	strm2.AssignLC(*store, KDictStrmUid2);
   194 	assignFc = CalcTickDiff(fc, User::FastCounter());
   195 	PrintFcDiffAsUs(_L("###  RDictionaryWriteStream::AssignLC(), Time=%d us\r\n"), assignFc);
   196 	DoStreamWriteTestL(strm2);
   197 	CleanupStack::PopAndDestroy(&strm2);
   198 
   199 	//RDictionaryReadStream::OpenL()
   200 	RDictionaryReadStream strm3;
   201 	CleanupClosePushL(strm3);
   202 	fc = User::FastCounter();
   203 	strm3.OpenL(*store, KDictStrmUid1);
   204 	TUint32 openFc = CalcTickDiff(fc, User::FastCounter());
   205 	PrintFcDiffAsUs(_L("###  RDictionaryReadStream::OpenL(), Time=%d us\r\n"), openFc);
   206 	DoStreamReadTestL(strm3);
   207 	CleanupStack::PopAndDestroy(&strm3);
   208 
   209 	//RDictionaryReadStream::OpenLC()
   210 	RDictionaryReadStream strm4;
   211 	fc = User::FastCounter();
   212 	strm4.OpenLC(*store, KDictStrmUid2);
   213 	openFc = CalcTickDiff(fc, User::FastCounter());
   214 	PrintFcDiffAsUs(_L("###  RDictionaryReadStream::OpenLC(), Time=%d us\r\n"), openFc);
   215 	DoStreamReadTestL(strm4);
   216 	CleanupStack::PopAndDestroy(&strm4);
   217 	
   218 	CleanupStack::PopAndDestroy(store);
   219 	}
   220 
   221 /**
   222 @SYMTestCaseID			PDS-STORE-UT-4054
   223 @SYMTestCaseDesc		Test for DEF141471 - STORE, new stream performance tests.
   224 						PREQ2505 Insturmentation of PDS.
   225 						RFileWriteStream & RFileReadStream performance tests.
   226 @SYMTestPriority		High
   227 @SYMTestActions			Test for DEF141471 - STORE, new stream performance tests.
   228 @SYMTestExpectedResults Test must not fail
   229 @SYMDEF					DEF141471
   230 */
   231 void FileStreamTestL()
   232 	{
   233 	(void)TheFs.Delete(TheTestFile);
   234 	
   235 	//RFileWriteStream::Create()
   236 	RFileWriteStream strm1;
   237 	TUint32 fc = User::FastCounter();
   238 	TInt err = strm1.Create(TheFs, TheTestFile, EFileWrite | EFileRead);
   239 	TUint32 createFc = CalcTickDiff(fc, User::FastCounter());
   240 	TEST2(err, KErrNone);
   241 	PrintFcDiffAsUs(_L("###  RFileWriteStream::Create(), Time=%d us\r\n"), createFc);
   242 	strm1.Close();
   243 	
   244 	//RFileWriteStream::Replace()
   245 	RFileWriteStream strm2;
   246 	fc = User::FastCounter();
   247 	err = strm2.Replace(TheFs, TheTestFile, EFileWrite | EFileRead);
   248 	TUint32 replaceFc = CalcTickDiff(fc, User::FastCounter());
   249 	TEST2(err, KErrNone);
   250 	PrintFcDiffAsUs(_L("###  RFileWriteStream::Replace(), Time=%d us\r\n"), replaceFc);
   251 	strm2.Close();
   252 	
   253 	//RFileWriteStream::Open()
   254 	RFileWriteStream strm3;
   255 	fc = User::FastCounter();
   256 	err = strm3.Open(TheFs, TheTestFile, EFileWrite | EFileRead);
   257 	TUint32 openFc = CalcTickDiff(fc, User::FastCounter());
   258 	TEST2(err, KErrNone);
   259 	PrintFcDiffAsUs(_L("###  RFileWriteStream::Open(), Time=%d us\r\n"), openFc);
   260 	strm3.Close();
   261 	
   262 	//RFileWriteStream::Attach()
   263 	RFile file;
   264 	err = file.Open(TheFs, TheTestFile, EFileWrite | EFileRead);
   265 	TEST2(err, KErrNone);
   266 	RFileWriteStream strm4;
   267 	CleanupClosePushL(strm4);
   268 	fc = User::FastCounter();
   269 	strm4.Attach(file);
   270 	TUint32 attachFc = CalcTickDiff(fc, User::FastCounter());
   271 	PrintFcDiffAsUs(_L("###  RFileWriteStream::Attach(), Time=%d us\r\n"), attachFc);
   272 	DoStreamWriteTestL(strm4);
   273 	CleanupStack::PopAndDestroy(&strm4);
   274 	
   275 	//RFileWriteStream::Temp()
   276 	RFileWriteStream strm5;
   277 	CleanupClosePushL(strm5);
   278 	TFileName fname;
   279 	fc = User::FastCounter();
   280 	err = strm5.Temp(TheFs, TheTestDir, fname, EFileWrite | EFileRead);
   281 	TUint32 tempFc = CalcTickDiff(fc, User::FastCounter());
   282 	TEST2(err, KErrNone);
   283 	PrintFcDiffAsUs(_L("###  RFileWriteStream::Temp(), Time=%d us\r\n"), tempFc);
   284 	DoStreamWriteTestL(strm5);
   285 	CleanupStack::PopAndDestroy(&strm5);
   286 	err = TheFs.Delete(fname);
   287 	TEST2(err, KErrNone);
   288 	
   289 	//RFileReadStream::Open()
   290 	RFileReadStream strm6;
   291 	fc = User::FastCounter();
   292 	err = strm6.Open(TheFs, TheTestFile, EFileRead);
   293 	openFc = CalcTickDiff(fc, User::FastCounter());
   294 	PrintFcDiffAsUs(_L("###  RFileReadStream::Open(), Time=%d us\r\n"), openFc);
   295 	strm6.Close();
   296 
   297 	//RFileReadStream::Attach()
   298 	err = file.Open(TheFs, TheTestFile, EFileRead);
   299 	TEST2(err, KErrNone);
   300 	RFileReadStream strm7;
   301 	fc = User::FastCounter();
   302 	strm7.Attach(file);
   303 	attachFc = CalcTickDiff(fc, User::FastCounter());
   304 	PrintFcDiffAsUs(_L("###  RFileReadStream::Attach(), Time=%d us\r\n"), attachFc);
   305 	strm7.Close();
   306 
   307 	//RFileReadStream::RFileReadStream(RFile&)
   308 	err = file.Open(TheFs, TheTestFile, EFileRead);
   309 	TEST2(err, KErrNone);
   310 	fc = User::FastCounter();
   311 	RFileReadStream strm8(file);
   312 	TUint32 constrFc = CalcTickDiff(fc, User::FastCounter());
   313 	CleanupClosePushL(strm8);
   314 	PrintFcDiffAsUs(_L("###  RFileReadStream::RFileReadStream(RFile&), Time=%d us\r\n"), constrFc);
   315 	DoStreamReadTestL(strm8);
   316 	CleanupStack::PopAndDestroy(&strm8);
   317 	}
   318 
   319 /**
   320 @SYMTestCaseID			PDS-STORE-UT-4055
   321 @SYMTestCaseDesc		Test for DEF141471 - STORE, new stream performance tests.
   322 						PREQ2505 Insturmentation of PDS.
   323 						RMemWriteStream & RMemReadStream performance tests.
   324 @SYMTestPriority		High
   325 @SYMTestActions			Test for DEF141471 - STORE, new stream performance tests.
   326 @SYMTestExpectedResults Test must not fail
   327 @SYMDEF					DEF141471
   328 */
   329 void MemStreamTestL()
   330 	{
   331 	HBufC8* buf = HBufC8::NewLC(KBufSize);
   332 	TPtr8 bufPtr = buf->Des();
   333 
   334 	//RMemWriteStream::Open()	
   335 	RMemWriteStream strm1;
   336 	TUint32 fc = User::FastCounter();
   337 	strm1.Open(const_cast <TUint8*> (bufPtr.Ptr()), KBufSize);
   338 	TUint32 openFc = CalcTickDiff(fc, User::FastCounter());
   339 	PrintFcDiffAsUs(_L("###  RMemWriteStream::Open(), Time=%d us\r\n"), openFc);
   340 	strm1.Close();
   341 	
   342 	//RMemWriteStream::RMemWriteStream(TAny*,...)	
   343 	fc = User::FastCounter();
   344 	RMemWriteStream strm2(const_cast <TUint8*> (bufPtr.Ptr()), KBufSize);
   345 	TUint32 constrFc = CalcTickDiff(fc, User::FastCounter());
   346 	PrintFcDiffAsUs(_L("###  RMemWriteStream::RMemWriteStream(TAny*,...), Time=%d us\r\n"), constrFc);
   347 	CleanupClosePushL(strm2);
   348 	DoStreamWriteTestL(strm2);
   349 	CleanupStack::PopAndDestroy(&strm2);
   350 	
   351 	//RMemReadStream::Open()
   352 	RMemReadStream strm3;
   353 	fc = User::FastCounter();
   354 	strm3.Open(bufPtr.Ptr(), KBufSize);
   355 	openFc = CalcTickDiff(fc, User::FastCounter());
   356 	PrintFcDiffAsUs(_L("###  RMemReadStream::Open(), Time=%d us\r\n"), openFc);
   357 	strm3.Close();
   358 
   359 	//RMemReadStream::RMemReadStream(TAny*,...)	
   360 	fc = User::FastCounter();
   361 	RMemReadStream strm4(bufPtr.Ptr(), KBufSize);
   362 	constrFc = CalcTickDiff(fc, User::FastCounter());
   363 	PrintFcDiffAsUs(_L("###  RMemReadStream::RMemReadStream(TAny*,...), Time=%d us\r\n"), openFc);
   364 	CleanupClosePushL(strm4);
   365 	DoStreamReadTestL(strm4);
   366 	CleanupStack::PopAndDestroy(&strm4);
   367 	
   368 	CleanupStack::PopAndDestroy(buf);
   369 	}
   370 
   371 /**
   372 @SYMTestCaseID			PDS-STORE-UT-4056
   373 @SYMTestCaseDesc		Test for DEF141471 - STORE, new stream performance tests.
   374 						PREQ2505 Insturmentation of PDS.
   375 						RBufWriteStream & RBufReadStream performance tests.
   376 @SYMTestPriority		High
   377 @SYMTestActions			Test for DEF141471 - STORE, new stream performance tests.
   378 @SYMTestExpectedResults Test must not fail
   379 @SYMDEF					DEF141471
   380 */
   381 void BufStreamTestL()
   382 	{
   383 	CBufFlat* bufFlat = CBufFlat::NewL(KTestDataLen);
   384 	CleanupStack::PushL(bufFlat);
   385 	
   386 	//RBufWriteStream::Open()
   387 	RBufWriteStream strm1;
   388 	CleanupClosePushL(strm1);
   389 	TUint32 fc = User::FastCounter();
   390 	strm1.Open(*bufFlat);
   391 	TUint32 openFc = CalcTickDiff(fc, User::FastCounter());
   392 	PrintFcDiffAsUs(_L("###  RBufWriteStream::Open(), Time=%d us\r\n"), openFc);
   393 	DoStreamWriteTestL(strm1);
   394 	CleanupStack::PopAndDestroy(&strm1);
   395 	TheTest.Printf(_L("       Buffer size=%d\r\n"), bufFlat->Size());
   396 
   397 	//RBufWriteStream::Append()
   398 	RBufWriteStream strm2;
   399 	CleanupClosePushL(strm2);
   400 	fc = User::FastCounter();
   401 	strm2.Append(*bufFlat);
   402 	TUint32 appendFc = CalcTickDiff(fc, User::FastCounter());
   403 	PrintFcDiffAsUs(_L("###  RBufWriteStream::Append(), Time=%d us\r\n"), appendFc);
   404 	DoStreamWriteTestL(strm2);
   405 	CleanupStack::PopAndDestroy(&strm2);
   406 	TheTest.Printf(_L("       Buffer size=%d\r\n"), bufFlat->Size());
   407 	
   408 	//RBufWriteStream::Insert()
   409 	RBufWriteStream strm3;
   410 	CleanupClosePushL(strm3);
   411 	fc = User::FastCounter();
   412 	strm3.Insert(*bufFlat, KBufSize);
   413 	TUint32 insertFc = CalcTickDiff(fc, User::FastCounter());
   414 	PrintFcDiffAsUs(_L("###  RBufWriteStream::Insert(), Time=%d us\r\n"), insertFc);
   415 	DoStreamWriteTestL(strm3);
   416 	CleanupStack::PopAndDestroy(&strm3);
   417 	TheTest.Printf(_L("       Buffer size=%d\r\n"), bufFlat->Size());
   418 	
   419 	//RBufWriteStream::Truncate()
   420 	RBufWriteStream strm4;
   421 	CleanupClosePushL(strm4);
   422 	fc = User::FastCounter();
   423 	strm4.Truncate(*bufFlat);
   424 	TUint32 truncateFc = CalcTickDiff(fc, User::FastCounter());
   425 	PrintFcDiffAsUs(_L("###  RBufWriteStream::Truncate(), Time=%d us\r\n"), truncateFc);
   426 	DoStreamWriteTestL(strm4);
   427 	CleanupStack::PopAndDestroy(&strm4);
   428 	TheTest.Printf(_L("       Buffer size=%d\r\n"), bufFlat->Size());
   429 	
   430 	RBufReadStream strm5;
   431 	CleanupClosePushL(strm5);
   432 	fc = User::FastCounter();
   433 	strm5.Open(*bufFlat);
   434 	openFc = CalcTickDiff(fc, User::FastCounter());
   435 	PrintFcDiffAsUs(_L("###  RBufReadStream::Open(), Time=%d us\r\n"), openFc);
   436 	DoStreamReadTestL(strm5);
   437 	CleanupStack::PopAndDestroy(&strm5);
   438 	
   439 	CleanupStack::PopAndDestroy(bufFlat);
   440 	}
   441 
   442 /** 
   443 @SYMTestCaseID			PDS-STORE-UT-4057
   444 @SYMTestCaseDesc		Test for DEF141471 - STORE, new stream performance tests.
   445 						PREQ2505 Insturmentation of PDS.
   446 						RPermanentFileStoreIter performance tests.
   447 @SYMTestPriority		High
   448 @SYMTestActions			Test for DEF141471 - STORE, new stream performance tests.
   449 @SYMTestExpectedResults Test must not fail
   450 @SYMDEF					DEF141471
   451 */
   452 void PermanentFileStoreIterTestL()
   453 	{
   454 	(void)TheFs.Delete(TheTestFile);
   455 
   456 	CPermanentFileStore* store = CPermanentFileStore::ReplaceLC(TheFs, TheTestFile, EFileWrite | EFileRead);
   457 	store->SetTypeL(KPermanentFileStoreLayoutUid);
   458 	
   459 	//Create streams
   460 	const TInt KStreamCnt = 10;
   461 	TStreamId streamId[KStreamCnt] = {0}; 	
   462 	TheTest.Printf(_L("###  CPermanentFileStore, create %d streams\r\n"), KStreamCnt);
   463 	for(TInt i=0;i<KStreamCnt;i++)
   464 		{
   465 		RStoreWriteStream out;
   466 		streamId[i] = out.CreateLC(*store);
   467 		TheTest.Printf(_L("###    Stream##%02d, streamId=%08X\r\n"), i + 1, streamId[i].Value());
   468 		DoStreamWriteTestL(out);
   469 		CleanupStack::PopAndDestroy(&out);
   470 		}
   471 	TUint32 fc = User::FastCounter();
   472 	store->CommitL();
   473 	TUint32 commitFc = CalcTickDiff(fc, User::FastCounter());
   474 	CleanupStack::PopAndDestroy(store);
   475 	PrintFcDiffAsUs(_L("###  RPermanentFileStoreIter::CommitL(), Time=%d us\r\n"), commitFc);
   476 	
   477 	//RPermanentFileStoreIter::ResetL()
   478 	store = CPermanentFileStore::OpenLC(TheFs, TheTestFile, EFileWrite | EFileRead);
   479 	RPermanentFileStoreIter it1;
   480 	CleanupClosePushL(it1);
   481 	fc = User::FastCounter();
   482 	it1.ResetL(*store);
   483 	TUint32 resetFc = CalcTickDiff(fc, User::FastCounter());
   484 	CleanupStack::PopAndDestroy(&it1);
   485 	CleanupStack::PopAndDestroy(store);
   486 	PrintFcDiffAsUs(_L("###  RPermanentFileStoreIter::ResetL(), Time=%d us\r\n"), resetFc);
   487 
   488 	//RPermanentFileStoreIter::ResetLC()
   489 	store = CPermanentFileStore::OpenLC(TheFs, TheTestFile, EFileWrite | EFileRead);
   490 	RPermanentFileStoreIter it2;
   491 	fc = User::FastCounter();
   492 	it2.ResetLC(*store);
   493 	resetFc = CalcTickDiff(fc, User::FastCounter());
   494 	CleanupStack::PopAndDestroy(&it2);
   495 	CleanupStack::PopAndDestroy(store);
   496 	PrintFcDiffAsUs(_L("###  RPermanentFileStoreIter::ResetLC(), Time=%d us\r\n"), resetFc);
   497 
   498 	//RPermanentFileStoreIter - construction & destruction
   499 	store = CPermanentFileStore::OpenLC(TheFs, TheTestFile, EFileWrite | EFileRead);
   500 	fc = User::FastCounter();
   501 	RPermanentFileStoreIter it3;
   502 	CleanupClosePushL(it3);
   503 	it3.ResetL(*store);
   504 	CleanupStack::PopAndDestroy(&it3);
   505 	TUint32 fc2 = CalcTickDiff(fc, User::FastCounter());
   506 	CleanupStack::PopAndDestroy(store);
   507 	PrintFcDiffAsUs(_L("###  RPermanentFileStoreIter - construction & destruction, Time=%d us\r\n"), fc2);
   508 
   509 	//RPermanentFileStoreIter::NextL()
   510 	store = CPermanentFileStore::OpenLC(TheFs, TheTestFile, EFileWrite | EFileRead);
   511 	RPermanentFileStoreIter it4;
   512 	it4.ResetLC(*store);
   513 	TStreamId id(KNullStreamIdValue);
   514 	TInt cnt = 0;
   515 	fc = User::FastCounter();
   516 	while((id = it4.NextL()) != KNullStreamIdValue)
   517 		{
   518 		++cnt;
   519 		}
   520 	TUint32 nextFc = CalcTickDiff(fc, User::FastCounter());
   521 	CleanupStack::PopAndDestroy(&it4);
   522 	CleanupStack::PopAndDestroy(store);
   523 	TEST2(cnt, KStreamCnt);
   524 	PrintFcDiffAsUs(_L("###  RPermanentFileStoreIter::NextL(), Time=%d us\r\n"), nextFc);
   525 	}
   526 
   527 /**
   528 @SYMTestCaseID          SYSLIB-STORE-CT-4007
   529 @SYMTestCaseDesc	    CDirectFileStore::ReplaceLC() and SetTypeL() performance test
   530 @SYMTestPriority 	    High
   531 @SYMTestActions  	    Creates new CDirectFileStore object and measures the time of the operation. 
   532 @SYMTestExpectedResults Tests set type time 
   533 @SYMCR                  ATHE-7CQP8H
   534 */
   535 void CreateDirectFileStoreTestL()
   536 	{	
   537 	(void)TheFs.Delete(TheTestFile);
   538 	    
   539     TUint32 fc = User::FastCounter();
   540 	CFileStore* store = CDirectFileStore::ReplaceLC(TheFs, TheTestFile, EFileWrite | EFileRead);
   541 	// Must say what kind of file store
   542 	// SetTypeL() calls RFileBuf::EndL() which used to call RFile::Size()
   543 	store->SetTypeL(KDirectFileStoreLayoutUid);
   544 	TUint32 time = CalcTickDiff(fc, User::FastCounter());
   545 	CleanupStack::PopAndDestroy(store);
   546 	PrintFcDiffAsUs(_L("###  CDirectFileStore::ReplaceLC() & SetTypeL(), Time=%d us\r\n"), time);
   547 	}
   548 
   549 /**
   550 @SYMTestCaseID          SYSLIB-STORE-CT-4008
   551 @SYMTestCaseDesc	    Tests performance when calling CFileStore::Destruct()
   552 @SYMTestPriority 	    High
   553 @SYMTestActions  	    Creates and deletes a File Store 
   554 @SYMTestExpectedResults Tests deletion time 
   555 @SYMCR                  ATHE-7CQP8H
   556 */
   557 void DirectFileStoreTestL()
   558 	{	
   559 	(void)TheFs.Delete(TheTestFile);
   560 	
   561     TUint32 fc = User::FastCounter();
   562 	CFileStore* store = CDirectFileStore::ReplaceLC(TheFs, TheTestFile, EFileWrite | EFileRead);
   563 	//then delete it. this calls CFileStore::Destruct(), which used to call Revert()
   564 	CleanupStack::PopAndDestroy(store);
   565 	TUint32 time = CalcTickDiff(fc, User::FastCounter());
   566 	PrintFcDiffAsUs(_L("###  CDirectFileStore construction & destruction, Time=%d us\r\n"), time);
   567 	}
   568 
   569 void DoTestsL()
   570 	{
   571 	TheTest.Start(_L("Get fast counter frequency"));
   572 	GetFastCounterFrequency();
   573 	
   574 	TheTest.Next(_L(" @SYMTestCaseID:PDS-STORE-UT-4053 RDictionaryWriteStream & RDictionaryReadStream - performance test"));
   575 	DictionaryStreamTestL();
   576 	
   577 	TheTest.Next(_L(" @SYMTestCaseID:PDS-STORE-UT-4054 RFileWriteStream & RFileReadStream - performance test"));
   578 	FileStreamTestL();
   579 
   580 	TheTest.Next(_L(" @SYMTestCaseID:PDS-STORE-UT-4055 RMemWriteStream & RMemReadStream - performance test"));
   581 	MemStreamTestL();
   582 
   583 	TheTest.Next(_L(" @SYMTestCaseID:PDS-STORE-UT-4056 RBufWriteStream & RBufReadStream - performance test"));
   584 	BufStreamTestL();
   585 
   586 	TheTest.Next(_L(" @SYMTestCaseID:PDS-STORE-UT-4057 RPermanentFileStoreIter - performance test"));
   587 	PermanentFileStoreIterTestL();
   588 	
   589 	TheTest.Next(_L(" @SYMTestCaseID SYSLIB-STORE-CT-4007 CDirectFileStore::ReplaceLC() & SetTypeL() performance test"));
   590 	CreateDirectFileStoreTestL();
   591 	
   592 	TheTest.Next(_L(" @SYMTestCaseID SYSLIB-STORE-CT-4008 CDirectFileStore construction & destruction performance test"));
   593 	DirectFileStoreTestL();
   594 	}
   595 
   596 //Usage: "t_streamperf [<drive letter>:]]"
   597 TInt E32Main()
   598 	{
   599 	TheTest.Title();
   600 
   601 	CTrapCleanup* tc = CTrapCleanup::New();
   602 	TheTest(tc != NULL);
   603 		
   604 	TBuf<256> cmdline;
   605 	User::CommandLine(cmdline);
   606 
   607 	TParse parse;
   608 
   609 	_LIT(KTestFile, "c:\\stor-tst\\t_streamperf.dat");
   610 	parse.Set(cmdline, &KTestFile, 0);
   611 	TheTestFile.Copy(parse.FullName());
   612 
   613 	_LIT(KTestPath, "c:\\stor-tst\\");
   614 	parse.Set(cmdline, &KTestPath, 0);
   615 	TheTestDir.Copy(parse.FullName());
   616 	
   617 	_LIT(KDictFile, "c:\\stor-tst\\dicfile.ini");
   618 	parse.Set(cmdline, &KDictFile, 0);
   619 	TheTestDictFile.Copy(parse.FullName());
   620 
   621 	__UHEAP_MARK;
   622 
   623 	CreateTestEnv();
   624 	TRAPD(err, DoTestsL());
   625 	TEST2(err, KErrNone);
   626 	DestroyTestEnv();
   627 
   628 	__UHEAP_MARKEND;
   629 
   630 	TheTest.End();
   631 	TheTest.Close();
   632 
   633 	delete tc;
   634 
   635 	User::Heap().Check();
   636 	return KErrNone;
   637 	}