3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Object hashing tests. */ $sos = new \SplObjectStorage(); $usage = "php %s INTEGER \t - Run the SPLObjectStorage vs. Array test with INTEGER size.\n"; if (count($argv) < 2) { printf($usage, $argv[0]); exit(1); } $docs = array(); $iterations = (int)$argv[1]; //100000; for ($i = 0; $i < $iterations; ++$i) { $doc = new \DOMDocument(); //$doc = new stdClass(); $docs[] = $doc; } $start = $finis = 0; $mem_empty = memory_get_usage(); // Load the SplObjectStorage $start = microtime(TRUE); foreach ($docs as $d) { $sos->attach($d); } $finis = microtime(TRUE); $time_to_fill = $finis - $start; // Check membership on the object storage $start = microtime(FALSE); foreach ($docs as $d) { $sos->contains($d); } $finis = microtime(FALSE); $time_to_check = $finis - $start; $mem_spl = memory_get_usage(); $mem_used = $mem_spl - $mem_empty; printf("SplObjectStorage:\nTime to fill: %0.12f.\nTime to check: %0.12f.\nMemory: %d\n\n", $time_to_fill, $time_to_check, $mem_used); unset($sos); $mem_empty = memory_get_usage(); // Test arrays: $start = microtime(TRUE); $arr = array(); // Load the array foreach ($docs as $d) { $arr[spl_object_hash($d)] = $d; } $finis = microtime(TRUE); $time_to_fill = $finis - $start; // Check membership on the array $start = microtime(FALSE); foreach ($docs as $d) { //$arr[spl_object_hash($d)]; isset($arr[spl_object_hash($d)]); } $finis = microtime(FALSE); $time_to_check = $finis - $start; $mem_arr = memory_get_usage(); $mem_used = $mem_arr - $mem_empty; printf("Arrays:\nTime to fill: %0.12f.\nTime to check: %0.12f.\nMemory: %d\n\n", $time_to_fill, $time_to_check, $mem_used);
Output for 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.26, 7.3.0 - 7.3.13, 7.4.0 - 7.4.1
php /in/oWDSq INTEGER - Run the SPLObjectStorage vs. Array test with INTEGER size.
Process exited with code 1.
Output for 5.1.0 - 5.1.6, 5.2.0 - 5.2.17
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/oWDSq on line 5 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/oWDSq on line 17 php /in/oWDSq INTEGER - Run the SPLObjectStorage vs. Array test with INTEGER size.
Process exited with code 1.
Output for 5.0.0 - 5.0.5
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/oWDSq on line 5 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/oWDSq on line 17 Fatal error: Class 'SplObjectStorage' not found in /in/oWDSq on line 5
Process exited with code 255.
Output for 4.3.2 - 4.3.11, 4.4.0 - 4.4.9
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/oWDSq on line 5 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/oWDSq on line 17 Fatal error: Cannot instantiate non-existent class: splobjectstorage in /in/oWDSq on line 5
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/oWDSq on line 5 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/oWDSq on line 17 Fatal error: Cannot instantiate non-existent class: splobjectstorage in /in/oWDSq on line 5

preferences:
195.23 ms | 402 KiB | 325 Q