[#3] signature: Add benchmarks

Add benchmarks for sign and verify methods

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
Dmitrii Stepanov 2023-02-28 14:43:13 +03:00
parent d005bf0393
commit e073c996fc

View file

@ -70,3 +70,56 @@ func TestBalanceResponse(t *testing.T) {
// verification must fail // verification must fail
require.Error(t, VerifyServiceMessage(req)) require.Error(t, VerifyServiceMessage(req))
} }
func BenchmarkSignRequest(b *testing.B) {
key, _ := crypto.LoadPrivateKey("Kwk6k2eC3L3QuPvD8aiaNyoSXgQ2YL1bwS5CP1oKoA9waeAze97s")
b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
b.StopTimer()
dec := new(accounting.Decimal)
dec.SetValue(100)
body := new(accounting.BalanceResponseBody)
body.SetBalance(dec)
meta := new(session.ResponseMetaHeader)
meta.SetTTL(1)
resp := new(accounting.BalanceResponse)
resp.SetBody(body)
resp.SetMetaHeader(meta)
b.StartTimer()
SignServiceMessage(key, resp)
}
}
func BenchmarkVerifyRequest(b *testing.B) {
key, _ := crypto.LoadPrivateKey("Kwk6k2eC3L3QuPvD8aiaNyoSXgQ2YL1bwS5CP1oKoA9waeAze97s")
b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
b.StopTimer()
dec := new(accounting.Decimal)
dec.SetValue(100)
body := new(accounting.BalanceResponseBody)
body.SetBalance(dec)
meta := new(session.ResponseMetaHeader)
meta.SetTTL(1)
resp := new(accounting.BalanceResponse)
resp.SetBody(body)
resp.SetMetaHeader(meta)
SignServiceMessage(key, resp)
b.StartTimer()
VerifyServiceMessage(resp)
}
}