|
Posted by Bent Stigsen on 06/21/06 19:39
Juliette wrote:
> Andy Jeffries wrote:
>> On Wed, 21 Jun 2006 20:17:25 +0200, Juliette wrote:
>>> The regex will still win, but I would guess this is slightly faster than
>>> my earlier function.
>>
>> Indeed it is, this function runs in 0.4208 seconds making it the second
>> fasted non-regex function.
Thanks for doing all the stats so far, hope you have time for two more :)
> Cool ! ;-)
> I've looked at Andy's to see what he does and bleeping heck, that's a
> hard one to get my head round, but I can see why that would be faster.
I think you can save a few jiffies by skipping the last entry in the array,
and just add it in the end. Saves you a comparison in the loop.
Like:
$array = explode ( ', ', $string );
$arraycount = ( count($array)-1 );
$string = '';
for( $i=0; $i<$arraycount; $i++ ) {
$string .= ((1&$i) ? ( $array[$i] . '; ' ) : ( $array[$i] . ', ' ));
}
$string .= $array[$i];
> Changing my function to a while loop would probably take yet some more
> of the timing, but I haven't really got the time to do so now.
$array = explode ( ', ', $string );
$string = current($array);
$x1 = null;
$x2 = next($array);
while ($x1=next($array)) {
$string .= ', '. $x2 . '; ' . $x1;
$x2 = next($array);
}
$string .= ', ' . $x2;
So many ways. The thread should have been called "50 ways to change..."
--
/Bent
Navigation:
[Reply to this message]
|