Brain deadness of PHP [message #2119] |
Wed, 01 May 2002 01:43 |
Ilia
Messages: 13241 Registered: January 2002
Karma: 0
|
Senior Member Administrator Core Developer |
|
|
"substr_replace" function was introduced a while back into PHP, in theory it is a wonderful function that allows the user to replace a section of the string with another.
Well, today while coding FUDcode parser, I decided to use that function , I should've known better.
After spending over 1 hour trying to trace the reason behind the slowness of my code I found out that substr_replace function is EXTREMLY slow and becomes exponentially slower as the string size increases. Now the "funny" part using php code I was able to write the same function which was in excess of 100% faster!!!! This should give you some idea as to how badly that function is written, since it is written in C and not PHP, hence should be @ least 10 times faster then anything I write in PHP.
</rantoff>
Moral of this story, DO NOT use substr_replace!
FUDforum Core Developer
|
|
|
|
|
Re: Brain deadness of PHP [message #2132 is a reply to message #2127] |
Wed, 01 May 2002 15:34 |
Ilia
Messages: 13241 Registered: January 2002
Karma: 0
|
Senior Member Administrator Core Developer |
|
|
djupsjob wrote on Wed, 01 May 2002 10:47 AM | You should perhaps consider working on php itself, to get rid of all the crappy things you don't like? I for one would be glad if you did.
|
Well, I've already done some work on php project shmop() module which is a C like implementaion of shared memory in PHP was written by hackie & myself.
If at some future point I have time I may re-write the substr_replace function and submit patch to PHP dev team.
FUDforum Core Developer
|
|
|
Re: Brain deadness of PHP [message #15373 is a reply to message #2119] |
Fri, 12 December 2003 17:12 |
|
Interesting post.
I use PHPLib's template on one of my sites. It's old but reliable. They use
$str = @preg_replace($this->varkeys, $this->varvals, $baseTxt);
Sarah King
|
|
|
Re: Brain deadness of PHP [message #15374 is a reply to message #15373] |
Fri, 12 December 2003 17:21 |
Ilia
Messages: 13241 Registered: January 2002
Karma: 0
|
Senior Member Administrator Core Developer |
|
|
That's ok, I've already rewritten PHP's substr_replace function and it'll works nice and fast as of version 4.3.5 (soon to be released).
FUDforum Core Developer
|
|
|