📄 performance.cpp
字号:
CPerformanceTest();
protected:
TInt iVirtualMethodCount;
};
CPerformanceTest::CPerformanceTest() :
CPerformanceTestBase()
{}
void CPerformanceTest::VirtualIncMethodCount()
{
iVirtualMethodCount++;
}
//////////////////////////////////////////////////////////////////////////////////
class CAppSpecificListView : public CQikViewBase
{
protected:
// from CQikViewBase
TVwsViewId ViewId() const;
void HandleCommandL(CQikCommand& aCommand);
void ViewConstructL();
void ViewDeactivated();
void ViewActivatedL(const TVwsViewId& aPrevViewId,const TUid aCustomMessageId,const TDesC8& aCustomMessage);
// new methods
void PerformTests();
public:
// new methods
CAppSpecificListView(CAppSpecificUi& aAppUi);
protected:
};
CAppSpecificListView::CAppSpecificListView(CAppSpecificUi& aAppUi) :
CQikViewBase(aAppUi,KNullViewId)
{}
TVwsViewId CAppSpecificListView::ViewId() const
//
// All views are uniquely identified within the entire system. A TVwsViewId consists of
// the application uid (uid3) and app specific view uid
//
{
return(KViewIdListView);
}
_LIT(KTimeInSecs,"%d.%d secs");
void CAppSpecificListView::PerformTests()
{
TTime start;
TTime end;
TBuf<128>bb;
///////////////////////////////////////////////////////////////////////////////////////
// see how many regular function calls per/sec can be called
// actually measures time taken to do 'n' iterations
start.HomeTime();
// Call a regular C/C++ function 10 million times
for (TInt i=0;i<10000000;i++)
IncFunctionCount();
// Report number of regular C/C++ function calls achieved
end.HomeTime();
TInt val=(TInt)(end.Int64()-start.Int64());
TInt secs=val/1000000;
TInt tenths=(val-(secs*1000000));
bb.Format(KTimeInSecs,secs,tenths);
_LIT(KFuncCalls,"Func calls");
iEikonEnv->InfoWinL(KFuncCalls,bb);
///////////////////////////////////////////////////////////////////////////////////////
// see how many method calls per sec can be called
// actually measures time taken to do 'n' iterations
CPerformanceTestBase* perf=new(ELeave)CPerformanceTest;
CleanupStack::PushL(perf);
start.HomeTime();
// Call a non virtual method 10 million times
for (TInt i=0;i<10000000;i++)
perf->IncMethodCount();
// Report number of method calls achieved
end.HomeTime();
val=(TInt)(end.Int64()-start.Int64());
secs=val/1000000;
tenths=(val-(secs*1000000));
bb.Format(KTimeInSecs,secs,tenths);
_LIT(KMethodCalls,"Method calls");
iEikonEnv->InfoWinL(KMethodCalls,bb);
///////////////////////////////////////////////////////////////////////////////////////
// see how many pure virtal method calls per sec can be called
// actually measures time taken to do 'n' iterations
start.HomeTime();
// Call a pure virtual method 10 million times
for (TInt i=0;i<10000000;i++)
perf->VirtualIncMethodCount();
// Report number of method calls achieved
end.HomeTime();
val=(TInt)(end.Int64()-start.Int64());
secs=val/1000000;
tenths=(val-(secs*1000000));
bb.Format(KTimeInSecs,secs,tenths);
_LIT(KVirtualMethods,"Virtual methods");
iEikonEnv->InfoWinL(KVirtualMethods,bb);
///////////////////////////////////////////////////////////////////////////////////////
// see how integer calcs per sec can be processed
// actually measures time taken to do 'n' iterations
start.HomeTime();
// perform lots (30 million) integer additions + subtractions
perf->IntegerCalc();
end.HomeTime();
val=(TInt)(end.Int64()-start.Int64());
secs=val/1000000;
tenths=(val-(secs*1000000));
bb.Format(KTimeInSecs,secs,tenths);
_LIT(KIntegers,"Integers");
iEikonEnv->InfoWinL(KIntegers,bb);
///////////////////////////////////////////////////////////////////////////////////////
// see how float calcs per sec can be processed
// actually measures time taken to do 'n' iterations
start.HomeTime();
// perform lots (2 million) floating point calculations
perf->FloatingPointCalc();
end.HomeTime();
val=(TInt)(end.Int64()-start.Int64());
secs=val/1000000;
tenths=(val-(secs*1000000));
bb.Format(KTimeInSecs,secs,tenths);
_LIT(KFloats,"Floats");
iEikonEnv->InfoWinL(KFloats,bb);
///////////////////////////////////////////////////////////////////////////////////////
// see how RunL()'s per sec can be processed
// actually measures time taken to do 'n' iterations
start.HomeTime();
// perform 500,000 RunL()s
perf->StartRunLTest();
end.HomeTime();
val=(TInt)(end.Int64()-start.Int64());
secs=val/1000000;
tenths=(val-(secs*1000000));
bb.Format(KTimeInSecs,secs,tenths);
_LIT(KRunls,"RunLs");
iEikonEnv->InfoWinL(KRunls,bb);
///////////////////////////////////////////////////////////////////////////////////////
// see how many TRAPD methods we can call per sec
// actually measures time taken to do 'n' iterations
start.HomeTime();
// Call 1 million methods under a TRAP harness
perf->TrapCalc();
end.HomeTime();
val=(TInt)(end.Int64()-start.Int64());
secs=val/1000000;
tenths=(val-(secs*1000000));
bb.Format(KTimeInSecs,secs,tenths);
_LIT(KTraps,"Traps");
iEikonEnv->InfoWinL(KTraps,bb);
///////////////////////////////////////////////////////////////////////////////////////
// see how long to append entries, CArray + RArrays + different granularities
// actually measures time taken to do 'n' iterations
start.HomeTime();
// Create and add entries to a CArray, granularity 1
perf->GranularityTestPart1L();
end.HomeTime();
val=(TInt)(end.Int64()-start.Int64());
secs=val/1000000;
tenths=(val-(secs*1000000));
bb.Format(KTimeInSecs,secs,tenths);
_LIT(KGranularity,"Granularity");
iEikonEnv->InfoWinL(KGranularity,bb);
///////////////////////////////////////////////////////////////////////////////////////
start.HomeTime();
// Create and add entries to a CArray, granularity 100000
perf->GranularityTestPart2L();
end.HomeTime();
val=(TInt)(end.Int64()-start.Int64());
secs=val/1000000;
tenths=(val-(secs*1000000));
bb.Format(KTimeInSecs,secs,tenths);
_LIT(KGranularity2,"Granularity2");
iEikonEnv->InfoWinL(KGranularity2,bb);
///////////////////////////////////////////////////////////////////////////////////////
start.HomeTime();
// Create and add entries to a RArray, granularity 1
perf->GranularityTestPart3L();
end.HomeTime();
val=(TInt)(end.Int64()-start.Int64());
secs=val/1000000;
tenths=(val-(secs*1000000));
bb.Format(KTimeInSecs,secs,tenths);
_LIT(KGranularity3,"Granularity3");
iEikonEnv->InfoWinL(KGranularity3,bb);
///////////////////////////////////////////////////////////////////////////////////////
start.HomeTime();
// Create and add entries to a RArray, granularity 100000
perf->GranularityTestPart4L();
end.HomeTime();
val=(TInt)(end.Int64()-start.Int64());
secs=val/1000000;
tenths=(val-(secs*1000000));
bb.Format(KTimeInSecs,secs,tenths);
_LIT(KGranularity4,"Granularity4");
iEikonEnv->InfoWinL(KGranularity4,bb);
///////////////////////////////////////////////////////////////////////////////////////
// look at array access times, for CArray, RArray + std C arrays
perf->CArrayTestPart1L(); // remove array creation from measured time
start.HomeTime();
// access a CArray 10 million times
perf->CArrayTestPart2();
end.HomeTime();
val=(TInt)(end.Int64()-start.Int64());
secs=val/1000000;
tenths=(val-(secs*1000000));
bb.Format(KTimeInSecs,secs,tenths);
_LIT(KCarray,"Carray []");
iEikonEnv->InfoWinL(KCarray,bb);
///////////////////////////////////////////////////////////////////////////////////////
perf->RArrayTestPart1L(); // remove array creation from measured time
start.HomeTime();
// access a RArray 10 million times
perf->RArrayTestPart2();
end.HomeTime();
val=(TInt)(end.Int64()-start.Int64());
secs=val/1000000;
tenths=(val-(secs*1000000));
bb.Format(KTimeInSecs,secs,tenths);
_LIT(KRarray,"Rarray []");
iEikonEnv->InfoWinL(KRarray,bb);
///////////////////////////////////////////////////////////////////////////////////////
start.HomeTime();
// access a regular C/C++ array (object property) as comparison for RArray + CArray
// performance figures.
perf->ArrayTest();
end.HomeTime();
val=(TInt)(end.Int64()-start.Int64());
secs=val/1000000;
tenths=(val-(secs*1000000));
bb.Format(KTimeInSecs,secs,tenths);
_LIT(KiArray,"iArray []");
iEikonEnv->InfoWinL(KiArray,bb);
///////////////////////////////////////////////////////////////////////////////////////
// look at file i/o performance
// see how buffer sizes affect writing throughput
start.HomeTime();
perf->FileWriteTest1();
end.HomeTime();
val=(TInt)(end.Int64()-start.Int64());
secs=val/1000000;
tenths=(val-(secs*1000000));
bb.Format(KTimeInSecs,secs,tenths);
_LIT(KFileWrite1,"File write1");
iEikonEnv->InfoWinL(KFileWrite1,bb);
///////////////////////////////////////////////////////////////////////////////////////
start.HomeTime();
perf->FileWriteTest2();
end.HomeTime();
val=(TInt)(end.Int64()-start.Int64());
secs=val/1000000;
tenths=(val-(secs*1000000));
bb.Format(KTimeInSecs,secs,tenths);
_LIT(KFileWrite2,"File write2");
iEikonEnv->InfoWinL(KFileWrite2,bb);
///////////////////////////////////////////////////////////////////////////////////////
perf->FileReadTest1Part1(); // create the file
// look at reading file performance
// see how buffer sizes affect throughput
start.HomeTime();
perf->FileReadTest1Part2();
end.HomeTime();
val=(TInt)(end.Int64()-start.Int64());
secs=val/1000000;
tenths=(val-(secs*1000000));
bb.Format(KTimeInSecs,secs,tenths);
_LIT(KFileRead1,"File read 1");
iEikonEnv->InfoWinL(KFileRead1,bb);
///////////////////////////////////////////////////////////////////////////////////////
start.HomeTime();
perf->FileReadTest1Part3();
end.HomeTime();
val=(TInt)(end.Int64()-start.Int64());
secs=val/1000000;
tenths=(val-(secs*1000000));
bb.Format(KTimeInSecs,secs,tenths);
_LIT(KFileRead2,"File read 2");
iEikonEnv->InfoWinL(KFileRead2,bb);
perf->FileReadTest1Part4(); // delete the file
CleanupStack::PopAndDestroy(perf);
}
void CAppSpecificListView::HandleCommandL(CQikCommand& aCommand)
//
// Handle the commands coming in from the controls that can deliver cmds..
//
{
switch (aCommand.Id())
{
case EAppCmdPerformTests:
PerformTests();
break;
default: // e.g. the back button...
CQikViewBase::HandleCommandL(aCommand);
break;
}
}
void CAppSpecificListView::ViewConstructL()
{
// Loads information about the UI configurations this view supports
// together with definition of each view.
ViewConstructFromResourceL(R_LIST_VIEW_CONFIGURATIONS);
// set the line below app name to be "List title"
TBuf<64>bb;
iEikonEnv->ReadResourceL(bb,R_STR_LIST_TITLE);
ViewContext()->AddTextL(1,bb);
}
void CAppSpecificListView::ViewDeactivated()
{
}
void CAppSpecificListView::ViewActivatedL(
//
// The view is being activated.
//
const TVwsViewId& aPrevViewId,
const TUid aCustomMessageId,
const TDesC8& aCustomMessage)
{
}
//////////////////////////////////////////////////////////////////////////////
CAppSpecificUi::~CAppSpecificUi()
{
}
void CAppSpecificUi::ConstructL()
//
// Normal primary entry point to a Symbian App
//
{
CQikAppUi::ConstructL();
// We create and add a view.
CAppSpecificListView* list=new(ELeave)CAppSpecificListView(*this);
CleanupStack::PushL(list);
list->ConstructL();
AddViewL(*list); // takes ownership
CleanupStack::Pop(list);
SetDefaultViewL(*list);
}
/////////////////////////////////////////////////////////////////////////////////////////////
// Standard Symbian application framework code when creating an application
class CAppSpecificDocument : public CQikDocument
{
protected:
CQikAppUi* CreateAppUiL();
public:
CAppSpecificDocument(CQikApplication& aApp);
static CAppSpecificDocument* NewL(CQikApplication& aApp);
protected:
};
CAppSpecificDocument::CAppSpecificDocument(CQikApplication& aApp) :
CQikDocument(aApp)
{
__DECLARE_NAME(_S("CAppSpecificDocument"));
}
CAppSpecificDocument* CAppSpecificDocument::NewL(CQikApplication& aApp)
{
return(new(ELeave)CAppSpecificDocument(aApp));
}
CQikAppUi* CAppSpecificDocument::CreateAppUiL()
{
return(new(ELeave)CAppSpecificUi);
}
//////////////////////////////////////////////////////////////////////////////////
// Standard Symbian application framework code when creating an application
class CAppSpecificApplication : public CQikApplication
{
protected:
TUid AppDllUid() const;
CApaDocument* CreateDocumentL();
};
TUid CAppSpecificApplication::AppDllUid() const
{
return(KAppSpecificUid);
}
CApaDocument* CAppSpecificApplication::CreateDocumentL()
{
return(CAppSpecificDocument::NewL(*this));
}
//////////////////////////////////////////////////////////////////////////////////
// Standard Symbian application start up code
LOCAL_C CApaApplication* NewApplication()
{
return(new CAppSpecificApplication);
}
GLDEF_C TInt E32Main()
{
return(EikStart::RunApplication(NewApplication));
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -