1 回答
TA贡献1825条经验 获得超6个赞
基准测试执行错误,正确版本:
func BenchmarkRBTree_Put(b *testing.B) {
count := 0
grow := 1
for size := 0; size < 100000; size += 1 * grow {
if count%10 == 0 {
count = 1
grow *= 10
}
b.Run(fmt.Sprintf("size-%d", size), func(b *testing.B) {
// prepare problem size
tree := NewRBTree(func(a, b interface{}) bool {
if a.(int) < b.(int) {
return true
}
return false
})
for n := 0; n < size-1; n++ {
tree.Put(n, n)
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
tree.Put(size, size) // only measure the last operation
}
})
count++
}
}
- 1 回答
- 0 关注
- 109 浏览
添加回答
举报