FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » General » PHP discussions » Brain deadness of PHP
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
Brain deadness of PHP [message #2119] Wed, 01 May 2002 01:43 Go to next message
Ilia is currently offline  Ilia   Canada
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 #2122 is a reply to message #2119] Wed, 01 May 2002 02:17 Go to previous messageGo to next message
Olliver   Germany
Messages: 443
Registered: March 2002
Karma: 0
Senior Member
Luckily I haven't used this before Wink But seems to be interesting to play around with if it causes such nice effects...
bye Ken
Re: Brain deadness of PHP [message #2127 is a reply to message #2119] Wed, 01 May 2002 14:47 Go to previous messageGo to next message
basse is currently offline  basse   Finland
Messages: 164
Registered: March 2002
Location: Åbo, Finland
Karma: 0
Senior Member
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.
Re: Brain deadness of PHP [message #2132 is a reply to message #2127] Wed, 01 May 2002 15:34 Go to previous messageGo to next message
Ilia is currently offline  Ilia   Canada
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 Go to previous messageGo to next message
sarahk is currently offline  sarahk   New Zealand
Messages: 3
Registered: December 2003
Location: New Zealand
Karma: 0
Junior Member

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 Go to previous message
Ilia is currently offline  Ilia   Canada
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
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: ob_start, ob_gzhandler
Next Topic: Differences in the definition of a string.
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sat Nov 23 09:50:46 GMT 2024

Total time taken to generate the page: 0.02255 seconds