Skip to content

Commit

Permalink
feat: make the benchmark configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobheun committed Feb 14, 2019
1 parent 7d708d0 commit 51b1a2b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
4 changes: 2 additions & 2 deletions benchmarks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 12 additions & 4 deletions benchmarks/bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,27 @@ 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
}
})

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'), {
Expand Down Expand Up @@ -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)
})
Expand Down

0 comments on commit 51b1a2b

Please sign in to comment.