1 回答

TA貢獻(xiàn)1825條經(jīng)驗(yàn) 獲得超6個(gè)贊
基準(zhǔn)測(cè)試執(zhí)行錯(cuò)誤,正確版本:
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 關(guān)注
- 146 瀏覽
添加回答
舉報(bào)