Re: Question about performance between for iteration and extension function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Dec 9, 2011 at 5:04 PM, Lin Yo-An <cornelius.howl@xxxxxxxxx> wrote:
> Hi folks,
>
> I am in doubt of this, I thought pure php iteration is slower than calling
> join or other extension functions.
>
> but the result shows:  https://gist.github.com/b2a94c94ca66a55814d4
>
> Using Pure PHP for iteration is faster than using join function. why ?
> because of the php runtime typecasting ?
>
> And json_encode is the most slowest.

There's a bug in your first test (the php iteration). You're using $i
for the inner and outer loop, meaning that the outer loop will only
run once.  Try this updated example:
https://gist.github.com/1452696

On my box it gives(with microtime instead of your timer class):
php join.php
n=1000
Pure PHP iteration: 0.87661409378052

String join: 0.13562703132629

json_encode: 0.081185102462769

json_encode is the fastest one here.

Matijn

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux