[]uint vs map[uint]struct{}
A wee bit of premature optimization, I was coding a thing where I wanted a set of uint, and I wanted to filter several million records against them. I had a hunch that []uint with binary search would be faster than hashing the key and doing lookup in a map[uint]. I was right, but only if the set of uint is smaller than 1000. Below 1000 elements, slices.BinarySearch() is faster, somewhere between 100 and 1000 is the crossover point in this test and after that map[uint]struct{} is faster.
I'm not couning setup time to build the set, just lookup time to do 100_000_000 lookups against the set.
No comments:
Post a Comment