Rate this script:  I Love it  /   I Hate it

Function.prototype.bench


Code


Function.prototype.bench = function(st){
        var self = this;
        return function(){
                var start = new Date();
                var res = self.apply(this,arguments);
                var end = new Date();
                // to customize
                window.status = st + " : " + (end-start);
                return res;
        }
}
// example
var func = function(){
        var array = [];
        for(var i=0;i<100000;i++){
                array.push(i)
        }
}
// create [benchmark enabled] function
var func_bench = func.bench("create Array(100000)");
func_bench();

// works in transparent
func = func.bench()
 

 

 
Function.prototype.bench scripts | Function.prototype.bench snippet | Function.prototype.bench example | Function.prototype.bench tutorial | Function.prototype.bench code