-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add request benchmarks, and make benchmarks opt-in with env var
To run benchmarks, do: BENCHMARK=true mocha test/benchmarks
- Loading branch information
Showing
5 changed files
with
560 additions
and
206 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
var Benchmark = require('benchmark'); | ||
var _ = require('@sailshq/lodash'); | ||
|
||
/** | ||
* benchmarx() | ||
* --------------------------- | ||
* @param {String} name | ||
* @param {Array} testFns [array of functions] | ||
* @param {Function} notifier | ||
* @param {Function} done | ||
*/ | ||
module.exports = function benchmarx (name, testFns, done) { | ||
Benchmark.options.minSamples = 500; | ||
var suite = new Benchmark.Suite({ name: name }); | ||
_.each(testFns, function (testFn) { | ||
suite = suite.add(testFn.name, { | ||
defer: true, | ||
fn: function (deferred) { | ||
testFn(function _afterRunningTestFn(err){ | ||
process.nextTick(function _afterEnsuringAsynchronous(){ | ||
if (err) { | ||
console.error('An error occured when attempting to benchmark this code:\n',err); | ||
// Resolve the deferred either way. | ||
} | ||
|
||
deferred.resolve(); | ||
});//</afterwards cb from waiting for nextTick> | ||
});//</afterwards cb from running test fn> | ||
} | ||
});//<suite.add> | ||
});//</each testFn> | ||
|
||
suite.on('cycle', function(event) { | ||
console.log(' •',String(event.target), '(avg ' + (event.target.stats.mean * 1000) + ' ms)'); | ||
}) | ||
.on('complete', function() { | ||
console.log('Fastest is ' + this.filter('fastest').map('name')); | ||
console.log('Slowest is ' + this.filter('slowest').map('name')); | ||
return done(undefined, this); | ||
}) | ||
.run(); | ||
}; |
Oops, something went wrong.