in reply to elsif chain vs. dispatch
Even though looking up an element of a hash tends to be an O(1) operation, its algorithmic complexity only describes the scaling factor of the algorithm as n increases. If you rearranged the if/else branches in decreasing order of probability according to your expected corpus, it would be faster than the hash lookup until you reached (wild guess) a dozen or so entries in the hash, or if your working corpus deviated significantly from your expected corpus.
A good benchmark with working example data would reveal more, but remember that:
- This depends on your version of Perl, your workload, and your machine.
- Getting the best performance possible is a matter of tuning.
- Perl is sensitive to fluctuations between different optrees and working sets.
- This is unlikely a bottleneck in any meaningful application.