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

Home » General » PHP discussions » Brain deadness of PHP
Show: Today's Messages :: Unread Messages :: Show Polls :: Message Navigator
| Subscribe to topic | Bookmark topic 
Switch to threaded view of this topic Create a new topic Submit Reply
Brain deadness of PHP [message #2119] Tue, 30 April 2002 21:43 Go to next message
Ilia is currently offline  Ilia   Canada
Messages: 13241
Registered: January 2002
Karma: 0
Senior Member
Administrator
Core Developer
add to buddy list
ignore all messages by this user
"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] Tue, 30 April 2002 22:17 Go to previous messageGo to next message
Olliver   Germany
Messages: 443
Registered: March 2002
Karma: 0
Senior Member
add to buddy list
ignore all messages by this user
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 10: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
add to buddy list
ignore all messages by this user
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 11: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
add to buddy list
ignore all messages by this user
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 12: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
add to buddy list
ignore all messages by this user

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 12:21 Go to previous message
Ilia is currently offline  Ilia   Canada
Messages: 13241
Registered: January 2002
Karma: 0
Senior Member
Administrator
Core Developer
add to buddy list
ignore all messages by this user
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
Quick Reply
Formatting Tools:   
  Switch to threaded view of this topic Create a new topic
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: Mon Dec 18 06:04:13 EST 2017

Total time taken to generate the page: 0.00616 seconds