timeit.js
// If target is an integer, it is already a loop count and will be returned as-is.
If target is an integer, it is already a loop count and will be returned as-is.
If target is an integer it is already a loop count and will be returned as - is .
function calibrateLoopCount( target, testFunc, cb ) {
    var t1, t2, nloops = 1;
    if (!cb) {
        if (target % 1 === 0) return target;
        __calibrating = true;
        do {
            var info = timeit(nloops, testFunc, SILENT);
            nloops = Math.round(nloops * 0.02 / info.wallclock);
        } while (info.wallclock < 0.02);
        nloops = Math.round(nloops * target / 0.02);
        if (nloops <= 0) nloops = 1;
        __calibrating = false;
        return nloops;
    }
    else {
        if (target % 1 === 0) return cb(null, target);
        var stop = false;
        __calibrating = true;
        repeatWhile(
            function(){
                return !stop;
            },
            function(done) {
                timeit(nloops, testFunc, SILENT, function(err, count, elapsed, wallclock) {
                    if (err) return done(err);
                    nloops = Math.round(nloops * 0.02 / wallclock);
                    if (wallclock >= 0.02) {
                        nloops = Math.round(nloops * target / wallclock);
                        stop = true;
                    }
                    done();
                })
            },
            function(err) {
                __calibrating = false;
                if (nloops <= 0) nloops = 1;
                return setImmediate(cb, err, nloops);
            }
        )
    }
}
function calibrateLoopCount ( target , testFunc , cb ) { var t1 , t2 , nloops = 1 ; if ( ! cb ) { if ( target % 1 === 0 ) return target ; __calibrating = true ; do { var info = timeit ( nloops , testFunc , SILENT ) ; nloops = Math . round ( nloops * 0.02 / info . wallclock ) ; } while ( info . wallclock < 0.02 ) ; nloops = Math . round ( nloops * target / 0.02 ) ; if ( nloops <= 0 ) nloops = 1 ; __calibrating = false ; return nloops ; } else { if ( target % 1 === 0 ) return cb ( null , target ) ; var stop = false ; __calibrating = true ; repeatWhile ( function ( ) { return ! stop ; } , function ( done ) { timeit ( nloops , testFunc , SILENT , function ( err , count , elapsed , wallclock ) { if ( err ) return done ( err ) ; nloops = Math . round ( nloops * 0.02 / wallclock ) ; if ( wallclock >= 0.02 ) { nloops = Math . round ( nloops * target / wallclock ) ; stop = true ; } done ( ) ; } ) } , function ( err ) { __calibrating = false ; if ( nloops <= 0 ) nloops = 1 ; return setImmediate ( cb , err , nloops ) ; } ) } }
If target is an integer, it is already a loop count and will be returned as-is.
If target is an integer it is already a loop count and will be returned as - is .