good chemistry is complicated, and a little bit messy -LW |
|
PerlMonks |
Re^6: Performance penalty of using qr//by vr (Curate) |
on Dec 22, 2017 at 19:26 UTC ( [id://1206065]=note: print w/replies, xml ) | Need Help?? |
C + NM, which was what your benchmark was measuring Having read your answers and this -- 269035 -- thread, maybe it's better to say that in case of "use_str" benchmark was measuring C + 2268 * ( 5 - time_for_C ) * 11 * ( M + E ) where E is "light-weight" compilation, consisting only of string equality (eq) check? Next example shows that "proper" compilation happens just once, if I'm reading output correctly:
("use_re" benchmarked concatenation of 45000 words, BTW. Similar, to above, script shows proper compilation happens only once, too.) And "time_for_C" is negligible, we can compile regexp placing dummy /$str/ at the top of the script, and benchmark result won't change. Moreover:
To summarize, if I may: if pattern is "long enough", then D (time to duplicate the regex structure) is much less than E (time to compare patterns with simple "eq"). For short patterns (as in OP), D is more expensive than E (even multiple E's), so attempt to optimize through use of "qr" failed. Edit. People "lucky" enough to hit 0..3 with "rand 400_000" should change offset in "substr" to "4 + rand 400_000". :( Edit 2. I mean, you say: if "N(M+D)" is so much faster than "C+NM", then it's C that is so slow, but I think, no, C is negligible, it's rather "N(M+D)" is faster than "C+N(M+E)" because D is faster than E. Sorry I haven't communicated this thought without edits.
In Section
Seekers of Perl Wisdom
|
|