paulmillr / noble-secp256k1

Fastest 4KB JS implementation of secp256k1 signatures and ECDH
https://paulmillr.com/noble
MIT License
757 stars 114 forks source link

use mod to improve performance #23

Closed minocoko closed 3 years ago

minocoko commented 3 years ago

a little bit performance improved

bench before:

getPublicKey(utils.randomPrivateKey()) x 2,896 ops/sec @ 345μs/op
sign x 2,108 ops/sec @ 474μs/op
verify x 516 ops/sec @ 1ms/op
recoverPublicKey x 282 ops/sec @ 3ms/op
getSharedSecret aka ecdh x 320 ops/sec @ 3ms/op
getSharedSecret (precomputed) x 3,707 ops/sec @ 269μs/op
Point.fromHex (decompression) x 7,106 ops/sec @ 140μs/op
schnorr.sign x 227 ops/sec @ 4ms/op
schnorr.verify x 284 ops/sec @ 3ms/op

after:

getPublicKey(utils.randomPrivateKey()) x 3,158 ops/sec @ 316μs/op
sign x 2,158 ops/sec @ 463μs/op
verify x 509 ops/sec @ 1ms/op
recoverPublicKey x 281 ops/sec @ 3ms/op
getSharedSecret aka ecdh x 319 ops/sec @ 3ms/op
getSharedSecret (precomputed) x 3,710 ops/sec @ 269μs/op
Point.fromHex (decompression) x 7,276 ops/sec @ 137μs/op
schnorr.sign x 224 ops/sec @ 4ms/op
schnorr.verify x 284 ops/sec @ 3ms/op

about 9% of getPublicKey(high score 11%) about 2.3% of sign(high score 5%) about -%1.4 of verify (high score 1%)

I thank the root reason is small bigint multiply is faster than big one

paulmillr commented 3 years ago

Can you run the bench a few more times?

Get pub key is not important to us, sign and verify is

paulmillr commented 3 years ago

thanks