Read more

JavaScript: How to log execution times to your browser console

Arne Hartherz
March 17, 2014Software engineer at makandra GmbH

If you are trying to inspect timings in JavaScript, you can use console.time and console.timeEnd which will write to your browser console.

Illustration web development

Do you need DevOps-experts?

Your development team has a full backlog? No time for infrastructure architecture? Our DevOps team is ready to support you!

  • We build reliable cloud solutions with Infrastructure as code
  • We are experts in security, Linux and databases
  • We support your dev team to perform
Read more Show archive.org snapshot

Example:

console.time('lengthy calculation');
lengthyCalculation();
console.timeEnd('lengthy calculation');

lengthy calculation: 1.337ms

Note that this allows using console.timeEnd in another context which is helpful when you are doing things asynchronously, or just in different places.

Works in all browsers, including recent Internet Explorers. For older IEs, you may activate Firebug Lite to get these commands.

Posted by Arne Hartherz to makandra dev (2014-03-17 15:05)