Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
maps vs slices for mapping small sets of ordinals to values
package whatever
import (
"testing"
)
func BenchmarkMapConstruction(b *testing.B) {
space := make([]map[int][]string, b.N)
for n := 0; n < b.N; n++ {
space[n] = map[int][]string{
0: []string{},
1: []string{},
2: []string{},
3: []string{},
}
}
}
func BenchmarkSliceConstruction(b *testing.B) {
space := make([][][]string, b.N)
for n := 0; n < b.N; n++ {
space[n] = make([][]string, 4)
}
}
@lloyd

This comment has been minimized.

Copy link
Owner Author

lloyd commented Jul 19, 2017

$  go test -bench=. -run "XXX"
BenchmarkMapConstruction-4     	 3000000	       562 ns/op
BenchmarkSliceConstruction-4   	10000000	       104 ns/op
PASS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.