3v4l.org

run code in 300+ PHP versions simultaneously
<?php $sos = new SplObjectStorage(); $arr = array(); $docs = array(); $iterations = 50000; for ($i = 0; $i < $iterations; ++$i) { $doc = new DOMDocument(); $docs[] = $doc; } $mem_empty = memory_get_usage(); // Load the SplObjectStorage $start = microtime(true); foreach ($docs as $d) { $sos->attach($d); //$sos[$d] = 1; } $finis = microtime(true); $time_to_fill = $finis - $start; // Check membership on the object storage $start = microtime(true); foreach ($docs as $d) { $sos->contains($d); //isset($sos[$d]); } $finis = microtime(true); $time_to_check = $finis - $start; $mem_spl = memory_get_usage(); $mem_used = $mem_spl - $mem_empty; printf("SplObjectStorage:\nTime to fill: %0.12f ms\nTime to check: %0.12f ms\nMemory: %d\n\n", $time_to_fill * 1000, $time_to_check * 1000, $mem_used); unset($sos); $mem_empty = memory_get_usage(); // Load the array $start = microtime(true); foreach ($docs as $d) { $arr[spl_object_id($d)] = $d; } $finis = microtime(true); $time_to_fill = $finis - $start; // Check membership on the array $start = microtime(true); foreach ($docs as $d) { isset($arr[spl_object_id($d)]); } $finis = microtime(true); $time_to_check = $finis - $start; $mem_arr = memory_get_usage(); $mem_used = $mem_arr - $mem_empty; printf("Arrays:\nTime to fill: %0.12f ms\nTime to check: %0.12f ms\nMemory: %d\n\n", $time_to_fill * 1000, $time_to_check * 1000, $mem_used);
Output for 8.4.3
SplObjectStorage: Time to fill: 6.856918334961 ms Time to check: 2.297163009644 ms Memory: 2252728 Arrays: Time to fill: 1.219987869263 ms Time to check: 0.760078430176 ms Memory: 1052728
Output for 8.3.16
SplObjectStorage: Time to fill: 27.591943740845 ms Time to check: 13.853073120117 ms Memory: 2252728 Arrays: Time to fill: 0.967025756836 ms Time to check: 0.787973403931 ms Memory: 1052728
Output for 8.2.27
SplObjectStorage: Time to fill: 19.193172454834 ms Time to check: 13.407945632935 ms Memory: 2252728 Arrays: Time to fill: 0.950098037720 ms Time to check: 0.789880752563 ms Memory: 1052728
Output for 8.1.31
SplObjectStorage: Time to fill: 13.749122619629 ms Time to check: 5.734920501709 ms Memory: 3301328 Arrays: Time to fill: 3.490924835205 ms Time to check: 1.507997512817 ms Memory: 2101328
Output for 7.4.33
SplObjectStorage: Time to fill: 14.916896820068 ms Time to check: 5.719900131226 ms Memory: 5302864 Arrays: Time to fill: 3.118038177490 ms Time to check: 1.610040664673 ms Memory: 2101328
Output for 5.6.40
SplObjectStorage: Time to fill: 21.255970001221 ms Time to check: 16.505956649780 ms Memory: 10525632 Fatal error: Call to undefined function spl_object_id() in /in/CZjfW on line 51
Process exited with code 255.

preferences:
56.78 ms | 412 KiB | 5 Q