|
|
|
@ -1074,14 +1074,155 @@ func assertValidTreeNode(t *testing.T, node *Node, expectedEntries int, expected
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func BenchmarkBTree(b *testing.B) {
|
|
|
|
|
func benchmarkGet(b *testing.B, tree *Tree, size int) {
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
|
tree := NewWithIntComparator(32)
|
|
|
|
|
for n := 0; n < 1000; n++ {
|
|
|
|
|
tree.Put(n, n)
|
|
|
|
|
for n := 0; n < size; n++ {
|
|
|
|
|
tree.Get(n)
|
|
|
|
|
}
|
|
|
|
|
for n := 0; n < 1000; n++ {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func benchmarkPut(b *testing.B, tree *Tree, size int) {
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
|
for n := 0; n < size; n++ {
|
|
|
|
|
tree.Put(n, struct{}{})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func benchmarkRemove(b *testing.B, tree *Tree, size int) {
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
|
for n := 0; n < size; n++ {
|
|
|
|
|
tree.Remove(n)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func BenchmarkBTreeGet100(b *testing.B) {
|
|
|
|
|
b.StopTimer()
|
|
|
|
|
size := 100
|
|
|
|
|
tree := NewWithIntComparator(128)
|
|
|
|
|
for n := 0; n < size; n++ {
|
|
|
|
|
tree.Put(n, struct{}{})
|
|
|
|
|
}
|
|
|
|
|
b.StartTimer()
|
|
|
|
|
benchmarkGet(b, tree, size)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func BenchmarkBTreeGet1000(b *testing.B) {
|
|
|
|
|
b.StopTimer()
|
|
|
|
|
size := 1000
|
|
|
|
|
tree := NewWithIntComparator(128)
|
|
|
|
|
for n := 0; n < size; n++ {
|
|
|
|
|
tree.Put(n, struct{}{})
|
|
|
|
|
}
|
|
|
|
|
b.StartTimer()
|
|
|
|
|
benchmarkGet(b, tree, size)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func BenchmarkBTreeGet10000(b *testing.B) {
|
|
|
|
|
b.StopTimer()
|
|
|
|
|
size := 10000
|
|
|
|
|
tree := NewWithIntComparator(128)
|
|
|
|
|
for n := 0; n < size; n++ {
|
|
|
|
|
tree.Put(n, struct{}{})
|
|
|
|
|
}
|
|
|
|
|
b.StartTimer()
|
|
|
|
|
benchmarkGet(b, tree, size)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func BenchmarkBTreeGet100000(b *testing.B) {
|
|
|
|
|
b.StopTimer()
|
|
|
|
|
size := 100000
|
|
|
|
|
tree := NewWithIntComparator(128)
|
|
|
|
|
for n := 0; n < size; n++ {
|
|
|
|
|
tree.Put(n, struct{}{})
|
|
|
|
|
}
|
|
|
|
|
b.StartTimer()
|
|
|
|
|
benchmarkGet(b, tree, size)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func BenchmarkBTreePut100(b *testing.B) {
|
|
|
|
|
b.StopTimer()
|
|
|
|
|
size := 100
|
|
|
|
|
tree := NewWithIntComparator(128)
|
|
|
|
|
b.StartTimer()
|
|
|
|
|
benchmarkPut(b, tree, size)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func BenchmarkBTreePut1000(b *testing.B) {
|
|
|
|
|
b.StopTimer()
|
|
|
|
|
size := 1000
|
|
|
|
|
tree := NewWithIntComparator(128)
|
|
|
|
|
for n := 0; n < size; n++ {
|
|
|
|
|
tree.Put(n, struct{}{})
|
|
|
|
|
}
|
|
|
|
|
b.StartTimer()
|
|
|
|
|
benchmarkPut(b, tree, size)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func BenchmarkBTreePut10000(b *testing.B) {
|
|
|
|
|
b.StopTimer()
|
|
|
|
|
size := 10000
|
|
|
|
|
tree := NewWithIntComparator(128)
|
|
|
|
|
for n := 0; n < size; n++ {
|
|
|
|
|
tree.Put(n, struct{}{})
|
|
|
|
|
}
|
|
|
|
|
b.StartTimer()
|
|
|
|
|
benchmarkPut(b, tree, size)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func BenchmarkBTreePut100000(b *testing.B) {
|
|
|
|
|
b.StopTimer()
|
|
|
|
|
size := 100000
|
|
|
|
|
tree := NewWithIntComparator(128)
|
|
|
|
|
for n := 0; n < size; n++ {
|
|
|
|
|
tree.Put(n, struct{}{})
|
|
|
|
|
}
|
|
|
|
|
b.StartTimer()
|
|
|
|
|
benchmarkPut(b, tree, size)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func BenchmarkBTreeRemove100(b *testing.B) {
|
|
|
|
|
b.StopTimer()
|
|
|
|
|
size := 100
|
|
|
|
|
tree := NewWithIntComparator(128)
|
|
|
|
|
for n := 0; n < size; n++ {
|
|
|
|
|
tree.Put(n, struct{}{})
|
|
|
|
|
}
|
|
|
|
|
b.StartTimer()
|
|
|
|
|
benchmarkRemove(b, tree, size)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func BenchmarkBTreeRemove1000(b *testing.B) {
|
|
|
|
|
b.StopTimer()
|
|
|
|
|
size := 1000
|
|
|
|
|
tree := NewWithIntComparator(128)
|
|
|
|
|
for n := 0; n < size; n++ {
|
|
|
|
|
tree.Put(n, struct{}{})
|
|
|
|
|
}
|
|
|
|
|
b.StartTimer()
|
|
|
|
|
benchmarkRemove(b, tree, size)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func BenchmarkBTreeRemove10000(b *testing.B) {
|
|
|
|
|
b.StopTimer()
|
|
|
|
|
size := 10000
|
|
|
|
|
tree := NewWithIntComparator(128)
|
|
|
|
|
for n := 0; n < size; n++ {
|
|
|
|
|
tree.Put(n, struct{}{})
|
|
|
|
|
}
|
|
|
|
|
b.StartTimer()
|
|
|
|
|
benchmarkRemove(b, tree, size)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func BenchmarkBTreeRemove100000(b *testing.B) {
|
|
|
|
|
b.StopTimer()
|
|
|
|
|
size := 100000
|
|
|
|
|
tree := NewWithIntComparator(128)
|
|
|
|
|
for n := 0; n < size; n++ {
|
|
|
|
|
tree.Put(n, struct{}{})
|
|
|
|
|
}
|
|
|
|
|
b.StartTimer()
|
|
|
|
|
benchmarkRemove(b, tree, size)
|
|
|
|
|
}
|
|
|
|
|