examples/perf/perf.js
function time(cmd, runs, runNumber, results, cb) {
    var start = process.hrtime();
    exec(cmd, { silent: true }, function() {
        var diff = process.hrtime(start),
            actual = diff[0] * 1e3 + diff[1] / 1e6; // ms

        results.push(actual);
        echo("Performance Run #" + runNumber + ":  %dms", actual);
        if (runs > 1) {
            time(cmd, runs - 1, runNumber + 1, results, cb);
        } else {
            return cb(results);
        }
    });
}
function time(cmd, runs, runNumber, results, cb) {
    var start = process.hrtime();
    exec(cmd, { silent: true }, function() {
        var diff = process.hrtime(start),
            actual = diff[0] * 1e3 + diff[1] / 1e6; // ms

        results.push(actual);
        echo("Performance Run #" + runNumber + ":  %dms", actual);
        if (runs > 1) {
            time(cmd, runs - 1, runNumber + 1, results, cb);
        } else {
            return cb(results);
        }
    });
}
function time ( cmd , runs , runNumber , results , cb ) { var start = process . hrtime ( ) ; exec ( cmd , { silent : true } , function ( ) { var diff = process . hrtime ( start ) , actual = diff [ 0 ] * 1e3 + diff [ 1 ] / 1e6 ; // ms results . push ( actual ) ; echo ( "Performance Run #" + runNumber + ":  %dms" , actual ) ; if ( runs > 1 ) { time ( cmd , runs - 1 , runNumber + 1 , results , cb ) ; } else { return cb ( results ) ; } } ) ; }
Calculates the time for each run for performance
@param {string} cmd cmd
@param {int} runs Total number of runs to do
@param {int} runNumber Current run number
@param {int[]} results Collection results from each run
@param {function} cb Function to call when everything is done
@returns {int[]} calls the cb with all the results
@private
Calculates the time for each run for performance