Created
August 11, 2010 04:58
-
-
Save katanacrimson/518512 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 | |
$mode = 'php'; | |
benchmark(); | |
$data = array('some_array' => array('another_array' => array('some_string'))); | |
for($i = 0; $i <= 2000; $i++) | |
{ | |
if($mode == 'json') | |
{ | |
json_decode(json_encode($data), true); | |
} | |
elseif($mode == 'php') | |
{ | |
unserialize(serialize($data)); | |
} | |
} | |
echo $mode . ' - '; | |
benchmark(); | |
die(); | |
function getTime() | |
{ | |
$timer = explode(' ', microtime()); | |
return $timer[1] + $timer[0]; | |
} | |
function benchmark() | |
{ | |
static $start = 0; | |
if(!$start) | |
$start = getTime(); | |
else | |
echo round(getTime() - $start, 6) . ' seconds' . PHP_EOL; | |
} |
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
obsidian@lithion-mint ~/Documents $ php benchmark.php | |
json - 0.027227 seconds | |
obsidian@lithion-mint ~/Documents $ php benchmark.php | |
json - 0.018487 seconds | |
obsidian@lithion-mint ~/Documents $ php benchmark.php | |
json - 0.01908 seconds | |
obsidian@lithion-mint ~/Documents $ php benchmark.php | |
json - 0.019124 seconds | |
obsidian@lithion-mint ~/Documents $ php benchmark.php | |
json - 0.018601 seconds | |
obsidian@lithion-mint ~/Documents $ php benchmark.php | |
php - 0.016961 seconds | |
obsidian@lithion-mint ~/Documents $ php benchmark.php | |
php - 0.016656 seconds | |
obsidian@lithion-mint ~/Documents $ php benchmark.php | |
php - 0.01743 seconds | |
obsidian@lithion-mint ~/Documents $ php benchmark.php | |
php - 0.017042 seconds | |
obsidian@lithion-mint ~/Documents $ php benchmark.php | |
php - 0.017177 seconds |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment