Skip to content

Commit

Permalink
Update benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
sc0Vu committed Oct 26, 2020
1 parent 696ed05 commit 030d867
Show file tree
Hide file tree
Showing 4 changed files with 640 additions and 94 deletions.
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,19 @@ v12.18.1
> secp256k1-benchmark@0.0.0 start /Users/peterlai/Desktop/Projects/js-secp256k1/benchmarks
> node index.js
Secp256k1 WASM (current) x 3,911 ops/sec ±0.84% (96 runs sampled)
GYP Binding (secp256k1) x 1,162 ops/sec ±0.67% (92 runs sampled)
Pure JS (elliptic) x 1,255 ops/sec ±0.16% (96 runs sampled)
Secp256k1 WASM (current) x 3,979 ops/sec ±0.22% (94 runs sampled)
Secp256k1 0.2.1 WASM (current) x 3,865 ops/sec ±1.08% (96 runs sampled)
GYP Binding (secp256k1) x 1,156 ops/sec ±1.17% (93 runs sampled)
Pure JS (elliptic) x 1,249 ops/sec ±0.57% (96 runs sampled)
Sign: fastest is Secp256k1 WASM (current)
Secp256k1 WASM (current) x 1,671 ops/sec ±1.32% (96 runs sampled)
Secp256k1 WASM (current) x 2,275 ops/sec ±0.55% (98 runs sampled)
Secp256k1 0.2.1 WASM (current) x 1,734 ops/sec ±0.07% (97 runs sampled)
GYP Binding (secp256k1):
Pure JS (elliptic) x 393 ops/sec ±2.32% (77 runs sampled)
Pure JS (elliptic) x 460 ops/sec ±0.32% (93 runs sampled)
Recover: fastest is Secp256k1 WASM (current)
Secp256k1 WASM (current) x 1,647 ops/sec ±1.68% (87 runs sampled)
Secp256k1 WASM (current) x 2,757 ops/sec ±0.08% (96 runs sampled)
GYP Binding (secp256k1):
Pure JS (elliptic) x 499 ops/sec ±2.94% (84 runs sampled)
Pure JS (elliptic) x 548 ops/sec ±0.34% (95 runs sampled)
Verify: fastest is Secp256k1 WASM (current)
```

Expand Down
91 changes: 48 additions & 43 deletions benchmarks/index.js
Original file line number Diff line number Diff line change
@@ -1,54 +1,59 @@
const benchmark = require('benchmark')
const secp256k121Async = require('js-secp256k1/dist/node-bundle.js')
const secp256k1Async = require('../dist/node-bundle.js')
const obindings = require('secp256k1')
const elliptic = require('elliptic')
const ec = new elliptic.ec('secp256k1')

secp256k1Async().then(function (secp256k1Wasm) {
const privkeyBuf = Buffer.from([70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70])
const ecprivkey = ec.keyFromPrivate(privkeyBuf)
const msg = require('crypto').randomBytes(32)
const pubkey = secp256k1Wasm.privkeyToPubkey(privkeyBuf)
const cpubkey = secp256k1Wasm.serializePubkey(pubkey, true)
new benchmark.Suite('Sign')
.add('Secp256k1 WASM (current)', () => secp256k1Wasm.sign(msg, privkeyBuf))
.add('GYP Binding (secp256k1)', () => obindings.sign(msg, privkeyBuf))
.add('Pure JS (elliptic)', () => ecprivkey.sign(msg))
.on('cycle', (event) => {
console.log(String(event.target))
})
.on('complete', function () {
console.log(`${this.name}: fastest is ${this.filter('fastest').map('name')}`)
})
.run()
secp256k121Async().then(function (secp256k121Wasm) {
const privkeyBuf = Buffer.from([70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70])
const ecprivkey = ec.keyFromPrivate(privkeyBuf)
const msg = require('crypto').randomBytes(32)
const pubkey = secp256k1Wasm.privkeyToPubkey(privkeyBuf)
const cpubkey = secp256k1Wasm.serializePubkey(pubkey, true)
new benchmark.Suite('Sign')
.add('Secp256k1 WASM (current)', () => secp256k1Wasm.sign(msg, privkeyBuf))
.add('Secp256k1 0.2.1 WASM (current)', () => secp256k121Wasm.sign(msg, privkeyBuf))
.add('GYP Binding (secp256k1)', () => obindings.sign(msg, privkeyBuf))
.add('Pure JS (elliptic)', () => ecprivkey.sign(msg))
.on('cycle', (event) => {
console.log(String(event.target))
})
.on('complete', function () {
console.log(`${this.name}: fastest is ${this.filter('fastest').map('name')}`)
})
.run()

const sig = secp256k1Wasm.sign(msg, privkeyBuf)
const sig2 = {
r: sig.signature.slice(0, 32),
s: sig.signature.slice(32)
}
const sig = secp256k1Wasm.sign(msg, privkeyBuf)
const sig2 = {
r: sig.signature.slice(0, 32),
s: sig.signature.slice(32)
}

new benchmark.Suite('Recover')
.add('Secp256k1 WASM (current)', () => secp256k1Wasm.recover(msg, sig.signature, sig.recovery))
.add('GYP Binding (secp256k1)', () => obindings.recover(msg, sig.signature, sig.recovery))
.add('Pure JS (elliptic)', () => ec.recoverPubKey(msg, sig2, sig.recovery))
.on('cycle', (event) => {
console.log(String(event.target))
})
.on('complete', function () {
console.log(`${this.name}: fastest is ${this.filter('fastest').map('name')}`)
})
.run()
new benchmark.Suite('Recover')
.add('Secp256k1 WASM (current)', () => secp256k1Wasm.recover(msg, sig.signature, sig.recovery))
.add('Secp256k1 0.2.1 WASM (current)', () => secp256k121Wasm.recover(msg, sig.signature, sig.recovery))
.add('GYP Binding (secp256k1)', () => obindings.recover(msg, sig.signature, sig.recovery))
.add('Pure JS (elliptic)', () => ec.recoverPubKey(msg, sig2, sig.recovery))
.on('cycle', (event) => {
console.log(String(event.target))
})
.on('complete', function () {
console.log(`${this.name}: fastest is ${this.filter('fastest').map('name')}`)
})
.run()

new benchmark.Suite('Verify')
.add('Secp256k1 WASM (current)', () => secp256k1Wasm.verify(msg, sig.signature, pubkey))
.add('GYP Binding (secp256k1)', () => obindings.verify(msg, sig.signature, cpubkey))
.add('Pure JS (elliptic)', () => ecprivkey.verify(msg, sig2))
.on('cycle', (event) => {
console.log(String(event.target))
})
.on('complete', function () {
console.log(`${this.name}: fastest is ${this.filter('fastest').map('name')}`)
})
.run()
new benchmark.Suite('Verify')
.add('Secp256k1 WASM (current)', () => secp256k1Wasm.verify(msg, sig.signature, pubkey))
.add('GYP Binding (secp256k1)', () => obindings.verify(msg, sig.signature, cpubkey))
.add('Pure JS (elliptic)', () => ecprivkey.verify(msg, sig2))
.on('cycle', (event) => {
console.log(String(event.target))
})
.on('complete', function () {
console.log(`${this.name}: fastest is ${this.filter('fastest').map('name')}`)
})
.run()
})
})

0 comments on commit 030d867

Please sign in to comment.