Trinithis
09-15-2007, 04:49 PM
1) CODE TITLE: Clocker
2) AUTHOR NAME/NOTES: Thomas Eding
3) DESCRIPTION: Clocks and analyzes function speeds.
4) URL TO CODE: http://trinithis.awardspace.com/Clocker/Clocker.js
Use for analyzing speeds during development:
function a(){...}
function b(){...}
Clocker.time(a, 100); //100 iterations of a
Clocker.time(b, 100); //100 iterations of b
alert(Clocker.analyze()); //returns fastest trial(s) based on ms/iter
Clocker.reset(); //clears the trial set
Clocker.run(a, 100); //run a for at least 100ms
Clocker.run(b, 100); //run b for at least 100ms
alert(Clocker.analyze()); //returns fastest trial(s) based on ms/iter
The code is smart enough to ignore the code stall of alert(), confirm(), and prompt() that might be in the tested functions. You can also name each trial by adding an extra argument to time() or run(). By default, the trials are named '1', '2', etc.
NOTE: You should not use a Clocker.run() and a Clocker.time() in the same trial set because their algorithm times differ. If it is necessay, try using: http://trinithis.awardspace.com/Clocker/Clocker2.js or http://trinithis.awardspace.com/Clocker/Clocker3.js.
2) AUTHOR NAME/NOTES: Thomas Eding
3) DESCRIPTION: Clocks and analyzes function speeds.
4) URL TO CODE: http://trinithis.awardspace.com/Clocker/Clocker.js
Use for analyzing speeds during development:
function a(){...}
function b(){...}
Clocker.time(a, 100); //100 iterations of a
Clocker.time(b, 100); //100 iterations of b
alert(Clocker.analyze()); //returns fastest trial(s) based on ms/iter
Clocker.reset(); //clears the trial set
Clocker.run(a, 100); //run a for at least 100ms
Clocker.run(b, 100); //run b for at least 100ms
alert(Clocker.analyze()); //returns fastest trial(s) based on ms/iter
The code is smart enough to ignore the code stall of alert(), confirm(), and prompt() that might be in the tested functions. You can also name each trial by adding an extra argument to time() or run(). By default, the trials are named '1', '2', etc.
NOTE: You should not use a Clocker.run() and a Clocker.time() in the same trial set because their algorithm times differ. If it is necessay, try using: http://trinithis.awardspace.com/Clocker/Clocker2.js or http://trinithis.awardspace.com/Clocker/Clocker3.js.