syncmap icon indicating copy to clipboard operation
syncmap copied to clipboard

The case BenchmarkRange seems has some problem ?

Open yandaren opened this issue 4 years ago • 1 comments

// syncmap code:
	b.Run(fmt.Sprintf("%T", &IntMap{}), func(b *testing.B) {
		m := &IntMap{}
		// setup:

		// reset:
		b.ResetTimer()

		// perG:
		perG := func(b *testing.B, pb *testing.PB, i int, m *IntMap) {
			for ; pb.Next(); i++ {
				m.Range(func(_, _ int) bool { return true })
			}
		}
		var i int64
		b.RunParallel(func(pb *testing.PB) {
			id := int(atomic.AddInt64(&i, 1) - 1)
			perG(b, pb, id*b.N, m)
		})
	})

seems the setup function is nil, then the map is empy, so at the benrchmark result, it seems vary fast

yandaren avatar Jun 27 '21 10:06 yandaren

Hey @yandaren, you're right. Some parts are missing there (my fault), but some parts are empty in purpose.

Would you like to send a patch to fix this? It's basically a changed version of sync/map_bench_test.go. If don't have time, it's fine, I can address this soon. Thanks 🙏

a8m avatar Jun 30 '21 08:06 a8m