mirror of
https://github.com/fluencelabs/js-libp2p-noise
synced 2025-06-21 13:41:41 +00:00
add benchmark
This commit is contained in:
38
benchmarks/benchmark.js
Normal file
38
benchmarks/benchmark.js
Normal file
@ -0,0 +1,38 @@
|
||||
const { Noise } = require('../dist/src/index')
|
||||
const benchmark = require('benchmark')
|
||||
const DuplexPair = require('it-pair/duplex')
|
||||
const PeerId = require('peer-id')
|
||||
|
||||
const bench = async function () {
|
||||
console.log('Initializing handshake benchmark')
|
||||
const initiator = new Noise()
|
||||
const initiatorPeer = await PeerId.createFromJSON({
|
||||
id: '12D3KooWH45PiqBjfnEfDfCD6TqJrpqTBJvQDwGHvjGpaWwms46D',
|
||||
privKey: 'CAESYBtKXrMwawAARmLScynQUuSwi/gGSkwqDPxi15N3dqDHa4T4iWupkMe5oYGwGH3Hyfvd/QcgSTqg71oYZJadJ6prhPiJa6mQx7mhgbAYfcfJ+939ByBJOqDvWhhklp0nqg==',
|
||||
pubKey: 'CAESIGuE+IlrqZDHuaGBsBh9x8n73f0HIEk6oO9aGGSWnSeq'
|
||||
})
|
||||
const responder = new Noise()
|
||||
const responderPeer = await PeerId.createFromJSON({
|
||||
id: '12D3KooWP63uzL78BRMpkQ7augMdNi1h3VBrVWZucKjyhzGVaSi1',
|
||||
privKey: 'CAESYPxO3SHyfc2578hDmfkGGBY255JjiLuVavJWy+9ivlpsxSyVKf36ipyRGL6szGzHuFs5ceEuuGVrPMg/rW2Ch1bFLJUp/fqKnJEYvqzMbMe4Wzlx4S64ZWs8yD+tbYKHVg==',
|
||||
pubKey: 'CAESIMUslSn9+oqckRi+rMxsx7hbOXHhLrhlazzIP61tgodW'
|
||||
})
|
||||
console.log('Init complete, running benchmark')
|
||||
const bench = new benchmark('handshake', {
|
||||
defer: true,
|
||||
fn: async function (deffered) {
|
||||
const [inboundConnection, outboundConnection] = DuplexPair()
|
||||
await Promise.all([
|
||||
initiator.secureOutbound(initiatorPeer, outboundConnection, responderPeer),
|
||||
responder.secureInbound(responderPeer, inboundConnection, initiatorPeer)
|
||||
])
|
||||
deffered.resolve()
|
||||
}
|
||||
})
|
||||
.on("complete", function(stats) {
|
||||
console.log(String(stats.currentTarget))
|
||||
})
|
||||
bench.run({ async: true })
|
||||
}
|
||||
|
||||
bench()
|
Reference in New Issue
Block a user