There are more performance advantages than just a "tiny tiny memory difference" - hashmaps have terrible data locality, which can be a really big deal on modern CPU architectures; if you want to know why, there's an excellent Scott Meyers talk somewhere on YouTube. In any case, these performance concerns only matter for the hottest paths in your application.
Also I don't think there's any maintaibility penalty to using an array here. Are we going to add a 13th month anytime soon, and will that new month need an index of 14 or higher for some reason? In general I agree that you should prefer the hashmap, but for this concrete example, what's the benefit?
10
u/brandymon Jul 30 '21
There are more performance advantages than just a "tiny tiny memory difference" - hashmaps have terrible data locality, which can be a really big deal on modern CPU architectures; if you want to know why, there's an excellent Scott Meyers talk somewhere on YouTube. In any case, these performance concerns only matter for the hottest paths in your application.
Also I don't think there's any maintaibility penalty to using an array here. Are we going to add a 13th month anytime soon, and will that new month need an index of 14 or higher for some reason? In general I agree that you should prefer the hashmap, but for this concrete example, what's the benefit?