Skip to content

Commit 813987a

Browse files
committed
更新benchmark
1 parent 9dcce14 commit 813987a

File tree

5 files changed

+87
-14
lines changed

5 files changed

+87
-14
lines changed

avltree/avltree_bench_test.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,15 @@ import (
55
"testing"
66
)
77

8+
// b.N = 3kw
9+
// pkg: github.com/antlabs/gstl/avltree
10+
// BenchmarkGetAsc-8 33178270 41.07 ns/op
11+
// BenchmarkGetDesc-8 33488839 39.91 ns/op
12+
// BenchmarkGetStd-8 29553132 49.34 ns/op
13+
814
func BenchmarkGetAsc(b *testing.B) {
9-
max := 1000000.0 * 5
15+
//max := 1000000.0 * 5
16+
max := float64(b.N)
1017
set := New[float64, float64]()
1118
for i := 0.0; i < max; i++ {
1219
set.Set(i, i)
@@ -23,7 +30,8 @@ func BenchmarkGetAsc(b *testing.B) {
2330
}
2431

2532
func BenchmarkGetDesc(b *testing.B) {
26-
max := 1000000.0 * 5
33+
//max := 1000000.0 * 5
34+
max := float64(b.N)
2735
set := New[float64, float64]()
2836
for i := max; i >= 0; i-- {
2937
set.Set(i, i)
@@ -41,7 +49,8 @@ func BenchmarkGetDesc(b *testing.B) {
4149

4250
func BenchmarkGetStd(b *testing.B) {
4351

44-
max := 1000000.0 * 5
52+
//max := 1000000.0 * 5
53+
max := float64(b.N)
4554
set := make(map[float64]float64, int(max))
4655
for i := 0.0; i < max; i++ {
4756
set[i] = i

btree/btree.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func (b *Btree[K, V]) nodeSet(n *node[K, V], item pair[K, V]) (prev V, replaced
117117
i, found := b.find(n, item.key)
118118
// 找到位置直接替换
119119
if found {
120-
fmt.Printf("1.## i = %v, item:%v\n", item.key, n.items)
120+
//fmt.Printf("1.## i = %v, item:%v\n", item.key, n.items)
121121
prevPtr := n.items.GetPtr(i)
122122
prev = prevPtr.val
123123
prevPtr.val = item.val

btree/btree_bench_test.go

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,64 @@ import (
1414
// PASS
1515
// ok github.com/antlabs/gstl/btree 25.315s
1616
// 五百万数据的Get操作时间
17-
func BenchmarkGet(b *testing.B) {
18-
max := 1000000 * 5.0
19-
bt := New[float64, float64](0)
17+
18+
// goos: darwin
19+
// goarch: arm64
20+
// pkg: github.com/antlabs/gstl/btree
21+
// BenchmarkGetAsc-8 17242494 79.54 ns/op
22+
// BenchmarkGetDesc-8 17556082 78.17 ns/op
23+
// BenchmarkGetStd-8 29304117 50.49 ns/op
24+
// PASS
25+
// ok github.com/antlabs/gstl/btree 10.503s
26+
func BenchmarkGetAsc(b *testing.B) {
27+
//max := 1000000.0 * 5
28+
set := New[float64, float64](0)
29+
max := float64(b.N)
30+
for i := 0.0; i < max; i++ {
31+
set.Set(i, i)
32+
}
33+
34+
b.ResetTimer()
35+
36+
for i := 0.0; i < max; i++ {
37+
v := set.Get(i)
38+
if v != i {
39+
panic(fmt.Sprintf("need:%f, got:%f", i, v))
40+
}
41+
}
42+
}
43+
44+
func BenchmarkGetDesc(b *testing.B) {
45+
max := float64(b.N)
46+
//max := 1000000.0 * 5
47+
set := New[float64, float64](0)
48+
for i := max; i >= 0; i-- {
49+
set.Set(i, i)
50+
}
51+
52+
b.ResetTimer()
53+
54+
for i := 0.0; i < max; i++ {
55+
v := set.Get(i)
56+
if v != i {
57+
panic(fmt.Sprintf("need:%f, got:%f", i, v))
58+
}
59+
}
60+
}
61+
62+
func BenchmarkGetStd(b *testing.B) {
63+
64+
max := float64(b.N)
65+
//max := 1000000.0 * 5
66+
set := make(map[float64]float64, int(max))
2067
for i := 0.0; i < max; i++ {
21-
bt.Set(i, i)
68+
set[i] = i
2269
}
2370

2471
b.ResetTimer()
2572

2673
for i := 0.0; i < max; i++ {
27-
v := bt.Get(i)
74+
v := set[i]
2875
if v != i {
2976
panic(fmt.Sprintf("need:%f, got:%f", i, v))
3077
}

rbtree/rbtree_bench_test.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package rbtree
22

33
// apache 2.0 antlabs
44

5+
// b.N = 500w
56
// goos: darwin
67
// goarch: amd64
78
// pkg: github.com/antlabs/gstl/rbtree
@@ -12,14 +13,26 @@ package rbtree
1213
// 1000000000 0.8940 ns/op
1314
// PASS
1415
// ok github.com/antlabs/gstl/rbtree 139.415s
16+
17+
// b.N = 3kw
18+
// goos: darwin
19+
// goarch: arm64
20+
// pkg: github.com/antlabs/gstl/rbtree
21+
// BenchmarkGetAsc-8 32662837 40.22 ns/op
22+
// BenchmarkGetDesc-8 33250437 39.52 ns/op
23+
// BenchmarkGetStd-8 29353758 49.73 ns/op
24+
// PASS
25+
// ok github.com/antlabs/gstl/rbtree 13.030s
26+
1527
import (
1628
"fmt"
1729
"testing"
1830
)
1931

2032
func BenchmarkGetAsc(b *testing.B) {
21-
max := 1000000.0 * 5
33+
//max := 1000000.0 * 5
2234
set := New[float64, float64]()
35+
max := float64(b.N)
2336
for i := 0.0; i < max; i++ {
2437
set.Set(i, i)
2538
}
@@ -35,7 +48,8 @@ func BenchmarkGetAsc(b *testing.B) {
3548
}
3649

3750
func BenchmarkGetDesc(b *testing.B) {
38-
max := 1000000.0 * 5
51+
max := float64(b.N)
52+
//max := 1000000.0 * 5
3953
set := New[float64, float64]()
4054
for i := max; i >= 0; i-- {
4155
set.Set(i, i)
@@ -53,7 +67,8 @@ func BenchmarkGetDesc(b *testing.B) {
5367

5468
func BenchmarkGetStd(b *testing.B) {
5569

56-
max := 1000000.0 * 5
70+
max := float64(b.N)
71+
//max := 1000000.0 * 5
5772
set := make(map[float64]float64, int(max))
5873
for i := 0.0; i < max; i++ {
5974
set[i] = i

skiplist/skiplist_bench_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ import (
1616
// ok github.com/antlabs/gstl/skiplist 178.377s
1717
// 五百万数据的Get操作时间
1818
func BenchmarkGet(b *testing.B) {
19-
max := 1000000.0 * 5
19+
//max := 1000000.0 * 5
20+
max := float64(b.N)
2021
set := New[float64, float64]()
2122
for i := 0.0; i < max; i++ {
2223
set.Set(i, i)
@@ -34,7 +35,8 @@ func BenchmarkGet(b *testing.B) {
3435

3536
func BenchmarkGetStd(b *testing.B) {
3637

37-
max := 1000000.0 * 5
38+
//max := 1000000.0 * 5
39+
max := float64(b.N)
3840
set := make(map[float64]float64, int(max))
3941
for i := 0.0; i < max; i++ {
4042
set[i] = i

0 commit comments

Comments
 (0)