Skip to content

Redblacktree benchmark useless code? #274

@MeteorsLiu

Description

@MeteorsLiu

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions