-
Notifications
You must be signed in to change notification settings - Fork 445
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clean up some todos & some refactoring (#12)
- Loading branch information
1 parent
f8b2ac1
commit c687899
Showing
14 changed files
with
855 additions
and
539 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,69 @@ | ||
'use strict' | ||
|
||
const Benchmark = require('benchmark') | ||
const crypto = require('crypto') | ||
const map = require('async/map') | ||
const parallel = require('async/parallel') | ||
|
||
const PSG = require('../src') | ||
const utils = require('../test/utils') | ||
|
||
const suite = new Benchmark.Suite('pubsub') | ||
|
||
// Simple benchmark, how many messages can we send from | ||
// one node to another. | ||
|
||
map([0, 1], (i, cb) => { | ||
utils.createNode('/ip4/127.0.0.1/tcp/0', (err, node) => { | ||
if (err) { | ||
return cb(err) | ||
} | ||
|
||
cb(null, { | ||
libp2p: node, | ||
ps: new PSG(node) | ||
}) | ||
}) | ||
}, (err, peers) => { | ||
if (err) { | ||
throw err | ||
} | ||
|
||
parallel([ | ||
(cb) => peers[0].libp2p.dialByPeerInfo(peers[1].libp2p.peerInfo, cb), | ||
(cb) => setTimeout(() => { | ||
peers[0].ps.subscribe('Z') | ||
peers[1].ps.subscribe('Z') | ||
cb(null, peers) | ||
}, 200) | ||
], (err, res) => { | ||
if (err) { | ||
throw err | ||
} | ||
const peers = res[1] | ||
|
||
suite.add('publish and receive', (deferred) => { | ||
const onMsg = (msg) => { | ||
deferred.resolve() | ||
peers[1].ps.removeListener('Z', onMsg) | ||
} | ||
|
||
peers[1].ps.on('Z', onMsg) | ||
|
||
peers[0].ps.publish('Z', crypto.randomBytes(1024)) | ||
}, { | ||
defer: true | ||
}) | ||
|
||
suite | ||
.on('cycle', (event) => { | ||
console.log(String(event.target)) | ||
}) | ||
.on('complete', () => { | ||
process.exit() | ||
}) | ||
.run({ | ||
async: true | ||
}) | ||
}) | ||
}) |
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,26 @@ | ||
'use strict' | ||
|
||
const Benchmark = require('benchmark') | ||
|
||
if (typeof window !== 'undefined') { | ||
window.Benchmark = Benchmark | ||
} | ||
|
||
const utils = require('../src/utils') | ||
|
||
const suite = new Benchmark.Suite('utils') | ||
|
||
let res = [] | ||
|
||
suite.add('randomSeqno', () => { | ||
res.push(utils.randomSeqno()) | ||
}) | ||
|
||
suite | ||
.on('cycle', (event) => { | ||
console.log(String(event.target)) | ||
res = [] | ||
}) | ||
.run({ | ||
async: true | ||
}) |
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 was deleted.
Oops, something went wrong.
Oops, something went wrong.