@@ -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 }
0 commit comments