The main difference probably isn't your computer vs. my computer. You left out the regex solutions which (the first time that the first one is called) "modify" the global $x by providing it with a string value.
Since the chop solution makes a copy in order to avoid changing the value of the global $x, it also doesn't give the global $x a string value. So if the chop solution is run first, it has to stringify $x for every single call (as in your two runs but not in mine).
Your substr solution also gives the global $x a string value, but it is getting run after the chop solution so it doesn't help (in my run, all of the regex solutions were run before the chop solution).
So for another way to compare the regular expression versions to the mod version, you could force a stringification per call. I didn't come up with an eligant way to do this (and I came up with some pretty interesting but non-intuitive and mutually contradictory benchmark numbers so I'll just leave this to someone else).
- tye (but my friends call me "Tye")In reply to (tye)Re2: japhy regex analysis: case study (RE question...)
by tye
in thread RE question...yup, another one ;)
by snafu
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |