How to Benchmark Your Javascript?

This is a quick tutorial on how to benchmark your javascript with console.time(“arg”) and console.timeEnd(“arg”)
You would use developer tools to see how fast your script runs.
javascript_benchmark

Example Code:

Array.prototype.proto1 = function(){};
Array.prototype.proto2 = function(){};
Array.prototype.proto3 = function(){};
Array.prototype.proto4 = function(){};
Array.prototype.proto5 = function(){};

var objectLateral = {
  arrayBank: ['Some random string', 'Other String', 'More Stringy Spaghetti']
};

function runThisCode(){
  var things = objectLateral.arrayBank,
      list = "";
	console.time("time");  

  for(var i = 0, ff = things.length; i < ff; i++){
    list += (things[i] + " ");
  }

  console.timeEnd("time");
  return list.trim();
}

runThisCode();

Leave a Reply