console.time & console.timeEnd

By  on  

The console.time and console.timeEnd methods allow developers to time any routine and get a duration in milliseconds.  Since JavaScript performance is becoming increasingly important, it's good to know basic techniques for benchmarking routines.  One of the most basic benchmarking tools is console.time with console.timeEnd.

console.time starts the time and console.timeEnd stops the timer and spits out the duration:

// Kick off the timer
console.time('testForEach');

// (Do some testing of a forEach, for example)

// End the timer, get the elapsed time
console.timeEnd('testForEach');

// 4522.303ms (or whatever time elapsed)

Passing a timer name as the first argument allows you to manage concurrent timers.  The console.timeEnd call immediately spits out the elapsed time in milliseconds.

There are more advanced techniques for performance testing and benchmarking but console.time/timeEnd provide a quick manual method for speed testing!

Recent Features

  • By
    CSS Filters

    CSS filter support recently landed within WebKit nightlies. CSS filters provide a method for modifying the rendering of a basic DOM element, image, or video. CSS filters allow for blurring, warping, and modifying the color intensity of elements. Let's have...

  • By
    I’m an Impostor

    This is the hardest thing I've ever had to write, much less admit to myself.  I've written resignation letters from jobs I've loved, I've ended relationships, I've failed at a host of tasks, and let myself down in my life.  All of those feelings were very...

Incredible Demos

Discussion

  1. no necessary label, the default label is default

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!