Skip to content

Instantly share code, notes, and snippets.

@panva

panva/bench.js Secret

Created September 3, 2019 12:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save panva/7d4c54c9e2de3c4daa310ba6719cf98b to your computer and use it in GitHub Desktop.
Save panva/7d4c54c9e2de3c4daa310ba6719cf98b to your computer and use it in GitHub Desktop.
const { sign, verify, generateKeyPairSync } = require('crypto')
const Benchmark = require('benchmark')
const ecdsaSignatures = require('./lib/help/ecdsa_signatures')
const { privateKey, publicKey } = generateKeyPairSync('ec', { namedCurve: 'P-256' })
let suite = new Benchmark.Suite()
const PAYLOAD = Buffer.from('foo')
const SIGNATURE = sign('sha256', PAYLOAD, {
key: privateKey,
dsaEncoding: 'ieee-p1363'
})
suite.add('sign ieee-p1363 via dsaEncoding', () => {
sign('sha256', PAYLOAD, {
key: privateKey,
dsaEncoding: 'ieee-p1363'
})
})
.add('sign ieee-p1363 via module', () => {
ecdsaSignatures.derToJose(sign('sha256', PAYLOAD, {
key: privateKey
}), 'ES256')
})
.on('cycle', (event) => {
console.log(String(event.target))
})
.on('complete', function () {
console.log('Fastest is ' + this.filter('fastest').map('name'))
})
.run()
suite = new Benchmark.Suite()
suite.add('verify ieee-p1363 via dsaEncoding', () => {
verify('sha256', PAYLOAD, {
key: publicKey,
dsaEncoding: 'ieee-p1363'
}, SIGNATURE)
})
.add('verify ieee-p1363 via module', () => {
verify('sha256', PAYLOAD, {
key: publicKey
}, ecdsaSignatures.joseToDer(SIGNATURE, 'ES256'))
})
.on('cycle', (event) => {
console.log(String(event.target))
})
.on('complete', function () {
console.log('Fastest is ' + this.filter('fastest').map('name'))
})
.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment