You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
package main_test
import "testing"
import "fmt"
// int64, int32, string - doesn't matter
type fixT int
const sz=15
func BenchmarkMapSize(b *testing.B) {
for n := 1; n <= sz; n++ {
b.Run(fmt.Sprintf("%d", n), func(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
m := make(map[fixT]bool)
for j := 0; j < n; j++ {
m[fixT(j)] = true
}
}
})
}
}
There are 3 allocations at point 14 every test, int64, int32 and string key types. Steps 9 and 13 - ok, but what is at step number14? I can't explain this behavior. It looks like unwanted magic number. Perhaps this is a unwanted feature of the hash distribution. I don't know.
Go versions from 1.7 to 1.18rc1, amd64, linux
There are 3 allocations at point 14 every test, int64, int32 and string key types. Steps 9 and 13 - ok, but what is at step number14? I can't explain this behavior. It looks like unwanted magic number. Perhaps this is a unwanted feature of the hash distribution. I don't know.
P.S. Map with big keys, [128]byte for example, shows different behavior. It's ok
The text was updated successfully, but these errors were encountered: