smart_str performance

php.internals

Brian J. France

23 years ago
This was a email I sent to Rasmus and another co-worker a while ago and forgot to post the question to the list. I just saw a commit converting zlib to smart_str and figured I would send it now. Comments? Brian ---- I think I found what you were looking for yesterday. implode has change between 4.3 and 4.2. 4.2 does the double pass while 4.3 has changed to use a new smart_str struct with smart_str_appendl function (a struct and function calls around what I was doing in my extension). I decided to run some quick tests and here is what I have found: for ( $i=0; $i < $count; $i++ ) { $arr[] = rand_string_function(); // 12 characters } $start = gettimeofday(); $str = implode( "", $arr ); $end = gettimeofday(); printf( "%8.8d: %8.8f\n", $count, time_diff( $start, $end ) ); give this output: 4.3: 1: 0.00005100 2: 0.00002800 5: 0.00003700 10: 0.00006000 100: 0.00045600 1000: 0.00478600 10000: 0.06507500 100000: 1.71620700 4.2: 1: 0.00004700 2: 0.00002500 5: 0.00002800 10: 0.00004000 100: 0.00022400 1000: 0.00240700 10000: 0.03677200 100000: 0.37068200 While below 10 items I am sure it is hard to tell the difference, but it is slower in all cases. Any clue why one item is slower than two or even five? Brian

Sterling Hughes

23 years ago
Switched it to avoid a copy on convert_to_string(). Performance in PHP5 now beats the previous version. -Sterling On Wed, 2003-05-21 at 12:36, Brian J. France wrote:
> This was a email I sent to Rasmus and another co-worker a while ago and forgot > to post the question to the list. I just saw a commit converting zlib to > smart_str and figured I would send it now. > > Comments? > > Brian > > ---- > I think I found what you were looking for yesterday. implode has change > between 4.3 and 4.2. 4.2 does the double pass while 4.3 has changed to use a > new smart_str struct with smart_str_appendl function (a struct and function > calls around what I was doing in my extension). I decided to run some > quick tests and here is what I have found: > > for ( $i=0; $i < $count; $i++ ) { > $arr[] = rand_string_function(); // 12 characters > } > > $start = gettimeofday(); > $str = implode( "", $arr ); > $end = gettimeofday(); > printf( "%8.8d: %8.8f\n", $count, time_diff( $start, $end ) ); > > give this output: > > 4.3: > 1: 0.00005100 > 2: 0.00002800 > 5: 0.00003700 > 10: 0.00006000 > 100: 0.00045600 > 1000: 0.00478600 > 10000: 0.06507500 > 100000: 1.71620700 > > 4.2: > 1: 0.00004700 > 2: 0.00002500 > 5: 0.00002800 > 10: 0.00004000 > 100: 0.00022400 > 1000: 0.00240700 > 10000: 0.03677200 > 100000: 0.37068200 > > While below 10 items I am sure it is hard to tell the difference, but it is > slower in all cases. Any clue why one item is slower than two or even five? > > Brian
-- "First they ignore you, then they laugh at you, then they fight you, then you win." - Gandhi

Rasmus Lerdorf

23 years ago
This seems like a trivial bug fix to me. Having implode() get significantly slower from 4.2 to 4.3 doesn't make any sense to me. -Rasmus On 21 May 2003, Sterling Hughes wrote:

Moriyoshi Koizumi

23 years ago
Sterling Hughes <sterling@bumblebury.com> wrote:
> Switched it to avoid a copy on convert_to_string(). Performance in PHP5 > now beats the previous version.
Your patch doesn't seem to work for me. <?php $foo = array(); $array = array(&$foo, &$foo); $test = implode("", $array); var_dump($array); ?> $ php test.php array(2) { [0]=> &string(5) "Array" [1]=> &string(5) "Array" } Moriyoshi

Sterling Hughes

23 years ago
On Wed, 2003-05-21 at 13:17, Moriyoshi Koizumi wrote:
> Sterling Hughes <sterling@bumblebury.com> wrote: > > > Switched it to avoid a copy on convert_to_string(). Performance in PHP5 > > now beats the previous version. > > Your patch doesn't seem to work for me. > > <?php > $foo = array(); > $array = array(&$foo, &$foo); > > $test = implode("", $array); > var_dump($array); > ?> > > $ php test.php > array(2) { > [0]=> > &string(5) "Array" > [1]=> > &string(5) "Array" > }
Well, one shouldn't be passing references, :) but I'll have a quick fix for that, one moment. -Sterling
-- "That stuff's easy compared to installing Horde" - Alan Knowles, In response to my applause for creating a LALR parser for PHP.