Re: Question about performance between for iteration and extension function

From: Date: Fri, 09 Dec 2011 18:29:29 +0000
Subject: Re: Question about performance between for iteration and extension function
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-315966@lists.php.net to get a copy of this message
On Fri, Dec 9, 2011 at 5:04 PM, Lin Yo-An <cornelius.howl@gmail.com> 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

« previous php.general (#315966) next »