Measure Function Execution Times

By JoeSimmons Last update May 13, 2009 — Installed 3,099 times.

Improvement

in
Subscribe to Improvement 1 post, 1 voice

w35l3y Scriptwright

You could do something like:

function measure(func, loop)
{
	var init = new Date.valueOf();
	while ( loop-- )
		func();

	return new Date().valueOf() - init;
}

var loops = 10000000;
alert(measure(function1, loops) - measure(function2, loops));

Cross
Presentational HTML allowed.
Use <code> for inline code and <pre> for code blocks. Use &lt; and &gt; for literal < and >.
We help break paragraphs and link your links.
or cancel