Browse Source

updated benchmark

pull/9/head
Jae Kwon 11 years ago
parent
commit
850144f3e7
3 changed files with 20 additions and 27 deletions
  1. +16
    -23
      merkle/iavl_test.go
  2. +1
    -1
      merkle/types.go
  3. +3
    -3
      merkle/util.go

+ 16
- 23
merkle/iavl_test.go View File

@ -53,12 +53,12 @@ func TestImmutableAvlPutHasGetRemove(t *testing.T) {
var val Value var val Value
var updated bool var updated bool
ranrec := func() *record {
randomRecord := func() *record {
return &record{ randstr(20), randstr(20) } return &record{ randstr(20), randstr(20) }
} }
for i := range records { for i := range records {
r := ranrec()
r := randomRecord()
records[i] = r records[i] = r
tree, updated = tree.Put(r.key, String("")) tree, updated = tree.Put(r.key, String(""))
if updated { if updated {
@ -121,25 +121,21 @@ func BenchmarkImmutableAvlTree(b *testing.B) {
value String 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() b.StartTimer()
for i := 0; i < b.N; i++ { 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 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") t.Error("key in wrong spot in-order")
} }
j += 1 j += 1
@ -206,9 +200,8 @@ func TestGriffin(t *testing.T) {
t.Fatalf("Expected %v new hashes, got %v", hashCount, count) t.Fatalf("Expected %v new hashes, got %v", hashCount, count)
} }
// nuke hashes and reconstruct hash, ensure it's the same. // 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 { if node != nil {
node.(*IAVLNode).hash = nil node.(*IAVLNode).hash = nil
} }


+ 1
- 1
merkle/types.go View File

@ -41,7 +41,7 @@ type Node interface {
Remove(key Key) (_ *IAVLNode, value Value, err error) 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 { func NotFound(key Key) error {
return fmt.Errorf("Key was not found.") return fmt.Errorf("Key was not found.")


+ 3
- 3
merkle/util.go View File

@ -8,7 +8,7 @@ func Iterator(node Node) NodeIterator {
stack := make([]Node, 0, 10) stack := make([]Node, 0, 10)
var cur Node = node var cur Node = node
var tn_iterator NodeIterator var tn_iterator NodeIterator
tn_iterator = func()(tn Node, next NodeIterator) {
tn_iterator = func()(tn Node) {
if len(stack) > 0 || cur != nil { if len(stack) > 0 || cur != nil {
for cur != nil { for cur != nil {
stack = append(stack, cur) stack = append(stack, cur)
@ -17,9 +17,9 @@ func Iterator(node Node) NodeIterator {
stack, cur = pop(stack) stack, cur = pop(stack)
tn = cur tn = cur
cur = cur.Right() cur = cur.Right()
return tn, tn_iterator
return tn
} else { } else {
return nil, nil
return nil
} }
} }
return tn_iterator return tn_iterator


Loading…
Cancel
Save