So, the thing that always happens happened. When you post something about which modules you use, or how the behave, perl folks come out of the woodwork to tell you all about how you got it wrong some new module you should be using, or how awesome some other module is.
Mind you, this is one of the greatest things about the perl community in general. Y’all sure are a vocal bunch. So, in particular I was told:
- I don’t understand constant folding. Which, whether true or not, isn’t really relevant for my original point, which was “golly this behavior is unexpected and surprising”
- I should be using Const::Fast, because it is better than Readonly.
So, here’s some code I wrote up:
It basically has 3 subs, one for constant, one for Readonly, and one for Const::Fast. It Dumper’s and Deparses the code (so we can see what awesome constant folding is happening (and it is awesome.)) It then uses the lovely Dumbbench module to benchmark them and see the actual difference. Here are the results:
So, I can’t really see a massive performance difference or compelling difference. Mind you, there *is* a performance difference, but like, we’re talking microseconds here right? I understand TIMTOWTDI. I ❤ that about perl. This time, I simply don’t get the benefits.
UPDATE: Holy crap, some nice commenter fellow sent me a link to a page in which someone compared 21 ways of doing constants in perl on CPAN. 21. There are 21 different solutions on how to do constants on CPAN. What a grim, meathook future.