More on constants in perl

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:

  1. 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”
  2. 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.

This entry was posted in tech and tagged , , . Bookmark the permalink.

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s