On Mon, 03 Jun 2013 10:55:16 +0200, Dmitry Stogov <[email protected]> wrote:
I didn't look into the code yet (and really don't like to do it), but we
just noticed terrible performance degradation of strtr() function between
5.4.11 and 5.4.15 coming probably after your changes.
$ cat strtr.php
<?php
function foo() {
for ($i = 0; $i < 100000; $i++) {
strtr("abcdefgh", array("a"=>"11", "g"=>"22"));
}
}
foo();
Your example is basically a worst-case scenario of the new algorithm and a
best-case scenario of the old one. The new algorithm has a more costly
preprocessing step and its gains are the smallest when the minimum pattern
size is 1. That combined with a very short text makes the cost of the
preprocessing step dominate.
For strtr(str_repeat("abcdefgh", 50), ...) the results are very close and
for 100 repeats the new algorithm is already faster. It also does not have
cases of multi-second runs in relatively small inputs like the old
algorithm (see https://bugs.php.net/bug.php?id=63893 ); you're talking
about function calls that still execute in around 7 microseconds.
That said, there certainly is an argument for using the old algorithm for
short inputs, as its preprocessing step is much cheaper. It will require
some experimentation in order to determine the cutoff, but if you think
it's important I can do it (you're welcome to do it as well).
Regards
--
Gustavo Lopes
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php