github.com/Bytom/bytom@v1.1.2-0.20210127130405-ae40204c0b09/crypto/ed25519/chainkd/bench_test.go (about) 1 package chainkd 2 3 import ( 4 "log" 5 "testing" 6 ) 7 8 var ( 9 benchXprv XPrv 10 benchXpub XPub 11 benchMsg = []byte("Hello, world!") 12 benchSig []byte 13 ) 14 15 func init() { 16 var err error 17 benchXprv, err = NewXPrv(nil) 18 if err != nil { 19 log.Fatalln(err) 20 } 21 benchXpub = benchXprv.XPub() 22 benchSig = benchXprv.Sign(benchMsg) 23 } 24 25 func BenchmarkXPrvChildNonHardened(b *testing.B) { 26 for i := 0; i < b.N; i++ { 27 benchXprv.Child(benchMsg, false) 28 } 29 } 30 31 func BenchmarkXPrvChildHardened(b *testing.B) { 32 for i := 0; i < b.N; i++ { 33 benchXprv.Child(benchMsg, true) 34 } 35 } 36 37 func BenchmarkXPubChild(b *testing.B) { 38 for i := 0; i < b.N; i++ { 39 benchXpub.Child(benchMsg) 40 } 41 } 42 43 func BenchmarkXPrvSign(b *testing.B) { 44 for i := 0; i < b.N; i++ { 45 benchXprv.Sign(benchMsg) 46 } 47 } 48 49 func BenchmarkXPubVerify(b *testing.B) { 50 for i := 0; i < b.N; i++ { 51 benchXpub.Verify(benchMsg, benchSig) 52 } 53 }