mirror of
https://github.com/lightningnetwork/lnd.git
synced 2024-11-19 01:43:16 +01:00
aezeed: add a set of benchmarks
In this commit we add a set of benchmarks to be able to measure the enciphering and deciphering speed of the current scheme with the current scrypt parameters. On my laptop I get about 100ms per attempt: ⛰ go test -run=XXX -bench=. goos: darwin goarch: amd64 pkg: github.com/lightningnetwork/lnd/aezeed BenchmarkToMnenonic-4 10 102287840 ns/op BenchmarkFromMnenonic-4 10 105874973 ns/op PASS ok github.com/lightningnetwork/lnd/aezeed 3.036s
This commit is contained in:
parent
eb3b5196e1
commit
120cebef77
69
aezeed/bench_test.go
Normal file
69
aezeed/bench_test.go
Normal file
@ -0,0 +1,69 @@
|
||||
package aezeed
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
mnemonic Mnemonic
|
||||
|
||||
seed *CipherSeed
|
||||
)
|
||||
|
||||
// BenchmarkFrommnemonic benchmarks the process of converting a cipher seed
|
||||
// (given the salt), to an enciphered mnemonic.
|
||||
func BenchmarkTomnemonic(b *testing.B) {
|
||||
scryptN = 32768
|
||||
scryptR = 8
|
||||
scryptP = 1
|
||||
|
||||
pass := []byte("1234567890abcedfgh")
|
||||
cipherSeed, err := New(0, nil, time.Now())
|
||||
if err != nil {
|
||||
b.Fatalf("unable to create seed: %v", err)
|
||||
}
|
||||
|
||||
var r Mnemonic
|
||||
for i := 0; i < b.N; i++ {
|
||||
r, err = cipherSeed.ToMnemonic(pass)
|
||||
if err != nil {
|
||||
b.Fatalf("unable to encipher: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
b.ReportAllocs()
|
||||
|
||||
mnemonic = r
|
||||
}
|
||||
|
||||
// BenchmarkToCipherSeed benchmarks the process of deciphering an existing
|
||||
// enciphered mnemonic.
|
||||
func BenchmarkToCipherSeed(b *testing.B) {
|
||||
scryptN = 32768
|
||||
scryptR = 8
|
||||
scryptP = 1
|
||||
|
||||
pass := []byte("1234567890abcedfgh")
|
||||
cipherSeed, err := New(0, nil, time.Now())
|
||||
if err != nil {
|
||||
b.Fatalf("unable to create seed: %v", err)
|
||||
}
|
||||
|
||||
mnemonic, err := cipherSeed.ToMnemonic(pass)
|
||||
if err != nil {
|
||||
b.Fatalf("unable to create mnemonic: %v", err)
|
||||
}
|
||||
|
||||
var s *CipherSeed
|
||||
for i := 0; i < b.N; i++ {
|
||||
s, err = mnemonic.ToCipherSeed(pass)
|
||||
if err != nil {
|
||||
b.Fatalf("unable to decipher: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
b.ReportAllocs()
|
||||
|
||||
seed = s
|
||||
}
|
Loading…
Reference in New Issue
Block a user