3 ms·
I believe a good rule of thumb is that looping over an array will generally be faster than using a hash map until you have around ~1,000 items. Very approximat
by BillinghamJ 9y ago
I believe a good rule of thumb is that looping over an array will generally be faster than using a hash map until you have around ~1,000 items.
Very approximate and dependent on the case obviously, but I always find it surprising how far you can go with just a simple array.
- zaarn 9y agoFrom experience I would say it's closer to 100 items, though this is using Go as benchmark. 100 items is also what I would expect considering CPU caches. From 100 to 1000 items the array performance is not massively worse and shouldn't matter much but a dictionary can beat it (by a tiny bit). If you're over 1000 definitely use a dictionary or tree.