diff options
| author | Thibaut Horel <thibaut.horel@gmail.com> | 2016-05-04 18:05:00 -0400 |
|---|---|---|
| committer | Thibaut Horel <thibaut.horel@gmail.com> | 2016-05-04 18:05:00 -0400 |
| commit | 5185b1ea87c04fcfe6d96797ac7a0d363bf1c4de (patch) | |
| tree | cb1a0311f52da1348d491003cb88d1a78a4aabd1 | |
| parent | 0408051b166871cbe48c582a7ab8e56c4bcb1961 (diff) | |
| download | pos-5185b1ea87c04fcfe6d96797ac7a0d363bf1c4de.tar.gz | |
Add benchmarks for proof extraction
| -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") + } + } +} |
