Set in Go, map[]bool and map[]struct{} performance comparison

Jerome Wu
ITNEXT
Published in
2 min readJun 14, 2021

--

TL;DR map[]struct{} is 5% faster in time and 10% less memory consumption comparing to map[]bool when it comes to a big Set.

It is not a secret that there is no built-in Set in go, so go developers use map to mimic the behavior of Set. Use map to implement Set means that the value of the map is not important, we only need to focus on the existence of the key…

--

--

Writer for

A technology enthusiast wishes to make the world better and better. Maintainer of tesseract.js and ffmpeg.wasm