Debugging bottlenecks in Javascript

For most bottleneck debugging Chrome Inspector’s profiles view in invaluable until a bottleneck is identified and then it becomes a bit cumbersome. I like to have a quicker overview of the piece i’m working on optimizing.

I use this small and easy timer snippet.

var timer = {
    start: function() {
        timer.t = new Date().getTime();
    },

    log: function(str) {
        str = str ? str : 'Execution time: ';
        console.log(str + ((new Date().getTime()) - timer.t));
    }
};

//Example
(function() {
    //...

    timer.start();  

    //...

    timer.log('first landmark passed: ');

    //...

    timer.log('second landmark passed: ');

    //...
})();

Leave a Comment