ID:               45265
 Comment by:       foruns at dan dot mus dot br
 Reported By:      marc at phpmyadmin dot net
 Status:           Assigned
 Bug Type:         Performance problem
 Operating System: win32 only
 PHP Version:      5.2CVS-2008-08-10
 Assigned To:      pajoye
 New Comment:

I'm running PHP 5.2.6 in a G4 iBook PPC and I'm experiencing extremely
low performance using that function. 

I intended to use stripos() inside a loop to retrieve the positions of
multiple DIV elements in a HTML page, increasing the offset value
accordingly.

But, on a 64kb document, it would take from 0.4sec to 2.5sec to find
each "<div" string.

Strpos() would take as little as 0.004sec on the same document.

Daniel


Previous Comments:
------------------------------------------------------------------------

[2008-08-11 00:34:09] ni...@php.net

And according to
http://msdn.microsoft.com/en-us/library/8h19t214(VS.80).aspx _tolower's
Windows implentation isn't ANSI.

------------------------------------------------------------------------

[2008-08-11 00:15:45] ni...@php.net

Nice work Pierre but according to MSDN and yourself, _tolower's Windows
implementation is clearly faster than tolower but has undefined results
if the character is not ASCII... And we can't rely on that... can we?

According to libc, tolower checks the locale too... And _lower on libc
is quite different than Windows's since the _tolower() function is
identical to tolower() except that c must be an upper-case letter.

So...

------------------------------------------------------------------------

[2008-08-10 23:41:53] paj...@php.net

The problem is that the Windows API does check for the locale while
processing the string (isupper, islower used by tolower or toupper).

Using _tolower/_toupper only speed up the functions using it (as fast
or faster than linux). But it does not work for non ASCII input.

I have to check is libc does check for locale as well, if not, I will
happily use _tolower on windows too.

That being said, it may be used too in zend then. tolower is used
*many* times there.

------------------------------------------------------------------------

[2008-08-10 17:01:44] ni...@php.net

It seems it's a php_strtolower() issue because we have the same problem
by replacing stripos to strtolower...

The problem occurs on Windows also with strtolower()...

71 seconds on Windows, 25s on linux...

Reproduce code:
$a = str_repeat('x', 100000);
for ($i = 0; $i < 10000; $i++) {
        $b = strtolower($a);
}


------------------------------------------------------------------------

[2008-06-13 17:44:20] marc at phpmyadmin dot net

Description:
------------
stripos() is very slow on Windows, about ten times slower than on
Linux. 

Reproduce code:
---------------
$a = str_repeat('x', 100000);
for ($i = 0; $i < 10000; $i++) {
        $b = stripos($a, 'y');
}


Expected result:
----------------
On Linux it takes about 3 secondes.

Actual result:
--------------
On Windows: 30 seconds


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=45265&edit=1

Reply via email to