benchmark 转移到其他仓库
This commit is contained in:
@@ -242,106 +242,106 @@ func TestQueueIndex(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkQueueGet(b *testing.B) {
|
||||
// func BenchmarkQueueGet(b *testing.B) {
|
||||
|
||||
l := loadTestData()
|
||||
// l := loadTestData()
|
||||
|
||||
pq := New(compare.Int)
|
||||
for _, v := range l {
|
||||
pq.Push(v)
|
||||
}
|
||||
// pq := New(compare.Int)
|
||||
// for _, v := range l {
|
||||
// pq.Push(v)
|
||||
// }
|
||||
|
||||
execCount := 5
|
||||
b.N = len(l) * execCount
|
||||
// execCount := 5
|
||||
// b.N = len(l) * execCount
|
||||
|
||||
b.ResetTimer()
|
||||
b.StartTimer()
|
||||
// b.ResetTimer()
|
||||
// b.StartTimer()
|
||||
|
||||
ALL:
|
||||
for i := 0; i < execCount; i++ {
|
||||
for _, v := range l {
|
||||
if gv, ok := pq.Get(v); !ok {
|
||||
b.Error(gv)
|
||||
break ALL
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// ALL:
|
||||
// for i := 0; i < execCount; i++ {
|
||||
// for _, v := range l {
|
||||
// if gv, ok := pq.Get(v); !ok {
|
||||
// b.Error(gv)
|
||||
// break ALL
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
func BenchmarkQueueRemove(b *testing.B) {
|
||||
l := loadTestData()
|
||||
// func BenchmarkQueueRemove(b *testing.B) {
|
||||
// l := loadTestData()
|
||||
|
||||
pq := New(compare.Int)
|
||||
for _, v := range l {
|
||||
pq.Push(v)
|
||||
}
|
||||
// pq := New(compare.Int)
|
||||
// for _, v := range l {
|
||||
// pq.Push(v)
|
||||
// }
|
||||
|
||||
b.N = len(l)
|
||||
b.ResetTimer()
|
||||
b.StartTimer()
|
||||
// b.N = len(l)
|
||||
// b.ResetTimer()
|
||||
// b.StartTimer()
|
||||
|
||||
for _, v := range l {
|
||||
pq.Remove(v)
|
||||
}
|
||||
}
|
||||
// for _, v := range l {
|
||||
// pq.Remove(v)
|
||||
// }
|
||||
// }
|
||||
|
||||
func BenchmarkQueueIndex(b *testing.B) {
|
||||
// func BenchmarkQueueIndex(b *testing.B) {
|
||||
|
||||
l := loadTestData()
|
||||
// l := loadTestData()
|
||||
|
||||
pq := New(compare.Int)
|
||||
for _, v := range l {
|
||||
pq.Push(v)
|
||||
}
|
||||
// pq := New(compare.Int)
|
||||
// for _, v := range l {
|
||||
// pq.Push(v)
|
||||
// }
|
||||
|
||||
execCount := 2
|
||||
b.N = len(l) * execCount
|
||||
// execCount := 2
|
||||
// b.N = len(l) * execCount
|
||||
|
||||
b.ResetTimer()
|
||||
b.StartTimer()
|
||||
// b.ResetTimer()
|
||||
// b.StartTimer()
|
||||
|
||||
ALL:
|
||||
for i := 0; i < execCount; i++ {
|
||||
for idx := range l {
|
||||
if v, ok := pq.Index(idx); !ok {
|
||||
b.Error(v)
|
||||
break ALL
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// ALL:
|
||||
// for i := 0; i < execCount; i++ {
|
||||
// for idx := range l {
|
||||
// if v, ok := pq.Index(idx); !ok {
|
||||
// b.Error(v)
|
||||
// break ALL
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
func BenchmarkPriorityPush(b *testing.B) {
|
||||
// func BenchmarkPriorityPush(b *testing.B) {
|
||||
|
||||
l := loadTestData()
|
||||
execCount := 5
|
||||
b.N = len(l) * execCount
|
||||
// l := loadTestData()
|
||||
// execCount := 5
|
||||
// b.N = len(l) * execCount
|
||||
|
||||
b.ResetTimer()
|
||||
b.StartTimer()
|
||||
// b.ResetTimer()
|
||||
// b.StartTimer()
|
||||
|
||||
for i := 0; i < execCount; i++ {
|
||||
pq := New(compare.Int)
|
||||
for _, v := range l {
|
||||
pq.Push(v)
|
||||
}
|
||||
}
|
||||
}
|
||||
// for i := 0; i < execCount; i++ {
|
||||
// pq := New(compare.Int)
|
||||
// for _, v := range l {
|
||||
// pq.Push(v)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
func BenchmarkPriorityPop(b *testing.B) {
|
||||
// func BenchmarkPriorityPop(b *testing.B) {
|
||||
|
||||
l := loadTestData()
|
||||
// l := loadTestData()
|
||||
|
||||
pq := New(compare.Int)
|
||||
for _, v := range l {
|
||||
pq.Push(v)
|
||||
}
|
||||
// pq := New(compare.Int)
|
||||
// for _, v := range l {
|
||||
// pq.Push(v)
|
||||
// }
|
||||
|
||||
b.N = len(l)
|
||||
b.ResetTimer()
|
||||
b.StartTimer()
|
||||
// b.N = len(l)
|
||||
// b.ResetTimer()
|
||||
// b.StartTimer()
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
pq.Pop()
|
||||
}
|
||||
}
|
||||
// for i := 0; i < b.N; i++ {
|
||||
// pq.Pop()
|
||||
// }
|
||||
// }
|
||||
|
||||
@@ -8,12 +8,8 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/474420502/focus/compare"
|
||||
"github.com/huandu/skiplist"
|
||||
|
||||
"github.com/Pallinder/go-randomdata"
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
"github.com/emirpasic/gods/trees/avltree"
|
||||
"github.com/emirpasic/gods/trees/redblacktree"
|
||||
)
|
||||
|
||||
func loadTestData() []int {
|
||||
@@ -178,35 +174,35 @@ func TestPutStable(t *testing.T) {
|
||||
|
||||
}
|
||||
|
||||
func TestPutComparatorRandom(t *testing.T) {
|
||||
// func TestPutComparatorRandom(t *testing.T) {
|
||||
|
||||
for n := 0; n < 30000; n++ {
|
||||
tree := newVBT(compare.Int)
|
||||
godsavl := avltree.NewWithIntComparator()
|
||||
// for n := 0; n < 30000; n++ {
|
||||
// tree := newVBT(compare.Int)
|
||||
// godsavl := avltree.NewWithIntComparator()
|
||||
|
||||
content := ""
|
||||
m := make(map[int]int)
|
||||
for i := 0; len(m) < 50; i++ {
|
||||
v := randomdata.Number(0, 65535)
|
||||
if _, ok := m[v]; !ok {
|
||||
m[v] = v
|
||||
content += spew.Sprint(v) + ","
|
||||
tree.Put(v)
|
||||
godsavl.Put(v, v)
|
||||
}
|
||||
}
|
||||
// content := ""
|
||||
// m := make(map[int]int)
|
||||
// for i := 0; len(m) < 50; i++ {
|
||||
// v := randomdata.Number(0, 65535)
|
||||
// if _, ok := m[v]; !ok {
|
||||
// m[v] = v
|
||||
// content += spew.Sprint(v) + ","
|
||||
// tree.Put(v)
|
||||
// godsavl.Put(v, v)
|
||||
// }
|
||||
// }
|
||||
|
||||
s1 := spew.Sprint(tree.Values())
|
||||
s2 := spew.Sprint(godsavl.Values())
|
||||
// s1 := spew.Sprint(tree.Values())
|
||||
// s2 := spew.Sprint(godsavl.Values())
|
||||
|
||||
if s1 != s2 {
|
||||
t.Error(godsavl.String())
|
||||
t.Error(tree.debugString())
|
||||
t.Error(content, n)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
// if s1 != s2 {
|
||||
// t.Error(godsavl.String())
|
||||
// t.Error(tree.debugString())
|
||||
// t.Error(content, n)
|
||||
// break
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
func TestGet(t *testing.T) {
|
||||
tree := newVBT(compare.Int)
|
||||
@@ -306,351 +302,351 @@ func TestTravalsal(t *testing.T) {
|
||||
|
||||
}
|
||||
|
||||
func TestRemoveAll(t *testing.T) {
|
||||
ALL:
|
||||
for c := 0; c < 20000; c++ {
|
||||
tree := newVBT(compare.Int)
|
||||
gods := avltree.NewWithIntComparator()
|
||||
var l []int
|
||||
m := make(map[int]int)
|
||||
|
||||
for i := 0; len(l) < 50; i++ {
|
||||
v := randomdata.Number(0, 65535)
|
||||
if _, ok := m[v]; !ok {
|
||||
m[v] = v
|
||||
l = append(l, v)
|
||||
tree.Put(v)
|
||||
gods.Put(v, v)
|
||||
}
|
||||
}
|
||||
|
||||
for i := 0; i < 50; i++ {
|
||||
tree.Remove(l[i])
|
||||
gods.Remove(l[i])
|
||||
|
||||
s1 := spew.Sprint(tree.Values())
|
||||
s2 := spew.Sprint(gods.Values())
|
||||
if s1 != s2 {
|
||||
t.Error("avl remove error", "avlsize = ", tree.Size())
|
||||
t.Error(tree.root, i, l[i])
|
||||
t.Error(s1)
|
||||
t.Error(s2)
|
||||
break ALL
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemove(t *testing.T) {
|
||||
|
||||
ALL:
|
||||
for N := 0; N < 5000; N++ {
|
||||
tree := newVBT(compare.Int)
|
||||
gods := avltree.NewWithIntComparator()
|
||||
|
||||
var l []int
|
||||
m := make(map[int]int)
|
||||
|
||||
for i := 0; len(l) < 20; i++ {
|
||||
v := randomdata.Number(0, 100)
|
||||
if _, ok := m[v]; !ok {
|
||||
l = append(l, v)
|
||||
m[v] = v
|
||||
tree.Put(v)
|
||||
gods.Put(v, v)
|
||||
}
|
||||
}
|
||||
|
||||
src1 := tree.String()
|
||||
src2 := gods.String()
|
||||
|
||||
for i := 0; i < 20; i++ {
|
||||
tree.Remove(l[i])
|
||||
gods.Remove(l[i])
|
||||
if tree.root != nil && spew.Sprint(gods.Values()) != spew.Sprint(tree.Values()) {
|
||||
t.Error(src1)
|
||||
t.Error(src2)
|
||||
t.Error(tree.debugString())
|
||||
t.Error(gods.String())
|
||||
t.Error(l[i])
|
||||
break ALL
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkSkipListGet(b *testing.B) {
|
||||
sl := skiplist.New(skiplist.Int)
|
||||
l := loadTestData()
|
||||
b.N = len(l)
|
||||
|
||||
for _, v := range l {
|
||||
sl.Set(v, v)
|
||||
}
|
||||
|
||||
b.ResetTimer()
|
||||
b.StartTimer()
|
||||
|
||||
execCount := 5
|
||||
b.N = len(l) * execCount
|
||||
|
||||
for i := 0; i < execCount; i++ {
|
||||
for _, v := range l {
|
||||
e := sl.Get(v)
|
||||
var result [50]interface{}
|
||||
for i := 0; i < 50 && e != nil; i++ {
|
||||
result[i] = e.Value
|
||||
e = e.Next()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkGetRange(b *testing.B) {
|
||||
|
||||
}
|
||||
|
||||
func BenchmarkIndexRange(b *testing.B) {
|
||||
tree := newVBT(compare.Int)
|
||||
l := loadTestData()
|
||||
b.N = len(l)
|
||||
|
||||
for _, v := range l {
|
||||
tree.Put(v)
|
||||
}
|
||||
|
||||
b.ResetTimer()
|
||||
b.StartTimer()
|
||||
|
||||
execCount := 5
|
||||
b.N = len(l) * execCount
|
||||
|
||||
for i := 0; i < execCount; i++ {
|
||||
for range l {
|
||||
tree.IndexRange(i, i+49)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkSkipListSet(b *testing.B) {
|
||||
|
||||
l := loadTestData()
|
||||
|
||||
execCount := 1
|
||||
b.N = len(l) * execCount
|
||||
|
||||
for i := 0; i < execCount; i++ {
|
||||
sl := skiplist.New(skiplist.Int)
|
||||
for _, v := range l {
|
||||
sl.Set(v, v)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkIterator(b *testing.B) {
|
||||
tree := newVBT(compare.Int)
|
||||
|
||||
l := loadTestData()
|
||||
b.N = len(l)
|
||||
|
||||
for _, v := range l {
|
||||
tree.Put(v)
|
||||
}
|
||||
|
||||
b.ResetTimer()
|
||||
b.StartTimer()
|
||||
iter := tree.Iterator()
|
||||
b.N = 0
|
||||
for iter.Next() {
|
||||
b.N++
|
||||
}
|
||||
for iter.Prev() {
|
||||
b.N++
|
||||
}
|
||||
for iter.Next() {
|
||||
b.N++
|
||||
}
|
||||
b.Log(b.N, len(l))
|
||||
}
|
||||
|
||||
func BenchmarkRemove(b *testing.B) {
|
||||
tree := newVBT(compare.Int)
|
||||
|
||||
l := loadTestData()
|
||||
|
||||
b.N = len(l)
|
||||
for _, v := range l {
|
||||
tree.Put(v)
|
||||
}
|
||||
|
||||
b.ResetTimer()
|
||||
b.StartTimer()
|
||||
|
||||
for i := 0; i < len(l); i++ {
|
||||
tree.Remove(l[i])
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkGodsRemove(b *testing.B) {
|
||||
tree := avltree.NewWithIntComparator()
|
||||
|
||||
l := loadTestData()
|
||||
|
||||
b.N = len(l)
|
||||
for _, v := range l {
|
||||
tree.Put(v, v)
|
||||
}
|
||||
|
||||
b.ResetTimer()
|
||||
b.StartTimer()
|
||||
|
||||
for i := 0; i < len(l); i++ {
|
||||
tree.Remove(l[i])
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkGodsRBRemove(b *testing.B) {
|
||||
tree := redblacktree.NewWithIntComparator()
|
||||
|
||||
l := loadTestData()
|
||||
|
||||
b.N = len(l)
|
||||
for _, v := range l {
|
||||
tree.Put(v, v)
|
||||
}
|
||||
|
||||
b.ResetTimer()
|
||||
b.StartTimer()
|
||||
|
||||
for i := 0; i < len(l); i++ {
|
||||
tree.Remove(l[i])
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkGet(b *testing.B) {
|
||||
|
||||
tree := newVBT(compare.Int)
|
||||
|
||||
l := loadTestData()
|
||||
b.N = len(l)
|
||||
for i := 0; i < b.N; i++ {
|
||||
tree.Put(l[i])
|
||||
}
|
||||
|
||||
b.ResetTimer()
|
||||
b.StartTimer()
|
||||
|
||||
execCount := 5
|
||||
b.N = len(l) * execCount
|
||||
|
||||
for i := 0; i < execCount; i++ {
|
||||
for _, v := range l {
|
||||
tree.Get(v)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkGodsRBGet(b *testing.B) {
|
||||
tree := redblacktree.NewWithIntComparator()
|
||||
|
||||
l := loadTestData()
|
||||
b.N = len(l)
|
||||
for i := 0; i < b.N; i++ {
|
||||
tree.Put(l[i], i)
|
||||
}
|
||||
|
||||
b.ResetTimer()
|
||||
b.StartTimer()
|
||||
|
||||
execCount := 10
|
||||
b.N = len(l) * execCount
|
||||
|
||||
for i := 0; i < execCount; i++ {
|
||||
for _, v := range l {
|
||||
tree.Get(v)
|
||||
}
|
||||
}
|
||||
}
|
||||
// func TestRemoveAll(t *testing.T) {
|
||||
// ALL:
|
||||
// for c := 0; c < 20000; c++ {
|
||||
// tree := newVBT(compare.Int)
|
||||
// gods := avltree.NewWithIntComparator()
|
||||
// var l []int
|
||||
// m := make(map[int]int)
|
||||
|
||||
// for i := 0; len(l) < 50; i++ {
|
||||
// v := randomdata.Number(0, 65535)
|
||||
// if _, ok := m[v]; !ok {
|
||||
// m[v] = v
|
||||
// l = append(l, v)
|
||||
// tree.Put(v)
|
||||
// gods.Put(v, v)
|
||||
// }
|
||||
// }
|
||||
|
||||
// for i := 0; i < 50; i++ {
|
||||
// tree.Remove(l[i])
|
||||
// gods.Remove(l[i])
|
||||
|
||||
// s1 := spew.Sprint(tree.Values())
|
||||
// s2 := spew.Sprint(gods.Values())
|
||||
// if s1 != s2 {
|
||||
// t.Error("avl remove error", "avlsize = ", tree.Size())
|
||||
// t.Error(tree.root, i, l[i])
|
||||
// t.Error(s1)
|
||||
// t.Error(s2)
|
||||
// break ALL
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// func TestRemove(t *testing.T) {
|
||||
|
||||
// ALL:
|
||||
// for N := 0; N < 5000; N++ {
|
||||
// tree := newVBT(compare.Int)
|
||||
// gods := avltree.NewWithIntComparator()
|
||||
|
||||
// var l []int
|
||||
// m := make(map[int]int)
|
||||
|
||||
// for i := 0; len(l) < 20; i++ {
|
||||
// v := randomdata.Number(0, 100)
|
||||
// if _, ok := m[v]; !ok {
|
||||
// l = append(l, v)
|
||||
// m[v] = v
|
||||
// tree.Put(v)
|
||||
// gods.Put(v, v)
|
||||
// }
|
||||
// }
|
||||
|
||||
// src1 := tree.String()
|
||||
// src2 := gods.String()
|
||||
|
||||
// for i := 0; i < 20; i++ {
|
||||
// tree.Remove(l[i])
|
||||
// gods.Remove(l[i])
|
||||
// if tree.root != nil && spew.Sprint(gods.Values()) != spew.Sprint(tree.Values()) {
|
||||
// t.Error(src1)
|
||||
// t.Error(src2)
|
||||
// t.Error(tree.debugString())
|
||||
// t.Error(gods.String())
|
||||
// t.Error(l[i])
|
||||
// break ALL
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// func BenchmarkSkipListGet(b *testing.B) {
|
||||
// sl := skiplist.New(skiplist.Int)
|
||||
// l := loadTestData()
|
||||
// b.N = len(l)
|
||||
|
||||
// for _, v := range l {
|
||||
// sl.Set(v, v)
|
||||
// }
|
||||
|
||||
// b.ResetTimer()
|
||||
// b.StartTimer()
|
||||
|
||||
// execCount := 5
|
||||
// b.N = len(l) * execCount
|
||||
|
||||
// for i := 0; i < execCount; i++ {
|
||||
// for _, v := range l {
|
||||
// e := sl.Get(v)
|
||||
// var result [50]interface{}
|
||||
// for i := 0; i < 50 && e != nil; i++ {
|
||||
// result[i] = e.Value
|
||||
// e = e.Next()
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// func BenchmarkGetRange(b *testing.B) {
|
||||
|
||||
// }
|
||||
|
||||
// func BenchmarkIndexRange(b *testing.B) {
|
||||
// tree := newVBT(compare.Int)
|
||||
// l := loadTestData()
|
||||
// b.N = len(l)
|
||||
|
||||
// for _, v := range l {
|
||||
// tree.Put(v)
|
||||
// }
|
||||
|
||||
// b.ResetTimer()
|
||||
// b.StartTimer()
|
||||
|
||||
// execCount := 5
|
||||
// b.N = len(l) * execCount
|
||||
|
||||
// for i := 0; i < execCount; i++ {
|
||||
// for range l {
|
||||
// tree.IndexRange(i, i+49)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// func BenchmarkSkipListSet(b *testing.B) {
|
||||
|
||||
// l := loadTestData()
|
||||
|
||||
// execCount := 1
|
||||
// b.N = len(l) * execCount
|
||||
|
||||
// for i := 0; i < execCount; i++ {
|
||||
// sl := skiplist.New(skiplist.Int)
|
||||
// for _, v := range l {
|
||||
// sl.Set(v, v)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// func BenchmarkIterator(b *testing.B) {
|
||||
// tree := newVBT(compare.Int)
|
||||
|
||||
// l := loadTestData()
|
||||
// b.N = len(l)
|
||||
|
||||
// for _, v := range l {
|
||||
// tree.Put(v)
|
||||
// }
|
||||
|
||||
// b.ResetTimer()
|
||||
// b.StartTimer()
|
||||
// iter := tree.Iterator()
|
||||
// b.N = 0
|
||||
// for iter.Next() {
|
||||
// b.N++
|
||||
// }
|
||||
// for iter.Prev() {
|
||||
// b.N++
|
||||
// }
|
||||
// for iter.Next() {
|
||||
// b.N++
|
||||
// }
|
||||
// b.Log(b.N, len(l))
|
||||
// }
|
||||
|
||||
// func BenchmarkRemove(b *testing.B) {
|
||||
// tree := newVBT(compare.Int)
|
||||
|
||||
// l := loadTestData()
|
||||
|
||||
// b.N = len(l)
|
||||
// for _, v := range l {
|
||||
// tree.Put(v)
|
||||
// }
|
||||
|
||||
// b.ResetTimer()
|
||||
// b.StartTimer()
|
||||
|
||||
// for i := 0; i < len(l); i++ {
|
||||
// tree.Remove(l[i])
|
||||
// }
|
||||
// }
|
||||
|
||||
// func BenchmarkGodsRemove(b *testing.B) {
|
||||
// tree := avltree.NewWithIntComparator()
|
||||
|
||||
// l := loadTestData()
|
||||
|
||||
// b.N = len(l)
|
||||
// for _, v := range l {
|
||||
// tree.Put(v, v)
|
||||
// }
|
||||
|
||||
// b.ResetTimer()
|
||||
// b.StartTimer()
|
||||
|
||||
// for i := 0; i < len(l); i++ {
|
||||
// tree.Remove(l[i])
|
||||
// }
|
||||
// }
|
||||
|
||||
// func BenchmarkGodsRBRemove(b *testing.B) {
|
||||
// tree := redblacktree.NewWithIntComparator()
|
||||
|
||||
// l := loadTestData()
|
||||
|
||||
// b.N = len(l)
|
||||
// for _, v := range l {
|
||||
// tree.Put(v, v)
|
||||
// }
|
||||
|
||||
// b.ResetTimer()
|
||||
// b.StartTimer()
|
||||
|
||||
// for i := 0; i < len(l); i++ {
|
||||
// tree.Remove(l[i])
|
||||
// }
|
||||
// }
|
||||
|
||||
// func BenchmarkGet(b *testing.B) {
|
||||
|
||||
// tree := newVBT(compare.Int)
|
||||
|
||||
// l := loadTestData()
|
||||
// b.N = len(l)
|
||||
// for i := 0; i < b.N; i++ {
|
||||
// tree.Put(l[i])
|
||||
// }
|
||||
|
||||
// b.ResetTimer()
|
||||
// b.StartTimer()
|
||||
|
||||
// execCount := 5
|
||||
// b.N = len(l) * execCount
|
||||
|
||||
// for i := 0; i < execCount; i++ {
|
||||
// for _, v := range l {
|
||||
// tree.Get(v)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// func BenchmarkGodsRBGet(b *testing.B) {
|
||||
// tree := redblacktree.NewWithIntComparator()
|
||||
|
||||
// l := loadTestData()
|
||||
// b.N = len(l)
|
||||
// for i := 0; i < b.N; i++ {
|
||||
// tree.Put(l[i], i)
|
||||
// }
|
||||
|
||||
// b.ResetTimer()
|
||||
// b.StartTimer()
|
||||
|
||||
// execCount := 10
|
||||
// b.N = len(l) * execCount
|
||||
|
||||
// for i := 0; i < execCount; i++ {
|
||||
// for _, v := range l {
|
||||
// tree.Get(v)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
func BenchmarkGodsAvlGet(b *testing.B) {
|
||||
tree := avltree.NewWithIntComparator()
|
||||
// func BenchmarkGodsAvlGet(b *testing.B) {
|
||||
// tree := avltree.NewWithIntComparator()
|
||||
|
||||
l := loadTestData()
|
||||
b.N = len(l)
|
||||
for i := 0; i < b.N; i++ {
|
||||
tree.Put(l[i], i)
|
||||
}
|
||||
// l := loadTestData()
|
||||
// b.N = len(l)
|
||||
// for i := 0; i < b.N; i++ {
|
||||
// tree.Put(l[i], i)
|
||||
// }
|
||||
|
||||
b.ResetTimer()
|
||||
b.StartTimer()
|
||||
// b.ResetTimer()
|
||||
// b.StartTimer()
|
||||
|
||||
execCount := 10
|
||||
b.N = len(l) * execCount
|
||||
|
||||
for i := 0; i < execCount; i++ {
|
||||
for _, v := range l {
|
||||
tree.Get(v)
|
||||
}
|
||||
}
|
||||
}
|
||||
// execCount := 10
|
||||
// b.N = len(l) * execCount
|
||||
|
||||
// for i := 0; i < execCount; i++ {
|
||||
// for _, v := range l {
|
||||
// tree.Get(v)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
func BenchmarkPut(b *testing.B) {
|
||||
l := loadTestData()
|
||||
|
||||
b.ResetTimer()
|
||||
b.StartTimer()
|
||||
// func BenchmarkPut(b *testing.B) {
|
||||
// l := loadTestData()
|
||||
|
||||
// b.ResetTimer()
|
||||
// b.StartTimer()
|
||||
|
||||
execCount := 50
|
||||
b.N = len(l) * execCount
|
||||
for i := 0; i < execCount; i++ {
|
||||
tree := newVBT(compare.Int)
|
||||
for _, v := range l {
|
||||
tree.Put(v)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkIndex(b *testing.B) {
|
||||
tree := newVBT(compare.Int)
|
||||
|
||||
l := loadTestData()
|
||||
b.N = len(l)
|
||||
for i := 0; i < b.N; i++ {
|
||||
tree.Put(l[i])
|
||||
}
|
||||
|
||||
b.ResetTimer()
|
||||
b.StartTimer()
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
tree.Index(i)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkGodsRBPut(b *testing.B) {
|
||||
tree := redblacktree.NewWithIntComparator()
|
||||
|
||||
l := loadTestData()
|
||||
|
||||
b.ResetTimer()
|
||||
b.StartTimer()
|
||||
|
||||
b.N = len(l)
|
||||
for _, v := range l {
|
||||
tree.Put(v, v)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkGodsPut(b *testing.B) {
|
||||
tree := avltree.NewWithIntComparator()
|
||||
|
||||
l := loadTestData()
|
||||
|
||||
b.ResetTimer()
|
||||
b.StartTimer()
|
||||
|
||||
b.N = len(l)
|
||||
for _, v := range l {
|
||||
tree.Put(v, v)
|
||||
}
|
||||
}
|
||||
// execCount := 50
|
||||
// b.N = len(l) * execCount
|
||||
// for i := 0; i < execCount; i++ {
|
||||
// tree := newVBT(compare.Int)
|
||||
// for _, v := range l {
|
||||
// tree.Put(v)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// func BenchmarkIndex(b *testing.B) {
|
||||
// tree := newVBT(compare.Int)
|
||||
|
||||
// l := loadTestData()
|
||||
// b.N = len(l)
|
||||
// for i := 0; i < b.N; i++ {
|
||||
// tree.Put(l[i])
|
||||
// }
|
||||
|
||||
// b.ResetTimer()
|
||||
// b.StartTimer()
|
||||
|
||||
// for i := 0; i < b.N; i++ {
|
||||
// tree.Index(i)
|
||||
// }
|
||||
// }
|
||||
|
||||
// func BenchmarkGodsRBPut(b *testing.B) {
|
||||
// tree := redblacktree.NewWithIntComparator()
|
||||
|
||||
// l := loadTestData()
|
||||
|
||||
// b.ResetTimer()
|
||||
// b.StartTimer()
|
||||
|
||||
// b.N = len(l)
|
||||
// for _, v := range l {
|
||||
// tree.Put(v, v)
|
||||
// }
|
||||
// }
|
||||
|
||||
// func BenchmarkGodsPut(b *testing.B) {
|
||||
// tree := avltree.NewWithIntComparator()
|
||||
|
||||
// l := loadTestData()
|
||||
|
||||
// b.ResetTimer()
|
||||
// b.StartTimer()
|
||||
|
||||
// b.N = len(l)
|
||||
// for _, v := range l {
|
||||
// tree.Put(v, v)
|
||||
// }
|
||||
// }
|
||||
|
||||
Reference in New Issue
Block a user