Skip to content
Simple component to time various sections of code. Supports multiple timers, and will list or graph results.
Pull request Compare This branch is even with webflint:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


The benchmark is a simple component that measures the execution time of code blocks.
	To use the benchmark Component, you instantiate the compontent:
	<cfset timer = createObject("component", "com.webflint.benchmarks.Benchmark").init() />
	You can then call the start and stop functions to capture execution times:
	<cfset timer.start("Example Timer") />
		run some code between start and stop
	<cfset timer.stop("Example Timer") />	
	the metadata for a timer includes the total execution time for all occurances and
				the number of times the timer was started and stopped.
	<cfset result = timer.get("Example Timer") />
	<cfoutput>The Example Timer took: #result.duration#ms, and ran #result.count# times</cfoutput>
	You may register any number of timers by specifying a new name for the timer.start( name )
	timers can also be nested.
	All running timers can be returned by calling the timer.getAll() function which returns
	a structure of metadata for all the timers.  
	A couple functions can output the current benchmarks at any given time and give you
	a visual view of the timers:

	a html ordered list of the current benchmarks
	A png of the current benchmarks, yay CFCHART

	Or you can build your own output templates.
	A simple snippet can be added to the bottom of a page to show this information at the 
	end of a request, and you can display the results as you wish.
	<cfset allTimers = timer.getAll() />
	<p><strong>Benchmark results</strong>												
		<cfloop collection="#allTimers#" item="timer">
			<li>#timer#: (#allTimers[timer].count#) #allTimers[timer].duration#ms</li>
Something went wrong with that request. Please try again.