Maps vs slices
which is faster, can you guess ?
Using slice
package main
import (
"runtime"
)
type data struct {
i, j int
}
func main() {
var N = 40000000
var structure []data
for i := 0; i < N; i++ {
value := int(i)
structure = append(structure, data{value, value})
}
runtime.GC()
_ = structure[0]
}Using a map with pointers
Using a map without pointers
Splitting the map
The implementation of this subsection will split the map into a map of maps, which is also called sharding. The program of this subsection is saved as mapSplit.go and will be presented in two parts
Results
What will be important in the presented output is not the exact numbers but the time difference between the four different approaches.
Last updated
Was this helpful?