Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redblacktree benchmark useless code? #274

Open
MeteorsLiu opened this issue Dec 27, 2024 · 0 comments
Open

Redblacktree benchmark useless code? #274

MeteorsLiu opened this issue Dec 27, 2024 · 0 comments

Comments

@MeteorsLiu
Copy link

MeteorsLiu commented 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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant