Skip to content

Latest commit

 

History

History
30 lines (23 loc) · 1.34 KB

2016-01-13-tip-to-measure-performance-of-a-javascript-block.md

File metadata and controls

30 lines (23 loc) · 1.34 KB

title: Tip to measure performance of a javascript block tip-number: 13 tip-username: manmadareddy tip-username-profile: https://twitter.com/manmadareddy tip-tldr: For quickly measuring performance of a javascript block, we can use the console functions like console.time(label) and console.timeEnd(label)

  • /en/tip-to-measure-performance-of-a-javascript-block/

For quickly measuring performance of a javascript block, we can use the console functions like console.time(label) and console.timeEnd(label)

console.time('Array initialize');
var arr = new Array(100),
    len = arr.length,
    i;

for (i = 0; i < len; i++) {
    arr[i] = new Object();
}
console.timeEnd('Array initialize'); // Outputs: Array initialize: 0.711ms

More info: Console object, Javascript benchmarking

Demo: jsfiddle - codepen (outputs in browser console)

Note: As Mozilla suggested don't use this for production sites, use it for development purposes only.