Performance in web development is critical. End users desire faster responses from the web applications, and optimizing the JavaScript is a demand. The "Profiling" in Chome DevTools is ideal for when a JavaScript CPU profile needs to be recorded. However, in most of the cases, it could be an overkill and something simpler to tell how much time did some piece of code took to execute sounds more suitable. The time() method on the console object could be utilized for that.

Log Time To Console

Let's create an array with a million numbers, and log the duration of creating that array to the console.

var arr = [];
for (var i = 0; i < 1000000; i++) {

The output will be the key that has been specified to the console.time() followed by the time in milliseconds.

Note: the key has to be exclusively determined in console.timeEnd() which matches the key in the console.time().