scripts/gauntlet.js
function sample(test, asap, minDuration, sampleSize, done) {
    var count = 0;
    var totalDuration = 0;
    var sampleDurations = [];
    next();
    function next() {
        measure(function (done) {
            test(asap, done);
        }, function (error, results, duration) {
            if (error) {
                done(error);
            }
            if (sampleDurations.length < sampleSize) {
                sampleDurations.push(duration);
            } else if (Math.random() < 1 / count) {
                sampleDurations.splice(Math.floor(Math.random() * sampleDurations.length), 1);
                sampleDurations.push(duration);
            }
            totalDuration += duration;
            count++;
            if (totalDuration >= minDuration) {
                done(null, {
                    name: test.name,
                    subjectName: asap.name,
                    count: count,
                    totalDuration: totalDuration,
                    averageFrequency: count / totalDuration,
                    averageDuration: totalDuration / count,
                    averageOpsHz: count / totalDuration,
                    sampleDurations: sampleDurations
                });
            } else {
                next();
            }
        });
    }
}
function sample(test, asap, minDuration, sampleSize, done) {
    var count = 0;
    var totalDuration = 0;
    var sampleDurations = [];
    next();
    function next() {
        measure(function (done) {
            test(asap, done);
        }, function (error, results, duration) {
            if (error) {
                done(error);
            }
            if (sampleDurations.length < sampleSize) {
                sampleDurations.push(duration);
            } else if (Math.random() < 1 / count) {
                sampleDurations.splice(Math.floor(Math.random() * sampleDurations.length), 1);
                sampleDurations.push(duration);
            }
            totalDuration += duration;
            count++;
            if (totalDuration >= minDuration) {
                done(null, {
                    name: test.name,
                    subjectName: asap.name,
                    count: count,
                    totalDuration: totalDuration,
                    averageFrequency: count / totalDuration,
                    averageDuration: totalDuration / count,
                    averageOpsHz: count / totalDuration,
                    sampleDurations: sampleDurations
                });
            } else {
                next();
            }
        });
    }
}
function sample ( test , asap , minDuration , sampleSize , done ) { var count = 0 ; var totalDuration = 0 ; var sampleDurations = [ ] ; next ( ) ; function next ( ) { measure ( function ( done ) { test ( asap , done ) ; } , function ( error , results , duration ) { if ( error ) { done ( error ) ; } if ( sampleDurations . length < sampleSize ) { sampleDurations . push ( duration ) ; } else if ( Math . random ( ) < 1 / count ) { sampleDurations . splice ( Math . floor ( Math . random ( ) * sampleDurations . length ) , 1 ) ; sampleDurations . push ( duration ) ; } totalDuration += duration ; count ++ ; if ( totalDuration >= minDuration ) { done ( null , { name : test . name , subjectName : asap . name , count : count , totalDuration : totalDuration , averageFrequency : count / totalDuration , averageDuration : totalDuration / count , averageOpsHz : count / totalDuration , sampleDurations : sampleDurations } ) ; } else { next ( ) ; } } ) ; } }
measures iterations of the test for a duration, maintaining a representative sample of the measurements up to a given size
measures iterations of the test for a duration maintaining a representative sample of the measurements up to a given size