Skip to content

Instantly share code, notes, and snippets.

@mrkmg
Created June 19, 2017 14:45
Show Gist options
  • Save mrkmg/85e209e7d863166624f980e088b23772 to your computer and use it in GitHub Desktop.
Save mrkmg/85e209e7d863166624f980e088b23772 to your computer and use it in GitHub Desktop.
Stream Beans Performance Testing
const Benchmark = require('benchmark');
const {PassThrough} = require("stream");
const createStreamBeans = require("streambeans").createStreamBeans;
const suite = new Benchmark.Suite();
const inStreamBeans = new PassThrough();
const outStreamBeans = new PassThrough();
const inStreamNoBeans = new PassThrough();
const outStreamNoBeans = new PassThrough();
const beans = createStreamBeans(inStreamBeans, outStreamBeans);
inStreamNoBeans.pipe(outStreamNoBeans);
function withoutBeansCallback(d) {
outStreamNoBeans.once("data", () => d.resolve());
inStreamNoBeans.write("0");
}
function withBeansCallback(d) {
outStreamBeans.once("data", () => d.resolve());
inStreamBeans.write("0");
}
// add tests
suite
.add('Without StreamBeans', withoutBeansCallback, {defer: true})
.add('With StreamBeans', withBeansCallback, {defer: true})
// add listeners
.on('cycle', function (event) {
console.log(String(event.target));
})
.on('complete', function () {
console.log('Fastest is ' + this.filter('fastest').map('name'));
})
// run async
.run({async: true});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment