Last active
August 29, 2015 13:57
-
-
Save PEKTOP/9839722 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 | |
$data_json = json_encode(array('one','two','three','four','five','six','seven','eight','nine')); | |
$data_with_delimiter = "one|two|three|four|five|six|seven|eight|nine"; | |
/* | |
|------------------------------------------------------------------------------ | |
| Performance test # 1 | |
|------------------------------------------------------------------------------ | |
*/ | |
$start = microtime(true); | |
for ($i = 0; $i < 100000; $i++) | |
{ | |
$data = json_decode($data_json); | |
} | |
$end = microtime(true); | |
$final = $end - $start; | |
echo "Json decode as stdObject: " . $final . "\n"; | |
/* | |
|------------------------------------------------------------------------------ | |
| Performance test # 2 | |
|------------------------------------------------------------------------------ | |
*/ | |
$start = microtime(true); | |
for ($i = 0; $i < 100000; $i++) | |
{ | |
$data = json_decode($data_json, true); | |
} | |
$end = microtime(true); | |
$final = $end - $start; | |
echo "Json decode as associative array: " . $final . "\n"; | |
/* | |
|------------------------------------------------------------------------------ | |
| Performance test # 3 | |
|------------------------------------------------------------------------------ | |
*/ | |
$start = microtime(true); | |
for ($i = 0; $i < 100000; $i++) | |
{ | |
$data = explode('|', $data_with_delimiter); | |
} | |
$end = microtime(true); | |
$final = $end - $start; | |
echo "Explode by delimiter as array: " . $final . "\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment