diff --git a/benchmarks/README.md b/benchmarks/README.md index b02525c..18a7c93 100644 --- a/benchmarks/README.md +++ b/benchmarks/README.md @@ -13,8 +13,8 @@ Benchmarks for both pull-mplex and libp2p-mplex This test will send a ping message from the dialer to the listener, which is echo'd back to the dialer. A new stream will be created for each echo. -**pull-mplex**: `node bench.js --lib=pull-mplex` -**libp2p-mplex**: `node bench.js --lib=libp2p-mplex` +**pull-mplex**: `node bench.js --lib=pull-mplex --msgs=100 --runs=3` +**libp2p-mplex**: `node bench.js --lib=libp2p-mplex --msgs=100 --runs=3` You should see results like: ```sh diff --git a/benchmarks/bench.js b/benchmarks/bench.js index a4baec0..9f67d13 100644 --- a/benchmarks/bench.js +++ b/benchmarks/bench.js @@ -11,13 +11,18 @@ const parallel = require('fastparallel')({ const pull = require('pull-stream') const toPull = require('stream-to-pull-stream') +let msgs +let runs + const argv = minimist(process.argv.slice(2), { boolean: 'child', default: { child: true, port: 3000, host: 'localhost', - lib: 'pull-mplex' + lib: 'pull-mplex', + msgs: 100, + runs: 3 } }) @@ -25,6 +30,8 @@ function buildPingPong (cb) { let child let dialer const mplex = require(argv.lib || 'pull-mplex') + msgs = argv.msgs + runs = argv.runs if (argv.child) { child = childProcess.fork(path.join(__dirname, 'mplex-echo.js'), { @@ -85,10 +92,11 @@ function times (num, run, cb) { buildPingPong(function (err, benchPingPong) { if (err) throw err - var run = bench([benchPingPong], 100) + // ping pong `msgs` many messages + const run = bench([benchPingPong], msgs) - // Do it 5 times - times(5, run, function () { + // Do it `runs` many times + times(runs, run, function () { // close the sockets the bad way process.exit(0) })