os/textandloc/textrendering/textformatting/test/src/TFormBenchmark.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 /*
     2 * Copyright (c) 2008-2010 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 "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 "TCustomWrap.h"
    20 #include "TGraphicsContext.h"
    21 #include <e32std.h>
    22 #include <e32test.h>
    23 #include <frmtlay.h>
    24 #include <frmtview.h>
    25 #include <txtlaydc.h>
    26 #include <fbs.h>
    27 #include <w32std.h>
    28 #include <txtrich.h>
    29 #include <e32math.h>
    30 #include <f32file.h>
    31 #include <flogger.h>
    32 
    33 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
    34 #include "TAGMA_INTERNAL.H"
    35 #endif
    36 
    37 #include "tformbenchmark.h"
    38 
    39 namespace LocalToTFormBenchmark
    40 {
    41 CTFormBenchmarkStep* TestStep = NULL;
    42 #define TESTPOINT(p) TestStep->testpoint(p,(TText8*)__FILE__,__LINE__)
    43 #define TESTPRINT(p) TestStep->print(p,(TText8*)__FILE__,__LINE__)
    44 }
    45 using namespace LocalToTFormBenchmark;
    46 
    47 RFs fs;
    48 RFile fileTimeStamps;
    49 
    50 _LIT(KFormBenchmark, "TFormBenchmark");
    51 
    52 #if ((defined (__WINS__)) || (defined (__X86GCC__)))
    53 	_LIT(KLogTimeStampsName, "c:\\formtimestamps.csv");
    54 #else
    55 	_LIT(KLogTimeStampsName, "e:\\formtimestamps.csv");
    56 #endif
    57 
    58 _LIT(KEnglish, "Whereas recognition of the inherent dignity and of the equal \
    59 and inalienable rights of all members of the human family is the foundation \
    60 of freedom, justice and peace in the world, ");
    61 const TInt KEnglishRepeats = 119;
    62 _LIT(KArabic, "\x644\x645\x651\x627 \x643\x627\x646 \x627\x644\x627\x639\x62A\
    63 \x631\x627\x641 \x628\x627\x644\x643\x631\x627\x645\x629 \x627\x644\x645\x62A\
    64 \x623\x635\x644\x629 \x641\x64A \x62C\x645\x64A\x639 \x623\x639\x636\x627\
    65 \x621 \x627\x644\x623\x633\x631\x629 \x627\x644\x628\x634\x631\x64A\x629\
    66  \x648\x628\x62D\x642\x648\x642\x647\x645 \x627\x644\x645\x62A\x633\x627\
    67 \x648\x64A\x629 \x627\x644\x62B\x627\x628\x62A\x629 \x647\x648 \x623\x633\
    68 \x627\x633 \x627\x644\x62D\x631\x64A\x629 \x648\x627\x644\x639\x62F\x644\
    69  \x648\x627\x644\x633\x644\x627\x645 \x641\x64A \x627\x644\x639\x627\x644\
    70 \x645. ");
    71 const TInt KArabicRepeats = 156;
    72 _LIT(KJapanese, "\x4EBA\x985E\x793E\x4F1A\x306E\x3059\x3079\x3066\x306E\x69CB\
    73 \x6210\x54E1\x306E\x56FA\x6709\x306E\x5C0A\x53B3\x3068\x5E73\x7B49\x3067\x8B72\
    74 \x308B\x3053\x3068\x306E\x3067\x304D\x306A\x3044\x6A29\x5229\x3068\x3092\
    75 \x627F\x8A8D\x3059\x308B\x3053\x3068\x306F\x3001\x4E16\x754C\x306B\x304A\
    76 \x3051\x308B\x81EA\x7531\x3001\x6B63\x7FA9\x53CA\x3073\x5E73\x548C\x306E\
    77 \x57FA\x790E\x3067\x3042\x308B\x306E\x3067\x3001 ");
    78 const TInt KJapaneseRepeats = 357;
    79 const TInt KDisplayWidth = 100;
    80 const TInt KDisplayHeight = 120;
    81 
    82 const TInt KInsertDisplayWidth = 200;
    83 const TInt KChangedDisplayWidth = 150;
    84 
    85 _LIT(KEnglishToInsert1, "Whereas recognition of the inherent dignity");
    86 _LIT(KEnglishToInsert2, " and of the equal and inalienable rights of all... and so on");
    87 
    88 const TInt KEnglishInsertRepeats = 400;
    89 const TInt KEnglishScrollRepeats = 100;
    90 
    91 const TInt KDeleteTextInterval = 10;//we measure delete text once for each 10 deletes, to make the output smaller
    92 
    93 _LIT8(KDeleteTextFromStart, "Delete text from start\r\n");
    94 _LIT8(KInsertTextAtStart, "Insert text at start\r\n");
    95 _LIT8(KScrollingUp, "Scrolling up\r\n");
    96 _LIT8(KScrollingDown, "Scrolling down\r\n");
    97 
    98 struct TDocInfo
    99 	{
   100 	TDocInfo():iDocLength(0), iDocParaCount(0), iLineCount(0){}
   101 	TInt iDocLength;
   102 	TInt iDocParaCount;
   103 	TInt iLineCount;
   104 	};
   105 
   106 struct TTFTimeStamp
   107 	{
   108 	TInt64 iTime;
   109 	TInt iIteration;
   110 	};
   111 
   112 struct TFormattingObjects
   113 	{
   114 	TRect* iDisplayRect;
   115 	CParaFormatLayer* iParFormat;
   116 	CCharFormatLayer* iCharFormat;
   117 	CRichText* iRichText;
   118 	CTextLayout* iLayout;
   119 	CTestGraphicsDevice* iDevice;
   120 	CTextView* iView;
   121 	};
   122 
   123 /*
   124 Functions for writing benchmarking data to the CSV
   125 */
   126 void WriteSampleDocInfo(TDocInfo aDocInfo, RFile aDest)
   127 	{
   128 	TBuf8<128> buf;
   129 	buf.Format(_L8("Sample text: %d characters: %d paras: %d lines\r\n"), aDocInfo.iDocLength, aDocInfo.iDocParaCount, aDocInfo.iLineCount);
   130 	aDest.Write(buf);
   131 	}
   132 
   133 void WriteTimeStampsL(const TDesC8& aTitle, RArray<TTFTimeStamp>& aTimeStamps)
   134 	{
   135 	fileTimeStamps.Write(aTitle);
   136 	for (TInt i = 0; i < aTimeStamps.Count(); i++)
   137 		{
   138 		TTFTimeStamp timestamp = aTimeStamps[i];
   139 		TBuf8<128> buf;
   140 		buf.Format(_L8("%d, %Ld\r\n"), timestamp.iIteration, timestamp.iTime/1000);
   141 		fileTimeStamps.Write(buf);
   142 		}
   143 	}
   144 
   145 TDocInfo GetSampleDocInfoL(TFormattingObjects& aFormattingObjects)
   146 	{
   147 	TDocInfo docInfo;
   148 	const CTmTextLayout& layout = aFormattingObjects.iView->Layout()->TagmaTextLayout();
   149 	docInfo.iDocLength = layout.Source()->DocumentLength();
   150 	docInfo.iDocParaCount = aFormattingObjects.iRichText->ParagraphCount();
   151 //very peculiar way to count the lines...
   152 	TCursorPosition::TMovementType move = TCursorPosition::EFLineDown;
   153 	while (move == TCursorPosition::EFLineDown)
   154 		{
   155 		aFormattingObjects.iView->MoveCursorL(move, EFalse);
   156 		}
   157 	move = TCursorPosition::EFLineUp;
   158 	while (move == TCursorPosition::EFLineUp)
   159 		{
   160 		docInfo.iLineCount++;
   161 		aFormattingObjects.iView->MoveCursorL(move, EFalse);
   162 		}
   163 	return docInfo;
   164 	}
   165 
   166 /*
   167 Set up the test document
   168 */
   169 void SetTextL(CRichText& aText, const TDesC& aSample, TInt aRepeats, TInt aRepeatsPerPara)
   170 	{
   171 	TInt repeatsInThisPar = 0;
   172 	aText.Reset();
   173 	for (; aRepeats != 0; --aRepeats)
   174 		{
   175 		aText.InsertL(0, aSample);
   176 		repeatsInThisPar ++;
   177 		if (repeatsInThisPar > aRepeatsPerPara)
   178 			{
   179 			TChar paragraphDelimiter(0x2029);
   180 			aText.InsertL(0, paragraphDelimiter);
   181 			repeatsInThisPar = 0;
   182 			}
   183 		}
   184 	}
   185 
   186 _LIT(KOneWord, "blahblahblahblahblahblahblahblah");
   187 
   188 void BigBufLC(RBuf& aBigBuf)
   189 	{
   190 	aBigBuf.CreateL(16384);
   191 	aBigBuf.CleanupClosePushL();
   192 	while(aBigBuf.Length()+KOneWord().Length() < aBigBuf.MaxLength())
   193 		{
   194 		aBigBuf.Append(KOneWord);
   195 		}
   196 	}
   197 
   198 TTimeIntervalMicroSeconds MeasureOpeningL(CTextView& aView)
   199 	{
   200 	TCursorSelection zero(0, 0);
   201 	aView.SetPendingSelection(zero);
   202 	TTime start;
   203 	TTime end;
   204 	start.UniversalTime();
   205 	aView.HandleGlobalChangeL();
   206 	end.UniversalTime();
   207 	return end.MicroSecondsFrom(start);
   208 	}
   209 
   210 TTimeIntervalMicroSeconds MeasureRmsCursorDownL(CTextView& aView)
   211 	{
   212 	TInt mem;
   213 	TInt cells = User::AllocSize(mem);
   214 	TReal totalOfSquares = 0;
   215 	TTime start;
   216 	TTime end;
   217 	TCursorPosition::TMovementType move = TCursorPosition::EFLineDown;
   218 	while (move == TCursorPosition::EFLineDown)
   219 		{
   220 		start.UniversalTime();
   221 		aView.MoveCursorL(move, EFalse);
   222 		end.UniversalTime();
   223 		TReal us = end.MicroSecondsFrom(start).Int64();
   224 		totalOfSquares += us*us;
   225 		}
   226 	TReal rms;
   227 	Math::Sqrt(rms, totalOfSquares);
   228 	cells = User::AllocSize(mem);
   229 	return TTimeIntervalMicroSeconds(static_cast<TInt64>(rms));
   230 	}
   231 
   232 TInt NumberOfLines(CTextLayout& aLayout)
   233 	{
   234 	TTmDocPosSpec dp(aLayout.DocumentLength(), TTmDocPosSpec::ETrailing);
   235 	TTmPosInfo2 posInfo;
   236 	TTmLineInfo lineInfo;
   237 	aLayout.FindDocPos(dp, posInfo, &lineInfo);
   238 	return lineInfo.iLineNumber;
   239 	}
   240 
   241 TTimeIntervalMicroSeconds MeasureFormattingL(CTextView& aView)
   242 	{
   243 	// This looks to me like a defect.
   244 	// We have to set the actual doc pos to prevent a crash, even
   245 	// though we are setting a pending selection.
   246 	// Probably not too serious, though.
   247 	aView.SetDocPosL(0, ETrue);
   248 	TCursorSelection zero(0, 0);
   249 	aView.SetPendingSelection(zero);
   250 	TTime start;
   251 	TTime end;
   252 	start.UniversalTime();
   253 	aView.HandleGlobalChangeL();
   254 	aView.FinishBackgroundFormattingL();
   255 	end.UniversalTime();
   256 	end.UniversalTime();
   257 	return end.MicroSecondsFrom(start);
   258 	}
   259 
   260 void MeasureDeleteTextFromStartL(RArray<TTFTimeStamp>& aTimeStamps,
   261 	TFormattingObjects& aFormattingObjects, TInt64& aSlowest)
   262 	{
   263 	const CTmTextLayout& tmLayout = aFormattingObjects.iLayout->TagmaTextLayout();
   264 	aTimeStamps.Close();
   265 	TTime start;
   266 	TTime end;
   267 	TInt iteration = 0;
   268 	TInt64 total = 0;
   269 
   270 	TInt step = 0;
   271 	while(aFormattingObjects.iRichText->DocumentLength() > 0)
   272 		{
   273 		aFormattingObjects.iRichText->DeleteL(0, 1);
   274 		TCursorSelection cursor(0,0);
   275 		start.UniversalTime();
   276 		aFormattingObjects.iView->HandleInsertDeleteL(cursor, 1, EFalse);
   277 		end.UniversalTime();
   278 
   279 		TInt64 us = end.MicroSecondsFrom(start).Int64();
   280 
   281 		if(us > aSlowest)
   282 			{
   283 			aSlowest = us;
   284 			}
   285 
   286 		total += us;
   287 		step++;
   288 		if(step == KDeleteTextInterval)
   289 			{
   290 			TInt64 average = total/KDeleteTextInterval;
   291 			TTFTimeStamp timestamp;
   292 			timestamp.iTime = average;
   293 			timestamp.iIteration = iteration;
   294 			User::LeaveIfError(aTimeStamps.Append(timestamp));
   295 			iteration++;
   296 			step = 0;
   297 			total = 0;
   298 			}
   299 		}
   300 	}
   301 
   302 void MeasureInsertTextAtStartL(TInt aRepeats, TInt aRepeatsPerPara, RArray<TTFTimeStamp>& aTimeStamps,
   303 	TFormattingObjects& aFormattingObjects, TInt64& aSlowest)
   304 	{
   305 	aTimeStamps.Close();
   306 	TTime start;
   307 	TTime end;
   308 	TInt repeatsInThisPar = 0;
   309 	TViewRectChanges changes;
   310 	aFormattingObjects.iRichText->Reset();
   311 	for (TInt i = 0; i < aRepeats; i++)
   312 		{
   313 		TBuf<128> sample;
   314 		if ((i%2)==0)
   315 			{
   316 			sample = KEnglishToInsert1;
   317 			}
   318 		else
   319 			{
   320 			sample = KEnglishToInsert2;
   321 			}
   322 		aFormattingObjects.iRichText->InsertL(0, sample);
   323 		TCursorSelection cursor(0, sample.Length());
   324 
   325 		start.UniversalTime();
   326 		aFormattingObjects.iLayout->HandleBlockChangeL(cursor, 0, changes, 0);
   327 		end.UniversalTime();
   328 
   329 		TInt64 us = end.MicroSecondsFrom(start).Int64();
   330 		repeatsInThisPar ++;
   331 		TTFTimeStamp timestamp;
   332 		timestamp.iTime = us;
   333 		timestamp.iIteration = i;
   334 		User::LeaveIfError(aTimeStamps.Append(timestamp));
   335 		if(us > aSlowest)
   336 			{
   337 			aSlowest = us;
   338 			}
   339 		if (repeatsInThisPar > aRepeatsPerPara)
   340 			{
   341 			TChar paragraphDelimiter(0x2029);
   342 			aFormattingObjects.iRichText->InsertL(0, paragraphDelimiter);
   343 			repeatsInThisPar = 0;
   344 			}
   345 		}
   346 	}
   347 
   348 void MeasureCursorL(RArray<TTFTimeStamp>& aTimeStamps, TCursorPosition::TMovementType aType,
   349 	TFormattingObjects& aFormattingObjects, TInt64& aSlowest)
   350 	{
   351 	aTimeStamps.Close();
   352 	TTime start;
   353 	TTime end;
   354 	TInt lines = 0;
   355 	TCursorPosition::TMovementType move = aType;
   356 
   357 	while (move == aType)
   358 		{
   359 		lines++;
   360 		start.UniversalTime();
   361 		aFormattingObjects.iView->MoveCursorL(move, EFalse);
   362 		end.UniversalTime();
   363 		TInt64 us = end.MicroSecondsFrom(start).Int64();
   364 		TTFTimeStamp timestamp;
   365 		timestamp.iTime = us;
   366 		timestamp.iIteration = lines;
   367 		User::LeaveIfError(aTimeStamps.Append(timestamp));
   368 		if(us > aSlowest)
   369 			{
   370 			aSlowest = us;
   371 			}
   372 		const CTmTextLayout& tmLayout = aFormattingObjects.iLayout->TagmaTextLayout();
   373 		}
   374 	}
   375 
   376 void CreateFormattingObjectsLC(TFormattingObjects& aFormattingObjects)
   377 	{
   378 	TRect* displayRect = new(ELeave) TRect(0, 0, KDisplayWidth, KDisplayHeight);
   379 	CleanupStack::PushL(displayRect);
   380 	CParaFormatLayer* paraFormat = CParaFormatLayer::NewL();
   381 	CleanupStack::PushL(paraFormat);
   382 	CCharFormatLayer* charFormat = CCharFormatLayer::NewL();
   383 	CleanupStack::PushL(charFormat);
   384 	CRichText* text = CRichText::NewL(paraFormat, charFormat);
   385 	CleanupStack::PushL(text);
   386 	CTextLayout* layout = CTextLayout::NewL(text, displayRect->Width());
   387 	CleanupStack::PushL(layout);
   388 	CTestGraphicsDevice* device = CTestGraphicsDevice::NewL(displayRect->Size(), 0);
   389 	CleanupStack::PushL(device);
   390 	// Prevent the line array from using up the memory
   391 	device->LineArray().Disable();
   392 	CTextView* view = CTextView::NewL(layout, *displayRect,
   393 		device, device, 0, 0, 0);
   394 	CleanupStack::PushL(view);
   395 	// must disable flicker-free redraw or Form will try to use
   396 	// the test font with an off-screen (i.e. real) graphics context,
   397 	// which will panic.
   398 	view->DisableFlickerFreeRedraw();
   399 
   400 	aFormattingObjects.iDisplayRect = displayRect;
   401 	aFormattingObjects.iParFormat = paraFormat;
   402 	aFormattingObjects.iCharFormat = charFormat;
   403 	aFormattingObjects.iRichText = text;
   404 	aFormattingObjects.iLayout = layout;
   405 	aFormattingObjects.iDevice = device;
   406 	aFormattingObjects.iView = view;
   407 	}
   408 
   409 void DestroyFormattingObjects(TFormattingObjects& aFormattingObjects)
   410 	{
   411 	CleanupStack::PopAndDestroy(aFormattingObjects.iView);
   412 	CleanupStack::PopAndDestroy(aFormattingObjects.iDevice);
   413 	CleanupStack::PopAndDestroy(aFormattingObjects.iLayout);
   414 	CleanupStack::PopAndDestroy(aFormattingObjects.iRichText);
   415 	CleanupStack::PopAndDestroy(aFormattingObjects.iCharFormat);
   416 	CleanupStack::PopAndDestroy(aFormattingObjects.iParFormat);
   417 	CleanupStack::PopAndDestroy(aFormattingObjects.iDisplayRect);
   418 	}
   419 
   420 /**
   421 @SYMTestCaseID SYSLIB-FORMA-UT-1897
   422 @SYMTestCaseDesc Benchmarks scrolling text
   423 @SYMTestPriority High
   424 @SYMTestActions creates document and scrolls it
   425 @SYMTestExpectedResults The test must not fail or panic .
   426 @SYMDEF DEF092140, DEF092139
   427 */
   428 void RunScrollingTestL(TInt aRepeats, TInt aRepeatsPerParagraph,
   429 	RArray<TTFTimeStamp>& aTimeStampsDown, RArray<TTFTimeStamp>& aTimeStampsUp,
   430 	TDocInfo& aDocInfo)
   431 	{
   432     TESTPRINT(_L(" @SYMTestCaseID:SYSLIB-FORMA-UT-1897 "));
   433 	TInt docLength = KEnglish().Length() * aRepeats;
   434 	TInt paragraphs = aRepeats/aRepeatsPerParagraph;
   435 
   436 	TFormattingObjects o;
   437 	CreateFormattingObjectsLC(o);
   438 	o.iLayout->SetWrapWidth(KInsertDisplayWidth);
   439 	o.iLayout->SetAmountToFormat(CTextLayout::EFFormatBand);
   440 	SetTextL(*(o.iRichText), KEnglish, aRepeats, aRepeatsPerParagraph);
   441 
   442 	TTimeIntervalMicroSeconds opening = MeasureOpeningL(*(o.iView));
   443 	TInt64 slowest = 0;
   444 	MeasureCursorL(aTimeStampsDown, TCursorPosition::EFLineDown, o, slowest);
   445 	MeasureCursorL(aTimeStampsUp, TCursorPosition::EFLineUp, o, slowest);
   446 
   447 	TBuf<256> buf;
   448 	buf.AppendFormat(_L("PERFORMANCE: Syslibs;Form_Scrolling_Slowest_Doc_with_%d_characters_%d_paragraphs;microseconds: %Ld"), docLength, paragraphs, slowest);
   449 	TESTPRINT(buf);
   450 	
   451 	aDocInfo = GetSampleDocInfoL(o);
   452 	DestroyFormattingObjects(o);
   453 	}
   454 
   455 /**
   456 @SYMTestCaseID SYSLIB-FORMA-UT-1898
   457 @SYMTestCaseDesc Benchmarks inserting, deleting and formatting text
   458 @SYMTestPriority High
   459 @SYMTestActions creates documents in each language and performs edits and reformats
   460 @SYMTestExpectedResults The test must not fail or panic .
   461 @SYMDEF DEF092140, DEF092139
   462 */
   463 void RunEnglishArabicJapaneseBenchmarksL(TFormattingObjects& aFormattingObjects)
   464 	{
   465     TESTPRINT(_L(" @SYMTestCaseID:SYSLIB-FORMA-UT-1898 "));
   466 	SetTextL(*aFormattingObjects.iRichText, KEnglish, KEnglishRepeats, KEnglishRepeats);
   467 	TTimeIntervalMicroSeconds opening = MeasureOpeningL(*aFormattingObjects.iView);
   468 	TTimeIntervalMicroSeconds rmsCursorDown = MeasureRmsCursorDownL(*aFormattingObjects.iView);
   469 	TTimeIntervalMicroSeconds englishFormatting = MeasureFormattingL(*aFormattingObjects.iView);
   470 	TInt englishLines = NumberOfLines(*aFormattingObjects.iLayout);
   471 	SetTextL(*aFormattingObjects.iRichText, KArabic, KArabicRepeats, KArabicRepeats);
   472 	TTimeIntervalMicroSeconds arabicFormatting = MeasureFormattingL(*aFormattingObjects.iView);
   473 	TInt arabicLines = NumberOfLines(*aFormattingObjects.iLayout);
   474 	SetTextL(*aFormattingObjects.iRichText, KJapanese, KJapaneseRepeats, KJapaneseRepeats);
   475 	TTimeIntervalMicroSeconds japaneseFormatting = MeasureFormattingL(*aFormattingObjects.iView);
   476 	TInt japaneseLines = NumberOfLines(*aFormattingObjects.iLayout);
   477 
   478 	// Check that the results are fair
   479 	TInt minLines;
   480 	TInt maxLines;
   481 	if (arabicLines < englishLines)
   482 		{
   483 		minLines = arabicLines;
   484 		maxLines = englishLines;
   485 		}
   486 	else
   487 		{
   488 		minLines = englishLines;
   489 		maxLines = arabicLines;
   490 		}
   491 	if (japaneseLines < minLines)
   492 		minLines = japaneseLines;
   493 	else if (maxLines < japaneseLines)
   494 		maxLines = japaneseLines;
   495 
   496 	//Tests that the number of lines in each test is more or less balanced
   497 	TESTPOINT(maxLines * 100 <= minLines * 105);
   498 
   499 	TBuf<256> buf;
   500 	buf.AppendFormat(_L("PERFORMANCE: Syslibs;Form_OpeningLargeParagraph;microseconds: %d"),
   501 		static_cast<TInt>(opening.Int64()));
   502 	TESTPRINT(buf);
   503 	buf.Zero();
   504 	
   505 	buf.AppendFormat(_L("PERFORMANCE: Syslibs;Form_RmsCursorDown;microseconds: %d"),
   506 		static_cast<TInt>(rmsCursorDown.Int64()));
   507 	TESTPRINT(buf);
   508 	buf.Zero();
   509 	
   510 	buf.AppendFormat(_L("PERFORMANCE: Syslibs;Form_FormattingEnglish;microseconds: %d"),
   511 		static_cast<TInt>(englishFormatting.Int64()));
   512 	TESTPRINT(buf);
   513 	buf.Zero();
   514 	
   515 	buf.AppendFormat(_L("PERFORMANCE: Syslibs;Form_FormattingArabic;microseconds: %d"),
   516 		static_cast<TInt>(arabicFormatting.Int64()));
   517 	TESTPRINT(buf);
   518 	buf.Zero();
   519 	
   520 	buf.AppendFormat(_L("PERFORMANCE: Syslibs;Form_FormattingJapanese;microseconds: %d"),
   521 		static_cast<TInt>(japaneseFormatting.Int64()));
   522 	TESTPRINT(buf);	
   523 	}
   524 
   525 /**
   526 @SYMTestCaseID SYSLIB-FORMA-UT-1896
   527 @SYMTestCaseDesc Benchmarks inserting text from the beginning of a paragraph
   528 @SYMTestPriority High
   529 @SYMTestActions creates a large paragraph containg just one word and inserts text iteratively from
   530 the beginning
   531 @SYMTestExpectedResults The test must not fail or panic .
   532 @SYMDEF DEF092140, DEF092139
   533 */
   534 void RunInsertTextTestsL(TInt aRepeats, TInt aRepeatsPerParagraph,
   535 	RArray<TTFTimeStamp>& aTimeStamps, TDocInfo& aDocInfo)
   536 	{
   537     TESTPRINT(_L(" @SYMTestCaseID:SYSLIB-FORMA-UT-1896 "));
   538 	TFormattingObjects o;
   539 	CreateFormattingObjectsLC(o);
   540 	TInt64 slowest = 0;
   541 	o.iLayout->SetWrapWidth(KInsertDisplayWidth);
   542 	o.iLayout->SetAmountToFormat(CTextLayout::EFFormatBand);
   543 	MeasureInsertTextAtStartL(aRepeats, aRepeatsPerParagraph, aTimeStamps, o, slowest);
   544 	aDocInfo = GetSampleDocInfoL(o);
   545 
   546 	TBuf<256> buf;
   547 	buf.AppendFormat(_L("PERFORMANCE: Syslibs;Form_InsertText_Slowest;microseconds: %Ld"), slowest);
   548 	TESTPRINT(buf);
   549 	
   550 	DestroyFormattingObjects(o);
   551 	}
   552 
   553 /**
   554 @SYMTestCaseID SYSLIB-FORMA-UT-1895
   555 @SYMTestCaseDesc Benchmarks deleting text from the beginning of a paragraph
   556 @SYMTestPriority High
   557 @SYMTestActions creates a large paragraph containg just one word and deletes text iteratively from
   558 the beginning
   559 @SYMTestExpectedResults The test must not fail or panic .
   560 @SYMDEF DEF092140, DEF092139
   561 */
   562 void RunDeleteTextFromStartTest(RArray<TTFTimeStamp>& aTimeStamps, TDocInfo& aDocInfo)
   563 	{
   564     TESTPRINT(_L(" @SYMTestCaseID:SYSLIB-FORMA-UT-1895 "));
   565 	TFormattingObjects o;
   566 	CreateFormattingObjectsLC(o);
   567 	TInt64 slowest = 0;
   568 	o.iLayout->SetWrapWidth(KInsertDisplayWidth);
   569 	o.iLayout->SetAmountToFormat(CTextLayout::EFFormatBand);
   570 	RBuf bigbuf;
   571 	BigBufLC(bigbuf);
   572 	SetTextL(*o.iRichText, bigbuf, 1, 1);
   573 	TTimeIntervalMicroSeconds opening = MeasureOpeningL(*o.iView);
   574 
   575 	MeasureDeleteTextFromStartL(aTimeStamps, o, slowest);
   576 	aDocInfo = GetSampleDocInfoL(o);
   577 
   578 	TBuf<256> buf;	
   579 	buf.AppendFormat(_L("PERFORMANCE: Syslibs;Form_DeleteText_Slowest;microseconds: %Ld"), slowest);
   580 	TESTPRINT(buf);	
   581 
   582 	CleanupStack::PopAndDestroy();//bigbuf
   583 	DestroyFormattingObjects(o);
   584 	}
   585 
   586 void GetFormattingBenchmarkL(TInt aNumberOfIterations, TInt& aNumberOfCharacters, TInt64& aNormalisedBenchmark)
   587 	{
   588     TESTPRINT(_L(" @SYMTestCaseID:SYSLIB-FORMA-UT-1895 "));
   589 	TFormattingObjects o;
   590 	CreateFormattingObjectsLC(o);
   591 	o.iLayout->SetWrapWidth(KInsertDisplayWidth);
   592 	o.iLayout->SetAmountToFormat(CTextLayout::EFFormatBand);
   593 
   594 	SetTextL(*(o.iRichText), KEnglish, aNumberOfIterations, aNumberOfIterations);
   595 
   596 	TTimeIntervalMicroSeconds ignore = MeasureOpeningL(*(o.iView));
   597 	o.iView->SetDocPosL(o.iRichText->DocumentLength());
   598 	//make a global change
   599 	o.iLayout->SetWrapWidth(KChangedDisplayWidth);
   600 	//measure time to reformat for it
   601 	TTime start;
   602 	TTime end;
   603 	start.UniversalTime();
   604 	o.iView->HandleGlobalChangeL();
   605 	end.UniversalTime();
   606 
   607 	TTimeIntervalMicroSeconds formattingTime = end.MicroSecondsFrom(start);
   608 
   609 	aNumberOfCharacters = o.iRichText->DocumentLength();
   610 	aNormalisedBenchmark = formattingTime.Int64()/aNumberOfIterations;
   611 
   612 	DestroyFormattingObjects(o);
   613 	}
   614 
   615 /**
   616 @SYMTestCaseID SYSLIB-FORMA-UT-1894
   617 @SYMTestCaseDesc Benchmarks formatting text
   618 @SYMTestPriority High
   619 @SYMTestActions for a series of documents of increasing size consisting of a single paragraph,
   620 sets the cursor position to the end of the document, makes a global change and formats it.
   621 @SYMTestExpectedResults The test must not fail or panic. The increase in time taken should be
   622 roughly linear with the document size.
   623 @SYMDEF DEF095401
   624 */
   625 void RunFormattingBenchmarksL()
   626 	{
   627     TESTPRINT(_L(" @SYMTestCaseID:SYSLIB-FORMA-UT-1894 "));
   628 	TInt numberOfCharacters = 0;
   629 	TInt numberOfIterations;
   630 	TInt64 normalisedBenchmark = 0;
   631 
   632 	TBuf<256> buf;
   633 	
   634 	numberOfIterations = 1;
   635 	GetFormattingBenchmarkL(numberOfIterations, numberOfCharacters, normalisedBenchmark);
   636 	buf.AppendFormat(_L("PERFORMANCE: Syslibs;Form_FormatText;document contains %d characters: %Ld microseconds per iteration"), numberOfCharacters, normalisedBenchmark);
   637 	TESTPRINT(buf);
   638 	
   639 	buf.Zero();
   640 	numberOfIterations = 5;
   641 	GetFormattingBenchmarkL(numberOfIterations, numberOfCharacters, normalisedBenchmark);
   642 	buf.AppendFormat(_L("PERFORMANCE: Syslibs;Form_FormatText;document contains %d characters: %Ld microseconds per iteration"), numberOfCharacters, normalisedBenchmark);
   643 	TESTPRINT(buf);
   644 	
   645 	buf.Zero();
   646 	numberOfIterations = 10;
   647 	GetFormattingBenchmarkL(numberOfIterations, numberOfCharacters, normalisedBenchmark);
   648 	buf.AppendFormat(_L("PERFORMANCE: Syslibs;Form_FormatText;document contains %d characters: %Ld microseconds per iteration"), numberOfCharacters, normalisedBenchmark);
   649 	TESTPRINT(buf);
   650 
   651 	buf.Zero();
   652 	numberOfIterations = 50;
   653 	GetFormattingBenchmarkL(numberOfIterations, numberOfCharacters, normalisedBenchmark);
   654 	buf.AppendFormat(_L("PERFORMANCE: Syslibs;Form_FormatText;document contains %d characters: %Ld microseconds per iteration"), numberOfCharacters, normalisedBenchmark);
   655 	TESTPRINT(buf);
   656 
   657 	buf.Zero();
   658 	numberOfIterations = 100;
   659 	GetFormattingBenchmarkL(numberOfIterations, numberOfCharacters, normalisedBenchmark);
   660 	buf.AppendFormat(_L("PERFORMANCE: Syslibs;Form_FormatText;document contains %d characters: %Ld microseconds per iteration"), numberOfCharacters, normalisedBenchmark);
   661 	TESTPRINT(buf);
   662 
   663 	buf.Zero();
   664 	numberOfIterations = 250;
   665 	GetFormattingBenchmarkL(numberOfIterations, numberOfCharacters, normalisedBenchmark);
   666 	buf.AppendFormat(_L("PERFORMANCE: Syslibs;Form_FormatText;document contains %d characters: %Ld microseconds per iteration"), numberOfCharacters, normalisedBenchmark);
   667 	TESTPRINT(buf);
   668 
   669 	buf.Zero();
   670 	numberOfIterations = 500;
   671 	GetFormattingBenchmarkL(numberOfIterations, numberOfCharacters, normalisedBenchmark);
   672 	buf.AppendFormat(_L("PERFORMANCE: Syslibs;Form_FormatText;document contains %d characters: %Ld microseconds per iteration"), numberOfCharacters, normalisedBenchmark);
   673 	TESTPRINT(buf);
   674 	
   675 	buf.Zero();
   676 	numberOfIterations = 750;
   677 	GetFormattingBenchmarkL(numberOfIterations, numberOfCharacters, normalisedBenchmark);
   678 	buf.AppendFormat(_L("PERFORMANCE: Syslibs;Form_FormatText;document contains %d characters: %Ld microseconds per iteration"), numberOfCharacters, normalisedBenchmark);
   679 	TESTPRINT(buf);
   680 	
   681 	buf.Zero();
   682 	numberOfIterations = 1000;
   683 	GetFormattingBenchmarkL(numberOfIterations, numberOfCharacters, normalisedBenchmark);
   684 	buf.AppendFormat(_L("PERFORMANCE: Syslibs;Form_FormatText;document contains %d characters: %Ld microseconds per iteration"), numberOfCharacters, normalisedBenchmark);
   685 	TESTPRINT(buf);
   686 	}
   687 
   688 void RunBenchmarksL()
   689 	{
   690 	CActiveScheduler* scheduler = new(ELeave) CActiveScheduler;
   691 	CleanupStack::PushL(scheduler);
   692 	CActiveScheduler::Install(scheduler);
   693 
   694 	RunFormattingBenchmarksL();
   695 
   696 	TDocInfo docInfo;
   697 	RArray<TTFTimeStamp> timestampsDown;
   698 	RArray<TTFTimeStamp> timestampsUp;
   699 	CleanupClosePushL(timestampsDown);
   700 	CleanupClosePushL(timestampsUp);
   701 
   702 	RunDeleteTextFromStartTest(timestampsUp, docInfo);
   703 	WriteSampleDocInfo(docInfo, fileTimeStamps);
   704 	WriteTimeStampsL(KDeleteTextFromStart, timestampsUp);
   705 
   706 	RunInsertTextTestsL(KEnglishInsertRepeats, KEnglishInsertRepeats, timestampsUp, docInfo);
   707 	WriteSampleDocInfo(docInfo, fileTimeStamps);
   708 	WriteTimeStampsL(KInsertTextAtStart, timestampsUp);
   709 
   710 	RunScrollingTestL(KEnglishScrollRepeats, KEnglishScrollRepeats, timestampsDown, timestampsUp, docInfo);
   711 	WriteSampleDocInfo(docInfo, fileTimeStamps);
   712 	WriteTimeStampsL(KScrollingDown, timestampsDown);
   713 	WriteTimeStampsL(KScrollingUp, timestampsUp);
   714 
   715 	RunScrollingTestL(KEnglishScrollRepeats, KEnglishScrollRepeats/2, timestampsDown, timestampsUp, docInfo);
   716 	WriteSampleDocInfo(docInfo, fileTimeStamps);
   717 	WriteTimeStampsL(KScrollingDown, timestampsDown);
   718 	WriteTimeStampsL(KScrollingUp, timestampsUp);
   719 
   720 	RunScrollingTestL(KEnglishScrollRepeats, KEnglishScrollRepeats/10, timestampsDown, timestampsUp, docInfo);
   721 	WriteSampleDocInfo(docInfo, fileTimeStamps);
   722 	WriteTimeStampsL(KScrollingDown, timestampsDown);
   723 	WriteTimeStampsL(KScrollingUp, timestampsUp);
   724 
   725 	TFormattingObjects o;
   726 	CreateFormattingObjectsLC(o);
   727 	RunEnglishArabicJapaneseBenchmarksL(o);
   728 	DestroyFormattingObjects(o);
   729 
   730 	CleanupStack::PopAndDestroy(2);
   731 	CleanupStack::PopAndDestroy(scheduler);
   732 
   733 	}
   734 
   735 TVerdict CTFormBenchmarkStep::doTestStepL()
   736 	{
   737     SetTestStepResult(EPass);
   738     TestStep = this;
   739     
   740     TESTPRINT(KFormBenchmark);
   741     TESTPRINT(_L("Start Font/Bitmap Server"));
   742 
   743 	TInt error = RFbsSession::Connect();
   744 	if (error == KErrNotFound)
   745 		{
   746 		FbsStartup();
   747 		error = RFbsSession::Connect();
   748 		}
   749 	// Tests that FBServ actually starts
   750 	TESTPOINT(error == KErrNone);
   751 	error = fs.Connect();
   752 	TESTPOINT(error == KErrNone);
   753 
   754 	error = fileTimeStamps.Replace(fs, KLogTimeStampsName, EFileWrite);
   755 	
   756 	TBuf<256> buf;
   757 	buf.AppendFormat(_L("> fileTimeStamps.Replace %d"), error);
   758 	TESTPRINT(buf);
   759 	
   760 	TESTPOINT(error == KErrNone);
   761 
   762 	TESTPRINT(_L("Run Benchmarks"));
   763 	TRAP(error, RunBenchmarksL());
   764 	// Tests that the Benchmarks did not run out of memory
   765 	// or otherwise leave
   766 	TESTPOINT(error == KErrNone);
   767 
   768 	fileTimeStamps.Close();
   769 	fs.Close();
   770 	RFbsSession::Disconnect();
   771 
   772 	return TestStepResult();
   773 	}
   774