MEASUREMENT
bench/gomap/runs/syncmap.txt
The script that produced the numbers in the article, and the record of the run. The file is read from the repository at build time — this is the code that was run, not a copy of it.
- Cited in
- /en/interview/golang/maps
The run below is recorded in Russian. It is a lab record, kept in the language it was written in; the numbers, the tables and the code read the same either way.
Record of the run
This measurement has no recorded run — only the script.
Script
32 linesgo1.24.7 linux/amd64 | GOMAXPROCS=2 | cpu: Intel(R) Xeon(R) Processor @ 2.80GHz
ключей: 10000, все загружены до замера; запись — перезапись существующего ключа
лучший из 7 чередующихся кругов; в скобках — разброс по кругам
1. ТОЛЬКО ЧТЕНИЕ, ОБЩИЕ КЛЮЧИ
-----------------------------
map + Mutex 41.94 нс/оп (41.94–56.20) выделений/оп 0.00
map + RWMutex 50.83 нс/оп (50.83–67.92) выделений/оп 0.00
sync.Map 24.16 нс/оп (24.16–32.29) выделений/оп 0.00
sync.Map быстрее, чем map + Mutex, в 1.74 раза
2. 90 % ЧТЕНИЙ, 10 % ЗАПИСЕЙ, ОБЩИЕ КЛЮЧИ
-----------------------------------------
map + Mutex 34.65 нс/оп (34.65–54.34) выделений/оп 0.00
map + RWMutex 33.52 нс/оп (33.52–48.76) выделений/оп 0.00
sync.Map 45.16 нс/оп (45.16–73.82) выделений/оп 0.10
sync.Map медленнее, чем map + RWMutex, в 1.35 раза
3. РАВНОМЕРНАЯ СМЕСЬ: 50 % ЧТЕНИЙ, 50 % ЗАПИСЕЙ, ОБЩИЕ КЛЮЧИ
------------------------------------------------------------
map + Mutex 43.97 нс/оп (43.97–63.80) выделений/оп 0.00
map + RWMutex 48.69 нс/оп (48.69–83.80) выделений/оп 0.00
sync.Map 105.66 нс/оп (105.66–170.75) выделений/оп 0.50
sync.Map медленнее, чем map + Mutex, в 2.40 раза
4. РАВНОМЕРНАЯ СМЕСЬ, НЕПЕРЕСЕКАЮЩИЕСЯ КЛЮЧИ
--------------------------------------------
map + Mutex 46.71 нс/оп (46.71–61.49) выделений/оп 0.00
map + RWMutex 46.64 нс/оп (46.64–75.65) выделений/оп 0.00
sync.Map 84.14 нс/оп (84.14–154.55) выделений/оп 0.50
sync.Map медленнее, чем map + RWMutex, в 1.80 раза