On Fri, Dec 9, 2011 at 5:04 PM, Lin Yo-An <cornelius.h...@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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php