JavaScript - Profiling
SunSpider JavaScript Benchmark
JSLitmus
http://mootools.net/slickspeed/
http://benchmarkjs.com/
http://jsperf.com/
<script type="text/javascript">
profileInfo = {}
function startProfileTimer(reason) {
if (typeof(profileInfo[reason]) == "undefined") {
profileInfo[reason] = {};
profileInfo[reason].counter = 0;
profileInfo[reason].totalTime = 0;
}
profileInfo[reason].startTime = new Date();
profileInfo[reason].counter = profileInfo[reason].counter + 1;
}
function endProfileTimer(reason) {
var endTime = new Date();
var startTime = profileInfo[reason].startTime;
var diff = endTime.valueOf() - startTime.valueOf();
profileInfo[reason].totalTime = profileInfo[reason].totalTime + diff;
}
</script>
The startProfileTimer and endProfileTimer function takes one parameter which is a string. In order for this to work, the string that you specify for startProfileTimer must exactly equal with the string you specify for endProfileTimer. This pair of functions capture the number of times a particular code block is executed, and the total amount that it take to execute this code block. At the end, you must inspect the profileInfo variable and compute the averages.
Microsoft Developer Tool and Firebug both have ability to profile your code. Give that a try too.
page revision: 4, last edited: 07 Mar 2016 00:08