-
-
Save c9s/b2a94c94ca66a55814d4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require( 'src/Phifty/TaskTimer.php' ); | |
use Phifty\TaskTimer; | |
$size = 1000; | |
echo "n=$size\n"; | |
$timer = new TaskTimer; | |
$timer->start( 'pure php iteration' ); | |
$list = range(1,1000); | |
for( $i = 0 ; $i < $size ; $i++ ) { | |
$output = ''; | |
$output .= '['; | |
$cnt = count($list); | |
for( $i = 0 ; $i < $cnt ; $i++ ) { | |
if( $i > 0 ) | |
$output .= ','; | |
$output .= $list[ $i ]; | |
} | |
$output .= ']'; | |
} | |
$timer->end()->report(); | |
$timer->start( 'via string join' ); | |
for( $i = 0 ; $i < $size ; $i++ ) { | |
$output = '[' . join(',',$list) . ']'; | |
} | |
$timer->end()->report(); | |
$timer->start( 'json_encode' ); | |
for( $i = 0 ; $i < $size ; $i++ ) { | |
$oiutput = json_encode( $list ); | |
} | |
$timer->end()->report(); |
Author
c9s
commented
Dec 9, 2011
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment