3v4l.org

run code in 300+ PHP versions simultaneously
<?php $refObjectTime = []; $objectTime = []; $copyArrayTime = []; $refArrayTime = []; function avg($array) { return empty($array) ? 0 : (array_sum($array) / count($array)); } function fooRefObject(&$var) { $var->test = 'bar'; } function fooObject($var) { $var->test = 'bar'; } function fooCopyArray($var) { $var['test'] = 'bar'; } function fooRefArray(&$var) { $var['test'] = 'bar'; } for ($i=0; $i<10000; ++$i) { //Passing object through reference, explicitly $start = microtime(true); $data = new stdclass; fooRefObject($data); $refObjectTime[] = microtime(true) - $start; //Passing object through reference, implicitly $start = microtime(true); $data = new stdclass; fooObject($data); $objectTime[] = microtime(true) - $start; //Passing array through copy-on-write $start = microtime(true); $data = []; fooCopyArray($data); $copyArrayTime[] = microtime(true) - $start; //Passing array through reference $start = microtime(true); $data = []; fooRefArray($data); $refArrayTime[] = microtime(true) - $start; } //Results: echo 'Results:' . PHP_EOL; echo 'Minimums:' . PHP_EOL . ' - Object through reference, explicitly: ' . min($refObjectTime) . PHP_EOL . ' - Object through reference, implicitly: ' . min($objectTime) . PHP_EOL . ' - Array through copy-on-write: ' . min($copyArrayTime) . PHP_EOL . ' - Array through reference: ' . min($refArrayTime) . PHP_EOL; echo 'Maximums:' . PHP_EOL . ' - Object through reference, explicitly: ' . max($refObjectTime) . PHP_EOL . ' - Object through reference, implicitly: ' . max($objectTime) . PHP_EOL . ' - Array through copy-on-write: ' . max($copyArrayTime) . PHP_EOL . ' - Array through reference: ' . max($refArrayTime) . PHP_EOL; echo 'Avergages:' . PHP_EOL . ' - Object through reference, explicitly: ' . avg($refObjectTime) . PHP_EOL . ' - Object through reference, implicitly: ' . avg($objectTime) . PHP_EOL . ' - Array through copy-on-write: ' . avg($copyArrayTime) . PHP_EOL . ' - Array through reference: ' . avg($refArrayTime) . PHP_EOL;

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
7.2.00.0100.01921.57
7.1.70.0100.02018.83
7.1.60.0030.04219.48
7.1.50.0130.03518.85
7.1.00.0130.08324.23
7.0.200.0000.02418.79
7.0.60.0300.09322.30
7.0.50.0100.10020.06
7.0.40.0170.08722.43
7.0.30.0600.07022.46
7.0.20.0800.08722.56
7.0.10.0170.11022.42
7.0.00.0200.10322.25
5.6.280.0070.11726.76
5.6.210.0170.09326.38
5.6.200.0030.08023.66
5.6.190.0370.12026.23
5.6.180.0630.11326.23
5.6.170.0270.17026.07
5.6.160.0430.16026.10
5.6.150.0300.16026.06
5.6.140.0200.17725.79
5.6.130.0230.12025.82
5.6.120.0330.11726.01
5.6.110.0200.11725.76
5.6.100.0400.11325.96
5.6.90.0170.12026.00
5.6.80.0230.12325.42
5.6.70.0300.15025.32
5.6.60.0230.11725.13
5.6.50.0270.10325.15
5.6.40.0330.09725.38
5.6.30.0170.11025.42
5.6.20.0200.11025.41
5.6.10.0200.11025.10
5.6.00.0400.09025.38
5.5.350.0000.07326.16
5.5.340.0030.09023.48
5.5.330.0870.16325.89
5.5.320.0730.14725.99
5.5.310.0430.12725.99
5.5.300.0170.15725.88
5.5.290.0500.14725.84
5.5.280.0300.13025.75
5.5.270.0030.15025.80
5.5.260.0230.13725.66
5.5.250.0330.10325.70
5.5.240.0370.13025.19
5.5.230.0270.11325.30
5.5.220.0430.11025.12
5.5.210.0230.10024.95
5.5.200.0370.10325.07
5.5.190.0230.10325.22
5.5.180.0300.09724.91
5.5.160.0270.10325.18
5.5.150.0170.10725.10
5.5.140.0270.10025.07
5.5.130.0170.11325.11
5.5.120.0370.10725.15
5.5.110.0130.10724.98
5.5.100.0370.13725.04
5.5.90.0130.11025.12
5.5.80.0130.11025.12
5.5.70.0300.09325.05
5.5.60.0130.11725.07
5.5.50.0200.10024.81
5.5.40.0400.14724.84
5.5.30.0200.14324.96
5.5.20.0200.17025.10
5.5.10.0330.11325.00
5.5.00.0230.11724.98

preferences:
41.47 ms | 403 KiB | 5 Q