This is a creation in Article, where the information may have evolved or changed.
Golang Map is a convenient operation for Golang Key-value
Package Mainimport ("FMT" "Math/rand" "Time" _ "StrConv") var x = Make (Map[int]int, 100000001)//var x = Make (map[string] String, 100000001) Func main () {ttime: = time. Now (). Unixnano ()//x: = Make (Map[int]int, 100000001)//x: = [100000001]int{}fmt. Printf ("Len x%d \ n", Len (x)) for I: = 1; i < 100000001; i++ {X[rand. INTN (i)] = rand. INTN (i)//x[strconv. Itoa (Rand. INTN (i))] = "AAAAAAAAAA"}fmt. Printf ("Len1 x%d \ n", Len (x)) Ttime1: = time. Now (). Unixnano () fmt. Printf ("Time Cal%f\n", Float64 (ttime1-ttime)/float64 (1*time. Second))}//go version:go1.4 operating system: Win7 Memory: 8G Core Number: 4
Summarize:
1, test results make (Map[int]int, 1.0,000,000,11e,+17) about 2s, equivalent to apply for 100MB space (estimate)
2, 100 million random write Map[int]int, spend 25s time, probably randomly write 5000w key, the average 1s write 400w map[int]int
100 million random writes to Map[string]string, takes 38s time, approximately randomly writes 5000w key, the average 1s writes 260w map[string]string