Signature verification speed vs matching engine speed
helinwang opened this issue · comments
Helin Wang commented
Tested on AMD Threadripper 1950x (3.5 GHz) with single thread code.
Signature Verification
BLS signature (used for both consensus system and user transaction signing, user transaction signing can be switched to ESCDA):
5 seconds: 11500 verifications.
ESCDA (https://github.com/ethereum/go-ethereum/tree/master/crypto):
5 seconds: 41000 verifications.
Matching Engine
Single order book, 5 seconds: 10000000 limit orders
Conclution
Matching Engine is two orders of magnitude faster than signature verification.
Code:
func TestOrderBookSpeed(t *testing.T) {
book := newOrderBook()
const total = 10000000
orders := make([]Order, total)
for i := 0; i < total; i++ {
orders[i].Price = uint64(1000 + rand.Intn(1000))
orders[i].Quant = uint64(rand.Intn(10000) + 10)
orders[i].SellSide = rand.Intn(2) == 0
}
start := time.Now()
for _, o := range orders {
book.Limit(o)
}
fmt.Println(time.Now().Sub(start), total)
}
func TestSignVerifySpeed(t *testing.T) {
var sk bls.SecretKey
msg := string(hexutil.MustDecode("0xce0677bb30baa8cf067c88db9811f4333d131bf8bcf12fe7065d211dce971008"))
sign := sk.Sign(msg)
pk := sk.GetPublicKey()
start := time.Now()
for i := 0; i < 11500; i++ {
sign.Verify(pk, msg)
}
fmt.Println(time.Now().Sub(start))
}
func TestEtherVerifySpeed(t *testing.T) {
testmsg := hexutil.MustDecode("0xce0677bb30baa8cf067c88db9811f4333d131bf8bcf12fe7065d211dce971008")
testsig := hexutil.MustDecode("0x90f27b8b488db00b00606796d2987f6a5f59ae62ea05effe84fef5b8b0e549984a691139ad57a3f0b906637673aa2f63d1f55cb1a69199d4009eea23ceaddc9301")
testpubkey := hexutil.MustDecode("0x04e32df42865e97135acfb65f3bae71bdc86f4d49150ad6a440b6f15878109880a0a2b2667f7e725ceea70c673093bf67663e0312623c8e091b13cf2c0f11ef652")
start := time.Now()
sig := testsig[:len(testsig)-1] // remove recovery id
for i := 0; i < 41000; i++ {
if !crypto.VerifySignature(testpubkey, testmsg, sig) {
panic("verify failed")
}
}
fmt.Println(time.Now().Sub(start))
}
Helin Wang commented
This is a note, not an issue.