Skip to content

Commit

Permalink
Merge pull request cosmos#48 from orijtech/build_tag_for_benchmarks
Browse files Browse the repository at this point in the history
iavl: use build tag gcc to run CLevelDB benchmarks appropriately
  • Loading branch information
ebuchman authored Aug 25, 2017
2 parents c0a9bcb + 48b7e3d commit 222b25c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 36 deletions.
43 changes: 7 additions & 36 deletions iavl/iavl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -584,51 +584,24 @@ func TestIAVLTreeProof(t *testing.T) {
}
}

func BenchmarkImmutableAvlTreeCLevelDB(b *testing.B) {
b.StopTimer()

db := db.NewDB("test", db.CLevelDBBackendStr, "./")
t := NewIAVLTree(100000, db)
// for i := 0; i < 10000000; i++ {
for i := 0; i < 1000000; i++ {
// for i := 0; i < 1000; i++ {
t.Set(i2b(int(RandInt32())), nil)
if i > 990000 && i%1000 == 999 {
t.Save()
}
}
t.Save()

fmt.Println("ok, starting")

runtime.GC()

b.StartTimer()
for i := 0; i < b.N; i++ {
ri := i2b(int(RandInt32()))
t.Set(ri, nil)
t.Remove(ri)
if i%100 == 99 {
t.Save()
}
}

db.Close()
func BenchmarkImmutableAvlTreeMemDB(b *testing.B) {
db := db.NewDB("test", db.MemDBBackendStr, "")
benchmarkImmutableAvlTreeWithDB(b, db)
}

func BenchmarkImmutableAvlTreeMemDB(b *testing.B) {
func benchmarkImmutableAvlTreeWithDB(b *testing.B, db db.DB) {
defer db.Close()

b.StopTimer()

db := db.NewDB("test", db.MemDBBackendStr, "")
t := NewIAVLTree(100000, db)
// for i := 0; i < 10000000; i++ {
for i := 0; i < 1000000; i++ {
// for i := 0; i < 1000; i++ {
t.Set(i2b(int(RandInt32())), nil)
if i > 990000 && i%1000 == 999 {
t.Save()
}
}
b.ReportAllocs()
t.Save()

fmt.Println("ok, starting")
Expand All @@ -644,6 +617,4 @@ func BenchmarkImmutableAvlTreeMemDB(b *testing.B) {
t.Save()
}
}

db.Close()
}
18 changes: 18 additions & 0 deletions iavl/iavl_with_gcc_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// +build gcc

// This file exists because some of the DBs e.g CLevelDB
// require gcc as the compiler before they can ran otherwise
// we'll encounter crashes such as in https://github.com/tendermint/merkleeyes/issues/39

package iavl

import (
"testing"

"github.com/tendermint/tmlibs/db"
)

func BenchmarkImmutableAvlTreeCLevelDB(b *testing.B) {
db := db.NewDB("test", db.CLevelDBBackendStr, "./")
benchmarkImmutableAvlTreeWithDB(b, db)
}

0 comments on commit 222b25c

Please sign in to comment.