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 關注
- 135 瀏覽
添加回答
舉報