diff options
Diffstat (limited to 'merkle_test.go')
| -rw-r--r-- | merkle_test.go | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/merkle_test.go b/merkle_test.go index c486dc1..f3a070e 100644 --- a/merkle_test.go +++ b/merkle_test.go @@ -2,11 +2,13 @@ package main import ( "bytes" + "fmt" + "math/rand" "testing" ) func testMerkle(mtype string) bool { - m := NewMerkle(mtype, 4, "test.db") + m := NewMerkle(mtype, 5, "test.db") root := m.Build() id := m.Size() / 2 proof := m.Proof(id) @@ -27,8 +29,39 @@ func testMerkle(mtype string) bool { func TestMerkle(t *testing.T) { tests := []string{"bfs", "post"} for _, test := range tests { + fmt.Println("Testing", test) if !testMerkle(test) { t.Error(test) } } } + +func BenchmarkBFSMerkle(b *testing.B) { + m := NewBFSMerkle(25, "/mnt/data/bfs.db") + root := make([]byte, hashSize) + m.Read(root, 0) + var id int64 + var proof [][]byte + for i := 0; i < b.N; i++ { + id = rand.Int63n(m.Size()/2) + m.Size()/2 + proof = m.Proof(id) + if len(proof) != int(m.height) { + fmt.Println("error") + } + } +} + +func BenchmarkPostMerkle(b *testing.B) { + m := NewPostMerkle(25, "/mnt/data/post.db") + root := make([]byte, hashSize) + m.Read(root, 0) + var id int64 + var proof [][]byte + for i := 0; i < b.N; i++ { + id = rand.Int63n(m.Size()/2) + m.Size()/2 + proof = m.Proof(id) + if len(proof) != int(m.height) { + fmt.Println("error") + } + } +} |
