Redblacktree benchmark useless code?
Author: MeteorsLiuCreated Dec 27, 2024Updated Dec 27, 2024
Hello,
I found that some benchmark codes of redblacktree are useless.
func BenchmarkRedBlackTreePut1000(b *testing.B) {
b.StopTimer()
size := 1000
tree := New[int, struct{}]()
// useless?
//for n := 0; n < size; n++ {
// tree.Put(n, struct{}{})
//}
b.StartTimer()
benchmarkPut(b, tree, size)
}and benchmarkPut may be biased.
func benchmarkPut(b *testing.B, tree *Tree[int, struct{}], size int) {
for i := 0; i < b.N; i++ {
for n := 0; n < size; n++ {
// Put will replace same keys,
// so it's equivalent to Get after inserting first size n.(without rebalancing)
//tree.Put(n, struct{}{})
// replace it to
tree.Put(rand.Int(), struct{}{})
}
}
}Should i open a pr?
Source: emirpasic/gods