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 UI/UX Design

UI/UX Design by makandra brand

We make sure that your target audience has the best possible experience with your digital product. You get:

  • Design tailored to your audience
  • Proven processes customized to your needs
  • An expert team of experienced designers
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)