os/textandloc/textrendering/textformatting/test/src/TFormBenchmark.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/textandloc/textrendering/textformatting/test/src/TFormBenchmark.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,774 @@
     1.4 +/*
     1.5 +* Copyright (c) 2008-2010 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 "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 "TCustomWrap.h"
    1.23 +#include "TGraphicsContext.h"
    1.24 +#include <e32std.h>
    1.25 +#include <e32test.h>
    1.26 +#include <frmtlay.h>
    1.27 +#include <frmtview.h>
    1.28 +#include <txtlaydc.h>
    1.29 +#include <fbs.h>
    1.30 +#include <w32std.h>
    1.31 +#include <txtrich.h>
    1.32 +#include <e32math.h>
    1.33 +#include <f32file.h>
    1.34 +#include <flogger.h>
    1.35 +
    1.36 +#ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
    1.37 +#include "TAGMA_INTERNAL.H"
    1.38 +#endif
    1.39 +
    1.40 +#include "tformbenchmark.h"
    1.41 +
    1.42 +namespace LocalToTFormBenchmark
    1.43 +{
    1.44 +CTFormBenchmarkStep* TestStep = NULL;
    1.45 +#define TESTPOINT(p) TestStep->testpoint(p,(TText8*)__FILE__,__LINE__)
    1.46 +#define TESTPRINT(p) TestStep->print(p,(TText8*)__FILE__,__LINE__)
    1.47 +}
    1.48 +using namespace LocalToTFormBenchmark;
    1.49 +
    1.50 +RFs fs;
    1.51 +RFile fileTimeStamps;
    1.52 +
    1.53 +_LIT(KFormBenchmark, "TFormBenchmark");
    1.54 +
    1.55 +#if ((defined (__WINS__)) || (defined (__X86GCC__)))
    1.56 +	_LIT(KLogTimeStampsName, "c:\\formtimestamps.csv");
    1.57 +#else
    1.58 +	_LIT(KLogTimeStampsName, "e:\\formtimestamps.csv");
    1.59 +#endif
    1.60 +
    1.61 +_LIT(KEnglish, "Whereas recognition of the inherent dignity and of the equal \
    1.62 +and inalienable rights of all members of the human family is the foundation \
    1.63 +of freedom, justice and peace in the world, ");
    1.64 +const TInt KEnglishRepeats = 119;
    1.65 +_LIT(KArabic, "\x644\x645\x651\x627 \x643\x627\x646 \x627\x644\x627\x639\x62A\
    1.66 +\x631\x627\x641 \x628\x627\x644\x643\x631\x627\x645\x629 \x627\x644\x645\x62A\
    1.67 +\x623\x635\x644\x629 \x641\x64A \x62C\x645\x64A\x639 \x623\x639\x636\x627\
    1.68 +\x621 \x627\x644\x623\x633\x631\x629 \x627\x644\x628\x634\x631\x64A\x629\
    1.69 + \x648\x628\x62D\x642\x648\x642\x647\x645 \x627\x644\x645\x62A\x633\x627\
    1.70 +\x648\x64A\x629 \x627\x644\x62B\x627\x628\x62A\x629 \x647\x648 \x623\x633\
    1.71 +\x627\x633 \x627\x644\x62D\x631\x64A\x629 \x648\x627\x644\x639\x62F\x644\
    1.72 + \x648\x627\x644\x633\x644\x627\x645 \x641\x64A \x627\x644\x639\x627\x644\
    1.73 +\x645. ");
    1.74 +const TInt KArabicRepeats = 156;
    1.75 +_LIT(KJapanese, "\x4EBA\x985E\x793E\x4F1A\x306E\x3059\x3079\x3066\x306E\x69CB\
    1.76 +\x6210\x54E1\x306E\x56FA\x6709\x306E\x5C0A\x53B3\x3068\x5E73\x7B49\x3067\x8B72\
    1.77 +\x308B\x3053\x3068\x306E\x3067\x304D\x306A\x3044\x6A29\x5229\x3068\x3092\
    1.78 +\x627F\x8A8D\x3059\x308B\x3053\x3068\x306F\x3001\x4E16\x754C\x306B\x304A\
    1.79 +\x3051\x308B\x81EA\x7531\x3001\x6B63\x7FA9\x53CA\x3073\x5E73\x548C\x306E\
    1.80 +\x57FA\x790E\x3067\x3042\x308B\x306E\x3067\x3001 ");
    1.81 +const TInt KJapaneseRepeats = 357;
    1.82 +const TInt KDisplayWidth = 100;
    1.83 +const TInt KDisplayHeight = 120;
    1.84 +
    1.85 +const TInt KInsertDisplayWidth = 200;
    1.86 +const TInt KChangedDisplayWidth = 150;
    1.87 +
    1.88 +_LIT(KEnglishToInsert1, "Whereas recognition of the inherent dignity");
    1.89 +_LIT(KEnglishToInsert2, " and of the equal and inalienable rights of all... and so on");
    1.90 +
    1.91 +const TInt KEnglishInsertRepeats = 400;
    1.92 +const TInt KEnglishScrollRepeats = 100;
    1.93 +
    1.94 +const TInt KDeleteTextInterval = 10;//we measure delete text once for each 10 deletes, to make the output smaller
    1.95 +
    1.96 +_LIT8(KDeleteTextFromStart, "Delete text from start\r\n");
    1.97 +_LIT8(KInsertTextAtStart, "Insert text at start\r\n");
    1.98 +_LIT8(KScrollingUp, "Scrolling up\r\n");
    1.99 +_LIT8(KScrollingDown, "Scrolling down\r\n");
   1.100 +
   1.101 +struct TDocInfo
   1.102 +	{
   1.103 +	TDocInfo():iDocLength(0), iDocParaCount(0), iLineCount(0){}
   1.104 +	TInt iDocLength;
   1.105 +	TInt iDocParaCount;
   1.106 +	TInt iLineCount;
   1.107 +	};
   1.108 +
   1.109 +struct TTFTimeStamp
   1.110 +	{
   1.111 +	TInt64 iTime;
   1.112 +	TInt iIteration;
   1.113 +	};
   1.114 +
   1.115 +struct TFormattingObjects
   1.116 +	{
   1.117 +	TRect* iDisplayRect;
   1.118 +	CParaFormatLayer* iParFormat;
   1.119 +	CCharFormatLayer* iCharFormat;
   1.120 +	CRichText* iRichText;
   1.121 +	CTextLayout* iLayout;
   1.122 +	CTestGraphicsDevice* iDevice;
   1.123 +	CTextView* iView;
   1.124 +	};
   1.125 +
   1.126 +/*
   1.127 +Functions for writing benchmarking data to the CSV
   1.128 +*/
   1.129 +void WriteSampleDocInfo(TDocInfo aDocInfo, RFile aDest)
   1.130 +	{
   1.131 +	TBuf8<128> buf;
   1.132 +	buf.Format(_L8("Sample text: %d characters: %d paras: %d lines\r\n"), aDocInfo.iDocLength, aDocInfo.iDocParaCount, aDocInfo.iLineCount);
   1.133 +	aDest.Write(buf);
   1.134 +	}
   1.135 +
   1.136 +void WriteTimeStampsL(const TDesC8& aTitle, RArray<TTFTimeStamp>& aTimeStamps)
   1.137 +	{
   1.138 +	fileTimeStamps.Write(aTitle);
   1.139 +	for (TInt i = 0; i < aTimeStamps.Count(); i++)
   1.140 +		{
   1.141 +		TTFTimeStamp timestamp = aTimeStamps[i];
   1.142 +		TBuf8<128> buf;
   1.143 +		buf.Format(_L8("%d, %Ld\r\n"), timestamp.iIteration, timestamp.iTime/1000);
   1.144 +		fileTimeStamps.Write(buf);
   1.145 +		}
   1.146 +	}
   1.147 +
   1.148 +TDocInfo GetSampleDocInfoL(TFormattingObjects& aFormattingObjects)
   1.149 +	{
   1.150 +	TDocInfo docInfo;
   1.151 +	const CTmTextLayout& layout = aFormattingObjects.iView->Layout()->TagmaTextLayout();
   1.152 +	docInfo.iDocLength = layout.Source()->DocumentLength();
   1.153 +	docInfo.iDocParaCount = aFormattingObjects.iRichText->ParagraphCount();
   1.154 +//very peculiar way to count the lines...
   1.155 +	TCursorPosition::TMovementType move = TCursorPosition::EFLineDown;
   1.156 +	while (move == TCursorPosition::EFLineDown)
   1.157 +		{
   1.158 +		aFormattingObjects.iView->MoveCursorL(move, EFalse);
   1.159 +		}
   1.160 +	move = TCursorPosition::EFLineUp;
   1.161 +	while (move == TCursorPosition::EFLineUp)
   1.162 +		{
   1.163 +		docInfo.iLineCount++;
   1.164 +		aFormattingObjects.iView->MoveCursorL(move, EFalse);
   1.165 +		}
   1.166 +	return docInfo;
   1.167 +	}
   1.168 +
   1.169 +/*
   1.170 +Set up the test document
   1.171 +*/
   1.172 +void SetTextL(CRichText& aText, const TDesC& aSample, TInt aRepeats, TInt aRepeatsPerPara)
   1.173 +	{
   1.174 +	TInt repeatsInThisPar = 0;
   1.175 +	aText.Reset();
   1.176 +	for (; aRepeats != 0; --aRepeats)
   1.177 +		{
   1.178 +		aText.InsertL(0, aSample);
   1.179 +		repeatsInThisPar ++;
   1.180 +		if (repeatsInThisPar > aRepeatsPerPara)
   1.181 +			{
   1.182 +			TChar paragraphDelimiter(0x2029);
   1.183 +			aText.InsertL(0, paragraphDelimiter);
   1.184 +			repeatsInThisPar = 0;
   1.185 +			}
   1.186 +		}
   1.187 +	}
   1.188 +
   1.189 +_LIT(KOneWord, "blahblahblahblahblahblahblahblah");
   1.190 +
   1.191 +void BigBufLC(RBuf& aBigBuf)
   1.192 +	{
   1.193 +	aBigBuf.CreateL(16384);
   1.194 +	aBigBuf.CleanupClosePushL();
   1.195 +	while(aBigBuf.Length()+KOneWord().Length() < aBigBuf.MaxLength())
   1.196 +		{
   1.197 +		aBigBuf.Append(KOneWord);
   1.198 +		}
   1.199 +	}
   1.200 +
   1.201 +TTimeIntervalMicroSeconds MeasureOpeningL(CTextView& aView)
   1.202 +	{
   1.203 +	TCursorSelection zero(0, 0);
   1.204 +	aView.SetPendingSelection(zero);
   1.205 +	TTime start;
   1.206 +	TTime end;
   1.207 +	start.UniversalTime();
   1.208 +	aView.HandleGlobalChangeL();
   1.209 +	end.UniversalTime();
   1.210 +	return end.MicroSecondsFrom(start);
   1.211 +	}
   1.212 +
   1.213 +TTimeIntervalMicroSeconds MeasureRmsCursorDownL(CTextView& aView)
   1.214 +	{
   1.215 +	TInt mem;
   1.216 +	TInt cells = User::AllocSize(mem);
   1.217 +	TReal totalOfSquares = 0;
   1.218 +	TTime start;
   1.219 +	TTime end;
   1.220 +	TCursorPosition::TMovementType move = TCursorPosition::EFLineDown;
   1.221 +	while (move == TCursorPosition::EFLineDown)
   1.222 +		{
   1.223 +		start.UniversalTime();
   1.224 +		aView.MoveCursorL(move, EFalse);
   1.225 +		end.UniversalTime();
   1.226 +		TReal us = end.MicroSecondsFrom(start).Int64();
   1.227 +		totalOfSquares += us*us;
   1.228 +		}
   1.229 +	TReal rms;
   1.230 +	Math::Sqrt(rms, totalOfSquares);
   1.231 +	cells = User::AllocSize(mem);
   1.232 +	return TTimeIntervalMicroSeconds(static_cast<TInt64>(rms));
   1.233 +	}
   1.234 +
   1.235 +TInt NumberOfLines(CTextLayout& aLayout)
   1.236 +	{
   1.237 +	TTmDocPosSpec dp(aLayout.DocumentLength(), TTmDocPosSpec::ETrailing);
   1.238 +	TTmPosInfo2 posInfo;
   1.239 +	TTmLineInfo lineInfo;
   1.240 +	aLayout.FindDocPos(dp, posInfo, &lineInfo);
   1.241 +	return lineInfo.iLineNumber;
   1.242 +	}
   1.243 +
   1.244 +TTimeIntervalMicroSeconds MeasureFormattingL(CTextView& aView)
   1.245 +	{
   1.246 +	// This looks to me like a defect.
   1.247 +	// We have to set the actual doc pos to prevent a crash, even
   1.248 +	// though we are setting a pending selection.
   1.249 +	// Probably not too serious, though.
   1.250 +	aView.SetDocPosL(0, ETrue);
   1.251 +	TCursorSelection zero(0, 0);
   1.252 +	aView.SetPendingSelection(zero);
   1.253 +	TTime start;
   1.254 +	TTime end;
   1.255 +	start.UniversalTime();
   1.256 +	aView.HandleGlobalChangeL();
   1.257 +	aView.FinishBackgroundFormattingL();
   1.258 +	end.UniversalTime();
   1.259 +	end.UniversalTime();
   1.260 +	return end.MicroSecondsFrom(start);
   1.261 +	}
   1.262 +
   1.263 +void MeasureDeleteTextFromStartL(RArray<TTFTimeStamp>& aTimeStamps,
   1.264 +	TFormattingObjects& aFormattingObjects, TInt64& aSlowest)
   1.265 +	{
   1.266 +	const CTmTextLayout& tmLayout = aFormattingObjects.iLayout->TagmaTextLayout();
   1.267 +	aTimeStamps.Close();
   1.268 +	TTime start;
   1.269 +	TTime end;
   1.270 +	TInt iteration = 0;
   1.271 +	TInt64 total = 0;
   1.272 +
   1.273 +	TInt step = 0;
   1.274 +	while(aFormattingObjects.iRichText->DocumentLength() > 0)
   1.275 +		{
   1.276 +		aFormattingObjects.iRichText->DeleteL(0, 1);
   1.277 +		TCursorSelection cursor(0,0);
   1.278 +		start.UniversalTime();
   1.279 +		aFormattingObjects.iView->HandleInsertDeleteL(cursor, 1, EFalse);
   1.280 +		end.UniversalTime();
   1.281 +
   1.282 +		TInt64 us = end.MicroSecondsFrom(start).Int64();
   1.283 +
   1.284 +		if(us > aSlowest)
   1.285 +			{
   1.286 +			aSlowest = us;
   1.287 +			}
   1.288 +
   1.289 +		total += us;
   1.290 +		step++;
   1.291 +		if(step == KDeleteTextInterval)
   1.292 +			{
   1.293 +			TInt64 average = total/KDeleteTextInterval;
   1.294 +			TTFTimeStamp timestamp;
   1.295 +			timestamp.iTime = average;
   1.296 +			timestamp.iIteration = iteration;
   1.297 +			User::LeaveIfError(aTimeStamps.Append(timestamp));
   1.298 +			iteration++;
   1.299 +			step = 0;
   1.300 +			total = 0;
   1.301 +			}
   1.302 +		}
   1.303 +	}
   1.304 +
   1.305 +void MeasureInsertTextAtStartL(TInt aRepeats, TInt aRepeatsPerPara, RArray<TTFTimeStamp>& aTimeStamps,
   1.306 +	TFormattingObjects& aFormattingObjects, TInt64& aSlowest)
   1.307 +	{
   1.308 +	aTimeStamps.Close();
   1.309 +	TTime start;
   1.310 +	TTime end;
   1.311 +	TInt repeatsInThisPar = 0;
   1.312 +	TViewRectChanges changes;
   1.313 +	aFormattingObjects.iRichText->Reset();
   1.314 +	for (TInt i = 0; i < aRepeats; i++)
   1.315 +		{
   1.316 +		TBuf<128> sample;
   1.317 +		if ((i%2)==0)
   1.318 +			{
   1.319 +			sample = KEnglishToInsert1;
   1.320 +			}
   1.321 +		else
   1.322 +			{
   1.323 +			sample = KEnglishToInsert2;
   1.324 +			}
   1.325 +		aFormattingObjects.iRichText->InsertL(0, sample);
   1.326 +		TCursorSelection cursor(0, sample.Length());
   1.327 +
   1.328 +		start.UniversalTime();
   1.329 +		aFormattingObjects.iLayout->HandleBlockChangeL(cursor, 0, changes, 0);
   1.330 +		end.UniversalTime();
   1.331 +
   1.332 +		TInt64 us = end.MicroSecondsFrom(start).Int64();
   1.333 +		repeatsInThisPar ++;
   1.334 +		TTFTimeStamp timestamp;
   1.335 +		timestamp.iTime = us;
   1.336 +		timestamp.iIteration = i;
   1.337 +		User::LeaveIfError(aTimeStamps.Append(timestamp));
   1.338 +		if(us > aSlowest)
   1.339 +			{
   1.340 +			aSlowest = us;
   1.341 +			}
   1.342 +		if (repeatsInThisPar > aRepeatsPerPara)
   1.343 +			{
   1.344 +			TChar paragraphDelimiter(0x2029);
   1.345 +			aFormattingObjects.iRichText->InsertL(0, paragraphDelimiter);
   1.346 +			repeatsInThisPar = 0;
   1.347 +			}
   1.348 +		}
   1.349 +	}
   1.350 +
   1.351 +void MeasureCursorL(RArray<TTFTimeStamp>& aTimeStamps, TCursorPosition::TMovementType aType,
   1.352 +	TFormattingObjects& aFormattingObjects, TInt64& aSlowest)
   1.353 +	{
   1.354 +	aTimeStamps.Close();
   1.355 +	TTime start;
   1.356 +	TTime end;
   1.357 +	TInt lines = 0;
   1.358 +	TCursorPosition::TMovementType move = aType;
   1.359 +
   1.360 +	while (move == aType)
   1.361 +		{
   1.362 +		lines++;
   1.363 +		start.UniversalTime();
   1.364 +		aFormattingObjects.iView->MoveCursorL(move, EFalse);
   1.365 +		end.UniversalTime();
   1.366 +		TInt64 us = end.MicroSecondsFrom(start).Int64();
   1.367 +		TTFTimeStamp timestamp;
   1.368 +		timestamp.iTime = us;
   1.369 +		timestamp.iIteration = lines;
   1.370 +		User::LeaveIfError(aTimeStamps.Append(timestamp));
   1.371 +		if(us > aSlowest)
   1.372 +			{
   1.373 +			aSlowest = us;
   1.374 +			}
   1.375 +		const CTmTextLayout& tmLayout = aFormattingObjects.iLayout->TagmaTextLayout();
   1.376 +		}
   1.377 +	}
   1.378 +
   1.379 +void CreateFormattingObjectsLC(TFormattingObjects& aFormattingObjects)
   1.380 +	{
   1.381 +	TRect* displayRect = new(ELeave) TRect(0, 0, KDisplayWidth, KDisplayHeight);
   1.382 +	CleanupStack::PushL(displayRect);
   1.383 +	CParaFormatLayer* paraFormat = CParaFormatLayer::NewL();
   1.384 +	CleanupStack::PushL(paraFormat);
   1.385 +	CCharFormatLayer* charFormat = CCharFormatLayer::NewL();
   1.386 +	CleanupStack::PushL(charFormat);
   1.387 +	CRichText* text = CRichText::NewL(paraFormat, charFormat);
   1.388 +	CleanupStack::PushL(text);
   1.389 +	CTextLayout* layout = CTextLayout::NewL(text, displayRect->Width());
   1.390 +	CleanupStack::PushL(layout);
   1.391 +	CTestGraphicsDevice* device = CTestGraphicsDevice::NewL(displayRect->Size(), 0);
   1.392 +	CleanupStack::PushL(device);
   1.393 +	// Prevent the line array from using up the memory
   1.394 +	device->LineArray().Disable();
   1.395 +	CTextView* view = CTextView::NewL(layout, *displayRect,
   1.396 +		device, device, 0, 0, 0);
   1.397 +	CleanupStack::PushL(view);
   1.398 +	// must disable flicker-free redraw or Form will try to use
   1.399 +	// the test font with an off-screen (i.e. real) graphics context,
   1.400 +	// which will panic.
   1.401 +	view->DisableFlickerFreeRedraw();
   1.402 +
   1.403 +	aFormattingObjects.iDisplayRect = displayRect;
   1.404 +	aFormattingObjects.iParFormat = paraFormat;
   1.405 +	aFormattingObjects.iCharFormat = charFormat;
   1.406 +	aFormattingObjects.iRichText = text;
   1.407 +	aFormattingObjects.iLayout = layout;
   1.408 +	aFormattingObjects.iDevice = device;
   1.409 +	aFormattingObjects.iView = view;
   1.410 +	}
   1.411 +
   1.412 +void DestroyFormattingObjects(TFormattingObjects& aFormattingObjects)
   1.413 +	{
   1.414 +	CleanupStack::PopAndDestroy(aFormattingObjects.iView);
   1.415 +	CleanupStack::PopAndDestroy(aFormattingObjects.iDevice);
   1.416 +	CleanupStack::PopAndDestroy(aFormattingObjects.iLayout);
   1.417 +	CleanupStack::PopAndDestroy(aFormattingObjects.iRichText);
   1.418 +	CleanupStack::PopAndDestroy(aFormattingObjects.iCharFormat);
   1.419 +	CleanupStack::PopAndDestroy(aFormattingObjects.iParFormat);
   1.420 +	CleanupStack::PopAndDestroy(aFormattingObjects.iDisplayRect);
   1.421 +	}
   1.422 +
   1.423 +/**
   1.424 +@SYMTestCaseID SYSLIB-FORMA-UT-1897
   1.425 +@SYMTestCaseDesc Benchmarks scrolling text
   1.426 +@SYMTestPriority High
   1.427 +@SYMTestActions creates document and scrolls it
   1.428 +@SYMTestExpectedResults The test must not fail or panic .
   1.429 +@SYMDEF DEF092140, DEF092139
   1.430 +*/
   1.431 +void RunScrollingTestL(TInt aRepeats, TInt aRepeatsPerParagraph,
   1.432 +	RArray<TTFTimeStamp>& aTimeStampsDown, RArray<TTFTimeStamp>& aTimeStampsUp,
   1.433 +	TDocInfo& aDocInfo)
   1.434 +	{
   1.435 +    TESTPRINT(_L(" @SYMTestCaseID:SYSLIB-FORMA-UT-1897 "));
   1.436 +	TInt docLength = KEnglish().Length() * aRepeats;
   1.437 +	TInt paragraphs = aRepeats/aRepeatsPerParagraph;
   1.438 +
   1.439 +	TFormattingObjects o;
   1.440 +	CreateFormattingObjectsLC(o);
   1.441 +	o.iLayout->SetWrapWidth(KInsertDisplayWidth);
   1.442 +	o.iLayout->SetAmountToFormat(CTextLayout::EFFormatBand);
   1.443 +	SetTextL(*(o.iRichText), KEnglish, aRepeats, aRepeatsPerParagraph);
   1.444 +
   1.445 +	TTimeIntervalMicroSeconds opening = MeasureOpeningL(*(o.iView));
   1.446 +	TInt64 slowest = 0;
   1.447 +	MeasureCursorL(aTimeStampsDown, TCursorPosition::EFLineDown, o, slowest);
   1.448 +	MeasureCursorL(aTimeStampsUp, TCursorPosition::EFLineUp, o, slowest);
   1.449 +
   1.450 +	TBuf<256> buf;
   1.451 +	buf.AppendFormat(_L("PERFORMANCE: Syslibs;Form_Scrolling_Slowest_Doc_with_%d_characters_%d_paragraphs;microseconds: %Ld"), docLength, paragraphs, slowest);
   1.452 +	TESTPRINT(buf);
   1.453 +	
   1.454 +	aDocInfo = GetSampleDocInfoL(o);
   1.455 +	DestroyFormattingObjects(o);
   1.456 +	}
   1.457 +
   1.458 +/**
   1.459 +@SYMTestCaseID SYSLIB-FORMA-UT-1898
   1.460 +@SYMTestCaseDesc Benchmarks inserting, deleting and formatting text
   1.461 +@SYMTestPriority High
   1.462 +@SYMTestActions creates documents in each language and performs edits and reformats
   1.463 +@SYMTestExpectedResults The test must not fail or panic .
   1.464 +@SYMDEF DEF092140, DEF092139
   1.465 +*/
   1.466 +void RunEnglishArabicJapaneseBenchmarksL(TFormattingObjects& aFormattingObjects)
   1.467 +	{
   1.468 +    TESTPRINT(_L(" @SYMTestCaseID:SYSLIB-FORMA-UT-1898 "));
   1.469 +	SetTextL(*aFormattingObjects.iRichText, KEnglish, KEnglishRepeats, KEnglishRepeats);
   1.470 +	TTimeIntervalMicroSeconds opening = MeasureOpeningL(*aFormattingObjects.iView);
   1.471 +	TTimeIntervalMicroSeconds rmsCursorDown = MeasureRmsCursorDownL(*aFormattingObjects.iView);
   1.472 +	TTimeIntervalMicroSeconds englishFormatting = MeasureFormattingL(*aFormattingObjects.iView);
   1.473 +	TInt englishLines = NumberOfLines(*aFormattingObjects.iLayout);
   1.474 +	SetTextL(*aFormattingObjects.iRichText, KArabic, KArabicRepeats, KArabicRepeats);
   1.475 +	TTimeIntervalMicroSeconds arabicFormatting = MeasureFormattingL(*aFormattingObjects.iView);
   1.476 +	TInt arabicLines = NumberOfLines(*aFormattingObjects.iLayout);
   1.477 +	SetTextL(*aFormattingObjects.iRichText, KJapanese, KJapaneseRepeats, KJapaneseRepeats);
   1.478 +	TTimeIntervalMicroSeconds japaneseFormatting = MeasureFormattingL(*aFormattingObjects.iView);
   1.479 +	TInt japaneseLines = NumberOfLines(*aFormattingObjects.iLayout);
   1.480 +
   1.481 +	// Check that the results are fair
   1.482 +	TInt minLines;
   1.483 +	TInt maxLines;
   1.484 +	if (arabicLines < englishLines)
   1.485 +		{
   1.486 +		minLines = arabicLines;
   1.487 +		maxLines = englishLines;
   1.488 +		}
   1.489 +	else
   1.490 +		{
   1.491 +		minLines = englishLines;
   1.492 +		maxLines = arabicLines;
   1.493 +		}
   1.494 +	if (japaneseLines < minLines)
   1.495 +		minLines = japaneseLines;
   1.496 +	else if (maxLines < japaneseLines)
   1.497 +		maxLines = japaneseLines;
   1.498 +
   1.499 +	//Tests that the number of lines in each test is more or less balanced
   1.500 +	TESTPOINT(maxLines * 100 <= minLines * 105);
   1.501 +
   1.502 +	TBuf<256> buf;
   1.503 +	buf.AppendFormat(_L("PERFORMANCE: Syslibs;Form_OpeningLargeParagraph;microseconds: %d"),
   1.504 +		static_cast<TInt>(opening.Int64()));
   1.505 +	TESTPRINT(buf);
   1.506 +	buf.Zero();
   1.507 +	
   1.508 +	buf.AppendFormat(_L("PERFORMANCE: Syslibs;Form_RmsCursorDown;microseconds: %d"),
   1.509 +		static_cast<TInt>(rmsCursorDown.Int64()));
   1.510 +	TESTPRINT(buf);
   1.511 +	buf.Zero();
   1.512 +	
   1.513 +	buf.AppendFormat(_L("PERFORMANCE: Syslibs;Form_FormattingEnglish;microseconds: %d"),
   1.514 +		static_cast<TInt>(englishFormatting.Int64()));
   1.515 +	TESTPRINT(buf);
   1.516 +	buf.Zero();
   1.517 +	
   1.518 +	buf.AppendFormat(_L("PERFORMANCE: Syslibs;Form_FormattingArabic;microseconds: %d"),
   1.519 +		static_cast<TInt>(arabicFormatting.Int64()));
   1.520 +	TESTPRINT(buf);
   1.521 +	buf.Zero();
   1.522 +	
   1.523 +	buf.AppendFormat(_L("PERFORMANCE: Syslibs;Form_FormattingJapanese;microseconds: %d"),
   1.524 +		static_cast<TInt>(japaneseFormatting.Int64()));
   1.525 +	TESTPRINT(buf);	
   1.526 +	}
   1.527 +
   1.528 +/**
   1.529 +@SYMTestCaseID SYSLIB-FORMA-UT-1896
   1.530 +@SYMTestCaseDesc Benchmarks inserting text from the beginning of a paragraph
   1.531 +@SYMTestPriority High
   1.532 +@SYMTestActions creates a large paragraph containg just one word and inserts text iteratively from
   1.533 +the beginning
   1.534 +@SYMTestExpectedResults The test must not fail or panic .
   1.535 +@SYMDEF DEF092140, DEF092139
   1.536 +*/
   1.537 +void RunInsertTextTestsL(TInt aRepeats, TInt aRepeatsPerParagraph,
   1.538 +	RArray<TTFTimeStamp>& aTimeStamps, TDocInfo& aDocInfo)
   1.539 +	{
   1.540 +    TESTPRINT(_L(" @SYMTestCaseID:SYSLIB-FORMA-UT-1896 "));
   1.541 +	TFormattingObjects o;
   1.542 +	CreateFormattingObjectsLC(o);
   1.543 +	TInt64 slowest = 0;
   1.544 +	o.iLayout->SetWrapWidth(KInsertDisplayWidth);
   1.545 +	o.iLayout->SetAmountToFormat(CTextLayout::EFFormatBand);
   1.546 +	MeasureInsertTextAtStartL(aRepeats, aRepeatsPerParagraph, aTimeStamps, o, slowest);
   1.547 +	aDocInfo = GetSampleDocInfoL(o);
   1.548 +
   1.549 +	TBuf<256> buf;
   1.550 +	buf.AppendFormat(_L("PERFORMANCE: Syslibs;Form_InsertText_Slowest;microseconds: %Ld"), slowest);
   1.551 +	TESTPRINT(buf);
   1.552 +	
   1.553 +	DestroyFormattingObjects(o);
   1.554 +	}
   1.555 +
   1.556 +/**
   1.557 +@SYMTestCaseID SYSLIB-FORMA-UT-1895
   1.558 +@SYMTestCaseDesc Benchmarks deleting text from the beginning of a paragraph
   1.559 +@SYMTestPriority High
   1.560 +@SYMTestActions creates a large paragraph containg just one word and deletes text iteratively from
   1.561 +the beginning
   1.562 +@SYMTestExpectedResults The test must not fail or panic .
   1.563 +@SYMDEF DEF092140, DEF092139
   1.564 +*/
   1.565 +void RunDeleteTextFromStartTest(RArray<TTFTimeStamp>& aTimeStamps, TDocInfo& aDocInfo)
   1.566 +	{
   1.567 +    TESTPRINT(_L(" @SYMTestCaseID:SYSLIB-FORMA-UT-1895 "));
   1.568 +	TFormattingObjects o;
   1.569 +	CreateFormattingObjectsLC(o);
   1.570 +	TInt64 slowest = 0;
   1.571 +	o.iLayout->SetWrapWidth(KInsertDisplayWidth);
   1.572 +	o.iLayout->SetAmountToFormat(CTextLayout::EFFormatBand);
   1.573 +	RBuf bigbuf;
   1.574 +	BigBufLC(bigbuf);
   1.575 +	SetTextL(*o.iRichText, bigbuf, 1, 1);
   1.576 +	TTimeIntervalMicroSeconds opening = MeasureOpeningL(*o.iView);
   1.577 +
   1.578 +	MeasureDeleteTextFromStartL(aTimeStamps, o, slowest);
   1.579 +	aDocInfo = GetSampleDocInfoL(o);
   1.580 +
   1.581 +	TBuf<256> buf;	
   1.582 +	buf.AppendFormat(_L("PERFORMANCE: Syslibs;Form_DeleteText_Slowest;microseconds: %Ld"), slowest);
   1.583 +	TESTPRINT(buf);	
   1.584 +
   1.585 +	CleanupStack::PopAndDestroy();//bigbuf
   1.586 +	DestroyFormattingObjects(o);
   1.587 +	}
   1.588 +
   1.589 +void GetFormattingBenchmarkL(TInt aNumberOfIterations, TInt& aNumberOfCharacters, TInt64& aNormalisedBenchmark)
   1.590 +	{
   1.591 +    TESTPRINT(_L(" @SYMTestCaseID:SYSLIB-FORMA-UT-1895 "));
   1.592 +	TFormattingObjects o;
   1.593 +	CreateFormattingObjectsLC(o);
   1.594 +	o.iLayout->SetWrapWidth(KInsertDisplayWidth);
   1.595 +	o.iLayout->SetAmountToFormat(CTextLayout::EFFormatBand);
   1.596 +
   1.597 +	SetTextL(*(o.iRichText), KEnglish, aNumberOfIterations, aNumberOfIterations);
   1.598 +
   1.599 +	TTimeIntervalMicroSeconds ignore = MeasureOpeningL(*(o.iView));
   1.600 +	o.iView->SetDocPosL(o.iRichText->DocumentLength());
   1.601 +	//make a global change
   1.602 +	o.iLayout->SetWrapWidth(KChangedDisplayWidth);
   1.603 +	//measure time to reformat for it
   1.604 +	TTime start;
   1.605 +	TTime end;
   1.606 +	start.UniversalTime();
   1.607 +	o.iView->HandleGlobalChangeL();
   1.608 +	end.UniversalTime();
   1.609 +
   1.610 +	TTimeIntervalMicroSeconds formattingTime = end.MicroSecondsFrom(start);
   1.611 +
   1.612 +	aNumberOfCharacters = o.iRichText->DocumentLength();
   1.613 +	aNormalisedBenchmark = formattingTime.Int64()/aNumberOfIterations;
   1.614 +
   1.615 +	DestroyFormattingObjects(o);
   1.616 +	}
   1.617 +
   1.618 +/**
   1.619 +@SYMTestCaseID SYSLIB-FORMA-UT-1894
   1.620 +@SYMTestCaseDesc Benchmarks formatting text
   1.621 +@SYMTestPriority High
   1.622 +@SYMTestActions for a series of documents of increasing size consisting of a single paragraph,
   1.623 +sets the cursor position to the end of the document, makes a global change and formats it.
   1.624 +@SYMTestExpectedResults The test must not fail or panic. The increase in time taken should be
   1.625 +roughly linear with the document size.
   1.626 +@SYMDEF DEF095401
   1.627 +*/
   1.628 +void RunFormattingBenchmarksL()
   1.629 +	{
   1.630 +    TESTPRINT(_L(" @SYMTestCaseID:SYSLIB-FORMA-UT-1894 "));
   1.631 +	TInt numberOfCharacters = 0;
   1.632 +	TInt numberOfIterations;
   1.633 +	TInt64 normalisedBenchmark = 0;
   1.634 +
   1.635 +	TBuf<256> buf;
   1.636 +	
   1.637 +	numberOfIterations = 1;
   1.638 +	GetFormattingBenchmarkL(numberOfIterations, numberOfCharacters, normalisedBenchmark);
   1.639 +	buf.AppendFormat(_L("PERFORMANCE: Syslibs;Form_FormatText;document contains %d characters: %Ld microseconds per iteration"), numberOfCharacters, normalisedBenchmark);
   1.640 +	TESTPRINT(buf);
   1.641 +	
   1.642 +	buf.Zero();
   1.643 +	numberOfIterations = 5;
   1.644 +	GetFormattingBenchmarkL(numberOfIterations, numberOfCharacters, normalisedBenchmark);
   1.645 +	buf.AppendFormat(_L("PERFORMANCE: Syslibs;Form_FormatText;document contains %d characters: %Ld microseconds per iteration"), numberOfCharacters, normalisedBenchmark);
   1.646 +	TESTPRINT(buf);
   1.647 +	
   1.648 +	buf.Zero();
   1.649 +	numberOfIterations = 10;
   1.650 +	GetFormattingBenchmarkL(numberOfIterations, numberOfCharacters, normalisedBenchmark);
   1.651 +	buf.AppendFormat(_L("PERFORMANCE: Syslibs;Form_FormatText;document contains %d characters: %Ld microseconds per iteration"), numberOfCharacters, normalisedBenchmark);
   1.652 +	TESTPRINT(buf);
   1.653 +
   1.654 +	buf.Zero();
   1.655 +	numberOfIterations = 50;
   1.656 +	GetFormattingBenchmarkL(numberOfIterations, numberOfCharacters, normalisedBenchmark);
   1.657 +	buf.AppendFormat(_L("PERFORMANCE: Syslibs;Form_FormatText;document contains %d characters: %Ld microseconds per iteration"), numberOfCharacters, normalisedBenchmark);
   1.658 +	TESTPRINT(buf);
   1.659 +
   1.660 +	buf.Zero();
   1.661 +	numberOfIterations = 100;
   1.662 +	GetFormattingBenchmarkL(numberOfIterations, numberOfCharacters, normalisedBenchmark);
   1.663 +	buf.AppendFormat(_L("PERFORMANCE: Syslibs;Form_FormatText;document contains %d characters: %Ld microseconds per iteration"), numberOfCharacters, normalisedBenchmark);
   1.664 +	TESTPRINT(buf);
   1.665 +
   1.666 +	buf.Zero();
   1.667 +	numberOfIterations = 250;
   1.668 +	GetFormattingBenchmarkL(numberOfIterations, numberOfCharacters, normalisedBenchmark);
   1.669 +	buf.AppendFormat(_L("PERFORMANCE: Syslibs;Form_FormatText;document contains %d characters: %Ld microseconds per iteration"), numberOfCharacters, normalisedBenchmark);
   1.670 +	TESTPRINT(buf);
   1.671 +
   1.672 +	buf.Zero();
   1.673 +	numberOfIterations = 500;
   1.674 +	GetFormattingBenchmarkL(numberOfIterations, numberOfCharacters, normalisedBenchmark);
   1.675 +	buf.AppendFormat(_L("PERFORMANCE: Syslibs;Form_FormatText;document contains %d characters: %Ld microseconds per iteration"), numberOfCharacters, normalisedBenchmark);
   1.676 +	TESTPRINT(buf);
   1.677 +	
   1.678 +	buf.Zero();
   1.679 +	numberOfIterations = 750;
   1.680 +	GetFormattingBenchmarkL(numberOfIterations, numberOfCharacters, normalisedBenchmark);
   1.681 +	buf.AppendFormat(_L("PERFORMANCE: Syslibs;Form_FormatText;document contains %d characters: %Ld microseconds per iteration"), numberOfCharacters, normalisedBenchmark);
   1.682 +	TESTPRINT(buf);
   1.683 +	
   1.684 +	buf.Zero();
   1.685 +	numberOfIterations = 1000;
   1.686 +	GetFormattingBenchmarkL(numberOfIterations, numberOfCharacters, normalisedBenchmark);
   1.687 +	buf.AppendFormat(_L("PERFORMANCE: Syslibs;Form_FormatText;document contains %d characters: %Ld microseconds per iteration"), numberOfCharacters, normalisedBenchmark);
   1.688 +	TESTPRINT(buf);
   1.689 +	}
   1.690 +
   1.691 +void RunBenchmarksL()
   1.692 +	{
   1.693 +	CActiveScheduler* scheduler = new(ELeave) CActiveScheduler;
   1.694 +	CleanupStack::PushL(scheduler);
   1.695 +	CActiveScheduler::Install(scheduler);
   1.696 +
   1.697 +	RunFormattingBenchmarksL();
   1.698 +
   1.699 +	TDocInfo docInfo;
   1.700 +	RArray<TTFTimeStamp> timestampsDown;
   1.701 +	RArray<TTFTimeStamp> timestampsUp;
   1.702 +	CleanupClosePushL(timestampsDown);
   1.703 +	CleanupClosePushL(timestampsUp);
   1.704 +
   1.705 +	RunDeleteTextFromStartTest(timestampsUp, docInfo);
   1.706 +	WriteSampleDocInfo(docInfo, fileTimeStamps);
   1.707 +	WriteTimeStampsL(KDeleteTextFromStart, timestampsUp);
   1.708 +
   1.709 +	RunInsertTextTestsL(KEnglishInsertRepeats, KEnglishInsertRepeats, timestampsUp, docInfo);
   1.710 +	WriteSampleDocInfo(docInfo, fileTimeStamps);
   1.711 +	WriteTimeStampsL(KInsertTextAtStart, timestampsUp);
   1.712 +
   1.713 +	RunScrollingTestL(KEnglishScrollRepeats, KEnglishScrollRepeats, timestampsDown, timestampsUp, docInfo);
   1.714 +	WriteSampleDocInfo(docInfo, fileTimeStamps);
   1.715 +	WriteTimeStampsL(KScrollingDown, timestampsDown);
   1.716 +	WriteTimeStampsL(KScrollingUp, timestampsUp);
   1.717 +
   1.718 +	RunScrollingTestL(KEnglishScrollRepeats, KEnglishScrollRepeats/2, timestampsDown, timestampsUp, docInfo);
   1.719 +	WriteSampleDocInfo(docInfo, fileTimeStamps);
   1.720 +	WriteTimeStampsL(KScrollingDown, timestampsDown);
   1.721 +	WriteTimeStampsL(KScrollingUp, timestampsUp);
   1.722 +
   1.723 +	RunScrollingTestL(KEnglishScrollRepeats, KEnglishScrollRepeats/10, timestampsDown, timestampsUp, docInfo);
   1.724 +	WriteSampleDocInfo(docInfo, fileTimeStamps);
   1.725 +	WriteTimeStampsL(KScrollingDown, timestampsDown);
   1.726 +	WriteTimeStampsL(KScrollingUp, timestampsUp);
   1.727 +
   1.728 +	TFormattingObjects o;
   1.729 +	CreateFormattingObjectsLC(o);
   1.730 +	RunEnglishArabicJapaneseBenchmarksL(o);
   1.731 +	DestroyFormattingObjects(o);
   1.732 +
   1.733 +	CleanupStack::PopAndDestroy(2);
   1.734 +	CleanupStack::PopAndDestroy(scheduler);
   1.735 +
   1.736 +	}
   1.737 +
   1.738 +TVerdict CTFormBenchmarkStep::doTestStepL()
   1.739 +	{
   1.740 +    SetTestStepResult(EPass);
   1.741 +    TestStep = this;
   1.742 +    
   1.743 +    TESTPRINT(KFormBenchmark);
   1.744 +    TESTPRINT(_L("Start Font/Bitmap Server"));
   1.745 +
   1.746 +	TInt error = RFbsSession::Connect();
   1.747 +	if (error == KErrNotFound)
   1.748 +		{
   1.749 +		FbsStartup();
   1.750 +		error = RFbsSession::Connect();
   1.751 +		}
   1.752 +	// Tests that FBServ actually starts
   1.753 +	TESTPOINT(error == KErrNone);
   1.754 +	error = fs.Connect();
   1.755 +	TESTPOINT(error == KErrNone);
   1.756 +
   1.757 +	error = fileTimeStamps.Replace(fs, KLogTimeStampsName, EFileWrite);
   1.758 +	
   1.759 +	TBuf<256> buf;
   1.760 +	buf.AppendFormat(_L("> fileTimeStamps.Replace %d"), error);
   1.761 +	TESTPRINT(buf);
   1.762 +	
   1.763 +	TESTPOINT(error == KErrNone);
   1.764 +
   1.765 +	TESTPRINT(_L("Run Benchmarks"));
   1.766 +	TRAP(error, RunBenchmarksL());
   1.767 +	// Tests that the Benchmarks did not run out of memory
   1.768 +	// or otherwise leave
   1.769 +	TESTPOINT(error == KErrNone);
   1.770 +
   1.771 +	fileTimeStamps.Close();
   1.772 +	fs.Close();
   1.773 +	RFbsSession::Disconnect();
   1.774 +
   1.775 +	return TestStepResult();
   1.776 +	}
   1.777 +