HTML and CSS Reference
In-Depth Information
var l = array.length, i = l, item;
while (i--) {
item = array[l - i - 1];
}
}
}, 1000);
This sort of benchmarking utility can be extended to yield more helpful reports.
Highlighting the fastest and slowest tests comes to mind as a useful extension. Listing
4.11 shows a possible solution.
Listing 4.11 Measuring and highlighting extremes
// Record times
var times;
function runTests (tests, view, iterations) {
// ...
(function (name, test) {
// ...
var total = new Date().getTime() - start;
times[name] = total;
// ...
}(label, tests[label]));
// ...
}
function highlightExtremes(view) {
// The timeout is queued after all other timers, ensuring
// that all tests are finished running and the times
// object is populated
setTimeout(function () {
var min = new Date().getTime();
var max = 0;
var fastest, slowest;
for (var label in times) {
if (!times.hasOwnProperty(label)) {
continue;
}
if (times[label] < min) {
min = times[label];
fastest = label;
}
 
Search WWH ::




Custom Search