forked from TrueCloudLab/frostfs-api-go
[#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:
parent
d005bf0393
commit
e073c996fc
1 changed files with 53 additions and 0 deletions
|
@ -70,3 +70,56 @@ func TestBalanceResponse(t *testing.T) {
|
|||
// verification must fail
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue