Last active
August 29, 2015 13:59
-
-
Save borkweb/10739054 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 | |
$loops = 1000000; | |
$start = microtime( TRUE ); | |
for ( $i = 0; $i < $loops; $i++ ) { | |
$thing = (object) array( | |
'cat' => (object) array( | |
'name' => 'Mr. Giggles', | |
'age' => 3, | |
), | |
'door' => (object) array( | |
'age' => 1, | |
), | |
); | |
}//end for | |
$total = microtime( TRUE ) - $start; | |
$avg = $total / $loops; | |
echo "Average for casting: {$total}s ( {$avg}s )\n"; | |
$start = microtime( TRUE ); | |
for ( $i = 0; $i < $loops; $i++ ) { | |
$thing = '{ "cat": { "name": "Mr. Giggles", "age": 3 }, "door" : { "age": 1 } }'; | |
json_decode( $thing ); | |
}//end for | |
$total = microtime( TRUE ) - $start; | |
$avg = $total / $loops; | |
echo "Average for json_decode: {$total}s ( {$avg}s )\n"; | |
$start = microtime( TRUE ); | |
for ( $i = 0; $i < $loops; $i++ ) { | |
$thing = new stdClass; | |
$thing->cat = new stdClass; | |
$thing->cat->name = 'Mr. Giggles'; | |
$thing->cat->age = 3; | |
$thing->door = new stdClass; | |
$thing->door->age = 1; | |
}//end for | |
$total = microtime( TRUE ) - $start; | |
$avg = $total / $loops; | |
echo "Average for stdClass: {$total}s ( {$avg}s )\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment