This is a creation in Article, where the information may have evolved or changed.
The GF Framework provides several very useful concurrency security containers, where Gmap is one of the most commonly used in project development.
Gmap Specific methods Please refer to godoc:https://godoc.org/github.com/...
There are several types of structure definitions within GMAP, including: Intboolmap, Intintmap, Intinterfacemap, Intstringmap, Interfaceinterfacemap, Stringboolmap, Stringintmap, Stringinterfacemap, Stringstringmap, Uintinterfacemap.
From the execution efficiency, based on the different requirements scenarios, select the appropriate type structure, its execution efficiency is not the same, the following use benchmark to compare the various types of write performance (test code):
john@johnstation:~/Workspace/Go/GOPATH/src/gitee.com/johng/gf/g/container/gmap$ go test gmap_test.go -bench=".*"goos: linuxgoarch: amd64BenchmarkIntBoolMap_Set-8 10000000 171 ns/opBenchmarkIntIntMap_Set-8 10000000 181 ns/opBenchmarkIntInterfaceMap_Set-8 10000000 227 ns/opBenchmarkIntStringMap_Set-8 10000000 271 ns/opBenchmarkInterfaceInterfaceMap_Set-8 5000000 331 ns/opBenchmarkStringBoolMap_Set-8 5000000 271 ns/opBenchmarkStringIntMap_Set-8 5000000 300 ns/opBenchmarkStringInterfaceMap_Set-8 5000000 363 ns/opBenchmarkStringStringMap_Set-8 5000000 394 ns/opBenchmarkUintInterfaceMap_Set-8 10000000 275 ns/opPASSok command-line-arguments 37.024s
Also, it is necessary to note that the go language has introduced the same support for concurrency-safe sync.map from version 1.9, so let's take a look at how the benchmark test results are:
john@johnstation:~/Workspace/Go/GOPATH/src/gitee.com/johng/gf/g/container/gmap$ go test *.go -bench=".*"goos: linuxgoarch: amd64BenchmarkGmapSet-8 10000000 181 ns/opBenchmarkSyncmapSet-8 5000000 366 ns/opBenchmarkGmapGet-8 30000000 82.6 ns/opBenchmarkSyncmapGet-8 20000000 95.7 ns/opBenchmarkGmapRemove-8 20000000 69.8 ns/opBenchmarkSyncmapRmove-8 20000000 93.6 ns/opPASSok command-line-arguments 27.950s
Check sync. Map source code We can find that its implementation principle is similar to gmap. Interfaceinterfacemap This type of structure, but efficiency is not gmap. Interfaceinterfacemap High.
It is therefore found that the efficiency of GMAP packets supporting concurrency security is already quite high.