lnd.xprv/aezeed/bench_test.go
Olaoluwa Osuntokun 120cebef77
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
2018-03-01 17:10:54 -08:00

70 lines
1.2 KiB
Go

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
}