Last Updated: January 28, 2019
· justgoscha

Quick performance test on JavaScript console

Quickly test performance of a function on the console (in the browser) with:

var i =; 

Or make a helper function, like this:

function performanceTest(testFunction, iterations){
  var sum = 0;
  var start =;
  for(var i = 0; i<iterations;i++){

  return time;

And use it like this:

performanceTest(function(){Math.random()*Math.random()}, 1000)

In NodeJS you would need to use process.hrtime() instead of and it behaves a little differently.

3 Responses
Add your response

Didn't know that existed. I always used new Date().

Good tip :O

over 1 year ago ·


over 1 year ago ·

Nice to know! :)

You could add the info that doesn't call console.log() implicit, what was my expectation after reading your code example.

over 1 year ago ·