mirror of
https://github.com/fluencelabs/tendermint
synced 2025-04-25 14:52:17 +00:00
updated benchmark
This commit is contained in:
parent
f7873d6e2b
commit
850144f3e7
@ -53,12 +53,12 @@ func TestImmutableAvlPutHasGetRemove(t *testing.T) {
|
||||
var val Value
|
||||
var updated bool
|
||||
|
||||
ranrec := func() *record {
|
||||
randomRecord := func() *record {
|
||||
return &record{ randstr(20), randstr(20) }
|
||||
}
|
||||
|
||||
for i := range records {
|
||||
r := ranrec()
|
||||
r := randomRecord()
|
||||
records[i] = r
|
||||
tree, updated = tree.Put(r.key, String(""))
|
||||
if updated {
|
||||
@ -121,25 +121,21 @@ func BenchmarkImmutableAvlTree(b *testing.B) {
|
||||
value String
|
||||
}
|
||||
|
||||
records := make([]*record, 100)
|
||||
|
||||
ranrec := func() *record {
|
||||
return &record{ randstr(20), randstr(20) }
|
||||
randomRecord := func() *record {
|
||||
return &record{ randstr(32), randstr(32) }
|
||||
}
|
||||
|
||||
for i := range records {
|
||||
records[i] = ranrec()
|
||||
t := NewIAVLTree()
|
||||
for i:=0; i<1000000; i++ {
|
||||
r := randomRecord()
|
||||
t.Put(r.key, r.value)
|
||||
}
|
||||
|
||||
b.StartTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
t := NewIAVLTree()
|
||||
for _, r := range records {
|
||||
t.Put(r.key, r.value)
|
||||
}
|
||||
for _, r := range records {
|
||||
t.Remove(r.key)
|
||||
}
|
||||
r := randomRecord()
|
||||
t.Put(r.key, r.value)
|
||||
t.Remove(r.key)
|
||||
}
|
||||
}
|
||||
|
||||
@ -161,11 +157,9 @@ func TestTraversals(t *testing.T) {
|
||||
}
|
||||
|
||||
j := 0
|
||||
for
|
||||
tn, next := Iterator(T.Root())();
|
||||
next != nil;
|
||||
tn, next = next () {
|
||||
if int(tn.Key().(Int)) != data[j] {
|
||||
itr := Iterator(T.Root());
|
||||
for node := itr(); node != nil; node = itr() {
|
||||
if int(node.Key().(Int)) != data[j] {
|
||||
t.Error("key in wrong spot in-order")
|
||||
}
|
||||
j += 1
|
||||
@ -206,9 +200,8 @@ func TestGriffin(t *testing.T) {
|
||||
t.Fatalf("Expected %v new hashes, got %v", hashCount, count)
|
||||
}
|
||||
// nuke hashes and reconstruct hash, ensure it's the same.
|
||||
var node Node
|
||||
for itr:=Iterator(n2); itr!=nil; {
|
||||
node, itr = itr()
|
||||
itr := Iterator(n2)
|
||||
for node:=itr(); node!=nil; node = itr() {
|
||||
if node != nil {
|
||||
node.(*IAVLNode).hash = nil
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ type Node interface {
|
||||
Remove(key Key) (_ *IAVLNode, value Value, err error)
|
||||
}
|
||||
|
||||
type NodeIterator func() (node Node, next NodeIterator)
|
||||
type NodeIterator func() (node Node)
|
||||
|
||||
func NotFound(key Key) error {
|
||||
return fmt.Errorf("Key was not found.")
|
||||
|
@ -8,7 +8,7 @@ func Iterator(node Node) NodeIterator {
|
||||
stack := make([]Node, 0, 10)
|
||||
var cur Node = node
|
||||
var tn_iterator NodeIterator
|
||||
tn_iterator = func()(tn Node, next NodeIterator) {
|
||||
tn_iterator = func()(tn Node) {
|
||||
if len(stack) > 0 || cur != nil {
|
||||
for cur != nil {
|
||||
stack = append(stack, cur)
|
||||
@ -17,9 +17,9 @@ func Iterator(node Node) NodeIterator {
|
||||
stack, cur = pop(stack)
|
||||
tn = cur
|
||||
cur = cur.Right()
|
||||
return tn, tn_iterator
|
||||
return tn
|
||||
} else {
|
||||
return nil, nil
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return tn_iterator
|
||||
|
Loading…
x
Reference in New Issue
Block a user