Frame.js icon indicating copy to clipboard operation
Frame.js copied to clipboard

Frame.perf

Open bishopZ opened this issue 13 years ago • 4 comments

(function(exports){ exports = exports || {}; var Frame = exports.Frame || {}; var tests = {};

Frame.perf = function(){
    Frame.perf('Frame.perf', 'start');
    var args = Array.prototype.slice.apply(arguments);

    var perf = {
        name : args[0],
        start:[],
        stop:[],
        duration:[]
    };
    if(tests.hasOwnProperty(perf.name)){ 
        perf = tests[perf.name];
    } else {
        tests[perf.name] = perf;
    };

    switch(args[1]){
    case 'start':
        var timer = new Date();
        perf.start.push(timer.getTime());
        break;
    case 'stop':
        var timer = new Date();
        perf.stop.push(timer.getTime());
        perf.duration.push( _.last(perf.stop) - _.last(perf.start) );
        //console.log(_.last(perf.stop) , _.last(perf.start),  _.last(perf.stop) - _.last(perf.start))
        break;
    };

    if(Frame.debug >= 3){
        Frame.log('Frame Perf Test ::', args);
    };

    Frame.perf('Frame.perf', 'stop');
    return perf;
};

Frame.perf.report = function(){
    var report = _.reduce(tests, function(m, perf){ 
        m[perf.name] = Math.floor(_.reduce(perf.duration, function(m, num){ return m + num; }, 0) / perf.duration.length);
        return m; 
    }, {});
    return report;
};

Frame.perf.count = function(){
    var report = _.reduce(tests, function(m, perf){ 
        m[perf.name] = perf.duration.length;
        return m; 
    }, {});
    return report;
};

Frame.perf.impact = function(){
    var report = _.reduce(tests, function(m, perf){ 
        m[perf.name] = Math.floor(_.reduce(perf.duration, function(m, d){ m += d; return m; }, 0) / 100);
        return m; 
    }, {});
    return report;
};

Frame.perf.range = function(){
    var report = _.reduce(tests, function(m, perf){ 
        m[perf.name] = Math.floor(_.range(perf.duration) / 100);
        return m; 
    }, {});
    return report;
};


Frame.perf.tests = tests;

})(window);

bishopZ avatar Sep 11 '12 15:09 bishopZ

There is a kind of strange interaction between the Frame.debug levels and the use of Frame.log here in perf. Frame.log needs re-thought-out, and it's use in perf should be considered.

bishopZ avatar Sep 26 '12 15:09 bishopZ

performance.now() is a higher resolution timer. should be used when available. See: http://updates.html5rocks.com/2012/08/When-milliseconds-are-not-enough-performance-now

bishopZ avatar Nov 06 '12 21:11 bishopZ

No reason not to include: https://gist.github.com/addyosmani/5528124

bishopZ avatar May 06 '13 20:05 bishopZ

here is another Perf related library http://lafikl.github.io/perfBar/

bishopZ avatar Aug 19 '14 14:08 bishopZ