github.com/0xmercurial/gomerkt@v0.0.0-20220318235942-262d88c66da9/merkle_bench_test.go (about) 1 package gomerkt 2 3 import ( 4 "math/rand" 5 "testing" 6 "time" 7 ) 8 9 var contents []Content 10 var letterRunes = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") 11 var iterations = 10000 12 13 func init() { 14 rand.Seed(time.Now().UnixNano()) 15 for i := 0; i < 10000; i++ { 16 contents = append(contents, 17 TestSHA256Content{ 18 RandStringRunes(5), 19 }) 20 } 21 } 22 23 func RandStringRunes(n int) string { 24 b := make([]rune, n) 25 for i := range b { 26 b[i] = letterRunes[rand.Intn(len(letterRunes))] 27 } 28 return string(b) 29 } 30 31 func BenchmarkNewTree(b *testing.B) { 32 for i := 0; i < iterations; i++ { 33 NewTree(contents) 34 } 35 } 36 37 func BenchmarkNewTreeCC2(b *testing.B) { 38 for i := 0; i < iterations; i++ { 39 NewTreeCC(2, contents) 40 } 41 } 42 43 func BenchmarkNewTreeCC4(b *testing.B) { 44 for i := 0; i < iterations; i++ { 45 NewTreeCC(4, contents) 46 } 47 } 48 49 func BenchmarkNewTreeCC8(b *testing.B) { 50 for i := 0; i < iterations; i++ { 51 NewTreeCC(8, contents) 52 } 53 }