lib/benchmark.js
function doAsyncBench(fn, callback) {

		var fnOverhead,
		    pretotal,
		    result,
		    args,
		    i;

		if (benchRunning > 0) {

			// Keep function optimized by not leaking the `arguments` object
			args = new Array(arguments.length);
			for (i = 0; i < args.length; i++) args[i] = arguments[i];

			benchQueue.push(args);
			return;
		}

		benchRunning++;

		// See how many times we can get it to run for 300ms
		Collection.Function.doTime(300, fn, function(err, runs, elapsed) {

			// See how the baseline latency is like
			Blast.getEventLatencyBaseline(function(err, median) {
				asyncTest(fn, runs, median+(getFunctionOverhead(runs)*8), function asyncDone(err, result) {

					var next,
					    name;

					// Call the callback
					if (callback) {
						result.name = fn.name || '';
						callback(err, result);
					} else {
						name = fn.name || '';
						if (name) name = 'for "' + name + '" ';

						console.log('Benchmark ' + name + 'did ' + Bound.Number.humanize(result.ops) + '/s (' + Bound.Number.humanize(result.iterations) + ' iterations)');
					}

					benchRunning--;

					// Schedule a next benchmark
					if (benchRunning == 0 && benchQueue.length > 0) {

						// Get the top of the queue
						next = benchQueue.shift();

						Blast.setImmediate(function() {
							doAsyncBench.apply(null, next);
						});
					}
				});
			});
		});
	}
function doAsyncBench(fn, callback) {

		var fnOverhead,
		    pretotal,
		    result,
		    args,
		    i;

		if (benchRunning > 0) {

			// Keep function optimized by not leaking the `arguments` object
			args = new Array(arguments.length);
			for (i = 0; i < args.length; i++) args[i] = arguments[i];

			benchQueue.push(args);
			return;
		}

		benchRunning++;

		// See how many times we can get it to run for 300ms
		Collection.Function.doTime(300, fn, function(err, runs, elapsed) {

			// See how the baseline latency is like
			Blast.getEventLatencyBaseline(function(err, median) {
				asyncTest(fn, runs, median+(getFunctionOverhead(runs)*8), function asyncDone(err, result) {

					var next,
					    name;

					// Call the callback
					if (callback) {
						result.name = fn.name || '';
						callback(err, result);
					} else {
						name = fn.name || '';
						if (name) name = 'for "' + name + '" ';

						console.log('Benchmark ' + name + 'did ' + Bound.Number.humanize(result.ops) + '/s (' + Bound.Number.humanize(result.iterations) + ' iterations)');
					}

					benchRunning--;

					// Schedule a next benchmark
					if (benchRunning == 0 && benchQueue.length > 0) {

						// Get the top of the queue
						next = benchQueue.shift();

						Blast.setImmediate(function() {
							doAsyncBench.apply(null, next);
						});
					}
				});
			});
		});
	}
function doAsyncBench ( fn , callback ) { var fnOverhead , pretotal , result , args , i ; if ( benchRunning > 0 ) { // Keep function optimized by not leaking the `arguments` object args = new Array ( arguments . length ) ; for ( i = 0 ; i < args . length ; i ++ ) args [ i ] = arguments [ i ] ; benchQueue . push ( args ) ; return ; } benchRunning ++ ; // See how many times we can get it to run for 300ms Collection . Function . doTime ( 300 , fn , function ( err , runs , elapsed ) { // See how the baseline latency is like Blast . getEventLatencyBaseline ( function ( err , median ) { asyncTest ( fn , runs , median + ( getFunctionOverhead ( runs ) * 8 ) , function asyncDone ( err , result ) { var next , name ; // Call the callback if ( callback ) { result . name = fn . name || '' ; callback ( err , result ) ; } else { name = fn . name || '' ; if ( name ) name = 'for "' + name + '" ' ; console . log ( 'Benchmark ' + name + 'did ' + Bound . Number . humanize ( result . ops ) + '/s (' + Bound . Number . humanize ( result . iterations ) + ' iterations)' ) ; } benchRunning -- ; // Schedule a next benchmark if ( benchRunning == 0 && benchQueue . length > 0 ) { // Get the top of the queue next = benchQueue . shift ( ) ; Blast . setImmediate ( function ( ) { doAsyncBench . apply ( null , next ) ; } ) ; } } ) ; } ) ; } ) ; }
Function that sets up the asynchronous benchmark

@author   Jelle De Loecker   <jelle@develry.be>
@since    0.1.2
@version  0.6.0

@param    {Function}   fn
@param    {Function}   callback

@return   {Object}
Function that sets up the asynchronous benchmark