Re:Interface Dispatch (2018)
by Insanity on Thursday April 18, 2019 @07:02AM
(#19690103)
Speaking of interfaces in Go, can anyone explain this particular result?
We've done a benchmark recently at work to test which way we would best represent a set. (Linux, go1.12)
results:
(I'm aware this is a bit of a tangent to TFA)
[ Parent
| on HN ]
Can’t really say what’s going on here without seeing some code.
Well the code is the same for all of them (but when using a bool map we assign true instead of empty struct). So we run this code inside a benchmarking function:
m := map[int]interface{}
// or m := map[int]struct{}
for i := 0; i < t.N; i++ {
m[i] = struct{}{}
}
edit: fix code.I'm speculating, but sizeof(bool) == 1, sizeof(struct{}) == 0 and sizeof(interface{}) == 8, so might be as simple as that.