github.com/NVIDIA/aistore@v1.3.23-0.20240517131212-7df6609be51d/bench/microbenchmarks/map/README.md (about)

     1  ## Map Benchmark
     2  
     3  This benchmark tests the performance of regular maps versus sync.Maps focusing on the primitive operations of get, put, and delete while under contention. For the use case of AIStore, we want the read times to be as fast as possible.
     4  
     5  ### Getting started
     6  
     7  Run
     8  
     9  ```console
    10  $ go run main.go -maxsize 1000000
    11  ```
    12  
    13  This will start the benchmark with the map size to be 1 million elements. 
    14  
    15  The list of available options are:
    16  
    17  * `-iter` int - Number of iterations to run (default 10)
    18  * `-maxsize` int - Maximum size of map (default 1000000)
    19  * `-minsize` int - Shrink size of map (default 10000)
    20  * `-numread` int - Number of random reads (default 200000)
    21  * `-putpct` int - Percentage of puts (default 10)
    22  * `-shrink` bool - Enable shrink (deletion) of map keys (default true)
    23  * `-workers` int - Number of Read/Write go-routines (default 8)
    24  
    25  ### Result
    26  
    27  From the results of the benchmark, `sync.Map` does appear to out perform regular maps for read operations when there is contention from multiple go routines. The performance of `sync.Map` for put and delete operations are usually slower than regular maps, but if we expect > `80%` of the requests to be reads, sync.Map will be faster than regular maps. Overall, if we expect that the maps will have much higher read requests than put/delete requests, `sync.Maps` are the better option.