How to measure time needed to execute a block of code in ColdFusion?
We can measure time needed to execute a block of code in ColdFusion using getTickCount()
method. getTickCount()
method returns a counter in milliseconds.
Syntax:
startTime = getTickCount( );
// Block of code
endTime = getTickCount( );
executionTime = endTime - startTime;
Example:
<cfscript>
startTime = getTickCount( );
// Block of code
cfloop( from = "1", to = "10", index = "i" ){
sleep( i * 100 );
}
endTime = getTickCount( );
executionTime = endTime - startTime;
writeOutput( executionTime );
</cfscript>