3v4l.org

run code in 300+ PHP versions simultaneously
<?php interface BarInterface{} function getMemoryUsage($size){ static $unit=['b','kb','mb','gb','tb','pb']; return $size > 0 ? @round($size/pow(1024,($i=floor(log($size,1024)))),2).' '.$unit[$i] : 0 . ' byte'; } class Bar implements BarInterface { public function run() { return true; } } class Foo { public function variadic(\BarInterface ...$bars) { foreach ($bars as $bar) { $bar->run(); } } public function iterated(array $bars) { foreach ($bars as $bar) { if (!$bar instanceof \BarInterface) { throw new \TypeError('Invalid BarInterface specified'); } } foreach ($bars as $bar) { $bar->run(); } } } $bars = []; for ($i=0; $i<10000 ;$i++) { $bars[] = new \Bar(); } $foo = new Foo(); $items = \count($bars); //initial call to reduce overhead $foo->variadic(...[]); $foo->iterated([]); microtime(true); memory_get_usage(true); //benchmark start $start = new \DateTime(); $mem_start = memory_get_usage(true); $foo->variadic(...$bars); $mem_variadic = memory_get_usage(true); $variadic = new \DateTime(); $variadicDiff = $start->diff($variadic)->format('%f'); printf('%sms (variadic passed %d %s increase)', $variadicDiff, $items, getMemoryUsage($mem_variadic-$mem_start)); echo \PHP_EOL . '--------' . \PHP_EOL; $start = new \DateTime(); $mem_start = memory_get_usage(true); $foo->iterated($bars); $mem_iterated = memory_get_usage(true); $iterated = new \DateTime(); $iteratedDiff = $start->diff($iterated)->format('%f'); printf('%sms (iterated passed %d %s increase)', $iteratedDiff, $items, getMemoryUsage($mem_iterated-$mem_start)); echo \PHP_EOL . '--------' . \PHP_EOL; if ($variadicDiff > $iteratedDiff) { $loser = 'Variadic'; $diff = $variadicDiff - $iteratedDiff; $loss = $diff / $iteratedDiff; } else { $loser = 'Iterated'; $diff = $iteratedDiff - $variadicDiff; $loss = $diff / $variadicDiff; } printf('%s was slower by %.2f%% (%d ms)', $loser, $loss * 100, $diff);
Output for 7.4.1
1229ms (variadic passed 10000 2 mb increase) -------- 616ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 99.51% (613 ms)
Output for 7.4.0
1557ms (variadic passed 10000 2 mb increase) -------- 752ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 107.05% (805 ms)
Output for 7.3.13
1616ms (variadic passed 10000 2 mb increase) -------- 780ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 107.18% (836 ms)
Output for 7.3.12
1567ms (variadic passed 10000 2 mb increase) -------- 800ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 95.88% (767 ms)
Output for 7.3.11
1630ms (variadic passed 10000 2 mb increase) -------- 774ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 110.59% (856 ms)
Output for 7.3.10
1329ms (variadic passed 10000 2 mb increase) -------- 699ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 90.13% (630 ms)
Output for 7.3.9
1271ms (variadic passed 10000 2 mb increase) -------- 617ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 106.00% (654 ms)
Output for 7.3.8
1525ms (variadic passed 10000 2 mb increase) -------- 623ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 144.78% (902 ms)
Output for 7.3.7
1178ms (variadic passed 10000 2 mb increase) -------- 610ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 93.11% (568 ms)
Output for 7.3.6
1403ms (variadic passed 10000 2 mb increase) -------- 791ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 77.37% (612 ms)
Output for 7.3.5
1635ms (variadic passed 10000 2 mb increase) -------- 781ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 109.35% (854 ms)
Output for 7.3.4
1281ms (variadic passed 10000 2 mb increase) -------- 686ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 86.73% (595 ms)
Output for 7.3.3
1699ms (variadic passed 10000 2 mb increase) -------- 905ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 87.73% (794 ms)
Output for 7.3.2
1655ms (variadic passed 10000 2 mb increase) -------- 793ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 108.70% (862 ms)
Output for 7.3.1
1817ms (variadic passed 10000 2 mb increase) -------- 1041ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 74.54% (776 ms)
Output for 7.3.0
1837ms (variadic passed 10000 2 mb increase) -------- 1066ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 72.33% (771 ms)
Output for 7.2.26
2393ms (variadic passed 10000 2 mb increase) -------- 1891ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 26.55% (502 ms)
Output for 7.2.25
2336ms (variadic passed 10000 2 mb increase) -------- 1882ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 24.12% (454 ms)
Output for 7.2.24
2234ms (variadic passed 10000 2 mb increase) -------- 1162ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 92.25% (1072 ms)
Output for 7.2.23
1784ms (variadic passed 10000 2 mb increase) -------- 1775ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 0.51% (9 ms)
Output for 7.2.22
2346ms (variadic passed 10000 2 mb increase) -------- 1557ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 50.67% (789 ms)
Output for 7.2.21
2195ms (variadic passed 10000 2 mb increase) -------- 1145ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 91.70% (1050 ms)
Output for 7.2.20
2565ms (variadic passed 10000 2 mb increase) -------- 1150ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 123.04% (1415 ms)
Output for 7.2.19
1971ms (variadic passed 10000 2 mb increase) -------- 1276ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 54.47% (695 ms)
Output for 7.2.18
1999ms (variadic passed 10000 2 mb increase) -------- 1219ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 63.99% (780 ms)
Output for 7.2.17
2031ms (variadic passed 10000 2 mb increase) -------- 1317ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 54.21% (714 ms)
Output for 7.2.16
2492ms (variadic passed 10000 2 mb increase) -------- 1555ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 60.26% (937 ms)
Output for 7.2.15
2553ms (variadic passed 10000 2 mb increase) -------- 1487ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 71.69% (1066 ms)
Output for 7.2.14
2261ms (variadic passed 10000 2 mb increase) -------- 1363ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 65.88% (898 ms)
Output for 7.2.13
2066ms (variadic passed 10000 2 mb increase) -------- 1225ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 68.65% (841 ms)
Output for 7.2.12
2341ms (variadic passed 10000 2 mb increase) -------- 1132ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 106.80% (1209 ms)
Output for 7.2.11
2068ms (variadic passed 10000 2 mb increase) -------- 1289ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 60.43% (779 ms)
Output for 7.2.10
2779ms (variadic passed 10000 2 mb increase) -------- 1333ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 108.48% (1446 ms)
Output for 7.2.9
2206ms (variadic passed 10000 2 mb increase) -------- 1117ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 97.49% (1089 ms)
Output for 7.2.8
1786ms (variadic passed 10000 2 mb increase) -------- 1118ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 59.75% (668 ms)
Output for 7.2.7
1849ms (variadic passed 10000 2 mb increase) -------- 1135ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 62.91% (714 ms)
Output for 7.2.6
1873ms (variadic passed 10000 2 mb increase) -------- 1210ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 54.79% (663 ms)
Output for 7.2.5
2229ms (variadic passed 10000 2 mb increase) -------- 1113ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 100.27% (1116 ms)
Output for 7.2.4
1797ms (variadic passed 10000 2 mb increase) -------- 1144ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 57.08% (653 ms)
Output for 7.2.3
1881ms (variadic passed 10000 2 mb increase) -------- 1187ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 58.47% (694 ms)
Output for 7.2.2
2702ms (variadic passed 10000 2 mb increase) -------- 1494ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 80.86% (1208 ms)
Output for 7.2.1
2614ms (variadic passed 10000 2 mb increase) -------- 1581ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 65.34% (1033 ms)
Output for 7.2.0
1954ms (variadic passed 10000 2 mb increase) -------- 1186ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 64.76% (768 ms)
Output for 7.1.33
2322ms (variadic passed 10000 2 mb increase) -------- 1756ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 32.23% (566 ms)
Output for 7.1.32
3392ms (variadic passed 10000 2 mb increase) -------- 2639ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 28.53% (753 ms)
Output for 7.1.31
2484ms (variadic passed 10000 2 mb increase) -------- 2016ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 23.21% (468 ms)
Output for 7.1.30
2781ms (variadic passed 10000 2 mb increase) -------- 2262ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 22.94% (519 ms)
Output for 7.1.29
3348ms (variadic passed 10000 2 mb increase) -------- 2718ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 23.18% (630 ms)
Output for 7.1.28
2342ms (variadic passed 10000 2 mb increase) -------- 2032ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 15.26% (310 ms)
Output for 7.1.27
2197ms (variadic passed 10000 2 mb increase) -------- 1774ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 23.84% (423 ms)
Output for 7.1.26
2656ms (variadic passed 10000 2 mb increase) -------- 2077ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 27.88% (579 ms)
Output for 7.1.25
3332ms (variadic passed 10000 2 mb increase) -------- 2768ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 20.38% (564 ms)
Output for 7.1.24
2930ms (variadic passed 10000 2 mb increase) -------- 2333ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 25.59% (597 ms)
Output for 7.1.23
3385ms (variadic passed 10000 2 mb increase) -------- 1707ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 98.30% (1678 ms)
Output for 7.1.22
2330ms (variadic passed 10000 2 mb increase) -------- 1840ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 26.63% (490 ms)
Output for 7.1.21
2190ms (variadic passed 10000 2 mb increase) -------- 1694ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 29.28% (496 ms)
Output for 7.1.20
2040ms (variadic passed 10000 2 mb increase) -------- 1835ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 11.17% (205 ms)
Output for 7.1.19
2222ms (variadic passed 10000 2 mb increase) -------- 1813ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 22.56% (409 ms)
Output for 7.1.18
2136ms (variadic passed 10000 2 mb increase) -------- 1756ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 21.64% (380 ms)
Output for 7.1.17
2262ms (variadic passed 10000 2 mb increase) -------- 1831ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 23.54% (431 ms)
Output for 7.1.16
2588ms (variadic passed 10000 2 mb increase) -------- 2116ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 22.31% (472 ms)
Output for 7.1.15
2964ms (variadic passed 10000 2 mb increase) -------- 2391ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 23.96% (573 ms)
Output for 7.1.14
2276ms (variadic passed 10000 2 mb increase) -------- 1755ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 29.69% (521 ms)
Output for 7.1.13
2229ms (variadic passed 10000 2 mb increase) -------- 1755ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 27.01% (474 ms)
Output for 7.1.12
2281ms (variadic passed 10000 2 mb increase) -------- 1912ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 19.30% (369 ms)
Output for 7.1.11
2150ms (variadic passed 10000 2 mb increase) -------- 1781ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 20.72% (369 ms)
Output for 7.1.10
2281ms (variadic passed 10000 2 mb increase) -------- 1764ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 29.31% (517 ms)
Output for 7.1.9
2328ms (variadic passed 10000 2 mb increase) -------- 1790ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 30.06% (538 ms)
Output for 7.1.8
2990ms (variadic passed 10000 2 mb increase) -------- 1906ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 56.87% (1084 ms)
Output for 7.1.7
3836ms (variadic passed 10000 2 mb increase) -------- 1872ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 104.91% (1964 ms)
Output for 7.1.6
2392ms (variadic passed 10000 2 mb increase) -------- 1861ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 28.53% (531 ms)
Output for 7.1.5
3359ms (variadic passed 10000 2 mb increase) -------- 2632ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 27.62% (727 ms)
Output for 7.1.4
2932ms (variadic passed 10000 2 mb increase) -------- 2398ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 22.27% (534 ms)
Output for 7.1.3
0ms (variadic passed 10000 2 mb increase) -------- 0ms (iterated passed 10000 0 byte increase) -------- Warning: Division by zero in /in/JMrsq on line 78 Iterated was slower by NaN% (0 ms)
Output for 7.1.2
2826ms (variadic passed 10000 2 mb increase) -------- 2282ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 23.84% (544 ms)
Output for 7.1.1
2242ms (variadic passed 10000 2 mb increase) -------- 1707ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 31.34% (535 ms)
Output for 7.1.0
2336ms (variadic passed 10000 2 mb increase) -------- 1879ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 24.32% (457 ms)