Skip to content

Instantly share code, notes, and snippets.

@PEKTOP
Last active August 29, 2015 13:57
Show Gist options
  • Save PEKTOP/9839722 to your computer and use it in GitHub Desktop.
Save PEKTOP/9839722 to your computer and use it in GitHub Desktop.
<?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