GF Framework's Concurrency Security container-gmap, as well as with sync. Comparison of Map performance

Source: Internet
Author: User
Tags benchmark
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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.