An alternative to the built-in or adding to profiling tools (the preferred option, I would say): use a timer. I prepared this file:
function Timer(){ var start = new Date ,ended = 'running ...'; return { start: function(){ start = new Date; return this }, stop: function(mssg) { var stoppedAt = (new Date - start); ended = [(mssg ? mssg+': ' : '') ,(stoppedAt/1000)+' sec (+/- 15ms)'].join('') return ended; } ,toString: function(){ return ended; } }; }
You can also use the wrapper function for the runtime of the function. Sort of:
function timedFn(fn){ var timer = new Timer().start(); fn(); console.log(timer.stop('function took ')); }
source share