Created
December 8, 2016 21:50
-
-
Save sminnee/ba90af9edf526eaaa6244ed7f1eb944e to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
| $data1 = [ "bla" => "foo", "whee" => [ "something", [ 1, 2, 3, 4, 5 ] ] ]; | |
| $data2 = [ "baz" => $data1, "heh" => $data1, "yep" => [6, 7, 8, 9 ,10 ] ]; | |
| $data3 = [ $data1, $data2, $data1, $data2, $data1, $data2 ]; | |
| $data4 = [ "something" => $data3, "else" => [$data1, $data2], "heh" => [ $data3, $data3, $data3 ] ]; | |
| print_r($data4); | |
| define('COUNT', 100000); | |
| timeIt("serialize/unserialize", function () use ($data4) { | |
| for ($i=0; $i<COUNT; $i++) { | |
| $ser = serialize($data4); | |
| $cmp = unserialize($ser); | |
| if ($cmp !== $data4) { | |
| echo "Bad data!"; | |
| } | |
| } | |
| }); | |
| timeIt("json_encode/json_decode", function () use ($data4) { | |
| for ($i=0; $i<COUNT; $i++) { | |
| $ser = json_encode($data4); | |
| $cmp = json_decode($ser, true); | |
| if ($cmp !== $data4) { | |
| echo "Bad data!"; | |
| } | |
| } | |
| }); | |
| function timeIt($label, $callback) | |
| { | |
| $t1 = microtime(true); | |
| $callback(); | |
| $t2 = microtime(true); | |
| echo "$label: " . ($t2-$t1) . " seconds\n"; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment