Skip to content

Instantly share code, notes, and snippets.

Created December 9, 2011 18:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/1452696 to your computer and use it in GitHub Desktop.
Save anonymous/1452696 to your computer and use it in GitHub Desktop.
Corrected
<?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( $j = 0 ; $j < $cnt ; $j++ ) {
if( $j > 0 )
$output .= ',';
$output .= $list[ $j ];
}
$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();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment