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 { } class Foo { public function variadic(\BarInterface ...$bars){} public function iterated(array $bars){} } $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 $mem_start = memory_get_usage(true); $start = new \DateTime(); $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; $mem_start = memory_get_usage(true); $start = new \DateTime(); $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.0
975ms (variadic passed 10000 2 mb increase) -------- 5ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 19400.00% (970 ms)
Output for 7.3.12
1220ms (variadic passed 10000 2 mb increase) -------- 7ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 17328.57% (1213 ms)
Output for 7.3.11
1439ms (variadic passed 10000 2 mb increase) -------- 7ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 20457.14% (1432 ms)
Output for 7.3.10
1254ms (variadic passed 10000 2 mb increase) -------- 7ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 17814.29% (1247 ms)
Output for 7.3.9
1347ms (variadic passed 10000 2 mb increase) -------- 6ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 22350.00% (1341 ms)
Output for 7.3.8
906ms (variadic passed 10000 2 mb increase) -------- 4ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 22550.00% (902 ms)
Output for 7.3.7
928ms (variadic passed 10000 2 mb increase) -------- 4ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 23100.00% (924 ms)
Output for 7.3.6
896ms (variadic passed 10000 2 mb increase) -------- 4ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 22300.00% (892 ms)
Output for 7.3.5
783ms (variadic passed 10000 2 mb increase) -------- 3ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 26000.00% (780 ms)
Output for 7.3.4
891ms (variadic passed 10000 2 mb increase) -------- 4ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 22175.00% (887 ms)
Output for 7.3.3
1140ms (variadic passed 10000 2 mb increase) -------- 5ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 22700.00% (1135 ms)
Output for 7.3.2
971ms (variadic passed 10000 2 mb increase) -------- 6ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 16083.33% (965 ms)
Output for 7.3.1
882ms (variadic passed 10000 2 mb increase) -------- 4ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 21950.00% (878 ms)
Output for 7.3.0
951ms (variadic passed 10000 2 mb increase) -------- 15ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 6240.00% (936 ms)
Output for 7.2.25
1721ms (variadic passed 10000 2 mb increase) -------- 6ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 28583.33% (1715 ms)
Output for 7.2.24
1843ms (variadic passed 10000 2 mb increase) -------- 6ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 30616.67% (1837 ms)
Output for 7.2.23
1241ms (variadic passed 10000 2 mb increase) -------- 5ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 24720.00% (1236 ms)
Output for 7.2.22
1216ms (variadic passed 10000 2 mb increase) -------- 4ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 30300.00% (1212 ms)
Output for 7.2.21
1173ms (variadic passed 10000 2 mb increase) -------- 4ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 29225.00% (1169 ms)
Output for 7.2.20
1316ms (variadic passed 10000 2 mb increase) -------- 4ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 32800.00% (1312 ms)
Output for 7.2.19
1413ms (variadic passed 10000 2 mb increase) -------- 4ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 35225.00% (1409 ms)
Output for 7.2.18
1457ms (variadic passed 10000 2 mb increase) -------- 5ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 29040.00% (1452 ms)
Output for 7.2.17
1604ms (variadic passed 10000 2 mb increase) -------- 4ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 40000.00% (1600 ms)
Output for 7.2.16
1196ms (variadic passed 10000 2 mb increase) -------- 4ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 29800.00% (1192 ms)
Output for 7.2.15
1611ms (variadic passed 10000 2 mb increase) -------- 5ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 32120.00% (1606 ms)
Output for 7.2.14
1673ms (variadic passed 10000 2 mb increase) -------- 5ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 33360.00% (1668 ms)
Output for 7.2.13
1582ms (variadic passed 10000 2 mb increase) -------- 5ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 31540.00% (1577 ms)
Output for 7.2.12
1478ms (variadic passed 10000 2 mb increase) -------- 4ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 36850.00% (1474 ms)
Output for 7.2.11
1346ms (variadic passed 10000 2 mb increase) -------- 4ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 33550.00% (1342 ms)
Output for 7.2.10
1145ms (variadic passed 10000 2 mb increase) -------- 3ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 38066.67% (1142 ms)
Output for 7.2.9
1192ms (variadic passed 10000 2 mb increase) -------- 3ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 39633.33% (1189 ms)
Output for 7.2.8
1675ms (variadic passed 10000 2 mb increase) -------- 5ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 33400.00% (1670 ms)
Output for 7.2.7
1143ms (variadic passed 10000 2 mb increase) -------- 3ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 38000.00% (1140 ms)
Output for 7.2.6
1651ms (variadic passed 10000 2 mb increase) -------- 4ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 41175.00% (1647 ms)
Output for 7.2.5
1390ms (variadic passed 10000 2 mb increase) -------- 3ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 46233.33% (1387 ms)
Output for 7.2.4
1288ms (variadic passed 10000 2 mb increase) -------- 3ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 42833.33% (1285 ms)
Output for 7.2.3
1364ms (variadic passed 10000 2 mb increase) -------- 3ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 45366.67% (1361 ms)
Output for 7.2.2
1414ms (variadic passed 10000 2 mb increase) -------- 4ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 35250.00% (1410 ms)
Output for 7.2.1
1424ms (variadic passed 10000 2 mb increase) -------- 4ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 35500.00% (1420 ms)
Output for 7.2.0
1259ms (variadic passed 10000 2 mb increase) -------- 4ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 31375.00% (1255 ms)
Output for 7.1.33
1926ms (variadic passed 10000 2 mb increase) -------- 7ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 27414.29% (1919 ms)
Output for 7.1.32
1346ms (variadic passed 10000 2 mb increase) -------- 5ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 26820.00% (1341 ms)
Output for 7.1.31
1497ms (variadic passed 10000 2 mb increase) -------- 5ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 29840.00% (1492 ms)
Output for 7.1.30
1695ms (variadic passed 10000 2 mb increase) -------- 5ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 33800.00% (1690 ms)
Output for 7.1.29
1306ms (variadic passed 10000 2 mb increase) -------- 3ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 43433.33% (1303 ms)
Output for 7.1.28
1629ms (variadic passed 10000 2 mb increase) -------- 5ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 32480.00% (1624 ms)
Output for 7.1.27
1303ms (variadic passed 10000 2 mb increase) -------- 4ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 32475.00% (1299 ms)
Output for 7.1.26
1894ms (variadic passed 10000 2 mb increase) -------- 4ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 47250.00% (1890 ms)
Output for 7.1.25
1430ms (variadic passed 10000 2 mb increase) -------- 4ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 35650.00% (1426 ms)
Output for 7.1.24
1286ms (variadic passed 10000 2 mb increase) -------- 4ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 32050.00% (1282 ms)
Output for 7.1.23
1335ms (variadic passed 10000 2 mb increase) -------- 3ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 44400.00% (1332 ms)
Output for 7.1.22
1163ms (variadic passed 10000 2 mb increase) -------- 3ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 38666.67% (1160 ms)
Output for 7.1.21
2302ms (variadic passed 10000 2 mb increase) -------- 9ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 25477.78% (2293 ms)
Output for 7.1.20
1439ms (variadic passed 10000 2 mb increase) -------- 5ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 28680.00% (1434 ms)
Output for 7.1.19
1321ms (variadic passed 10000 2 mb increase) -------- 4ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 32925.00% (1317 ms)
Output for 7.1.18
1498ms (variadic passed 10000 2 mb increase) -------- 4ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 37350.00% (1494 ms)
Output for 7.1.17
1548ms (variadic passed 10000 2 mb increase) -------- 4ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 38600.00% (1544 ms)
Output for 7.1.16
1251ms (variadic passed 10000 2 mb increase) -------- 2ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 62450.00% (1249 ms)
Output for 7.1.15
1323ms (variadic passed 10000 2 mb increase) -------- 2ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 66050.00% (1321 ms)
Output for 7.1.14
1241ms (variadic passed 10000 2 mb increase) -------- 3ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 41266.67% (1238 ms)
Output for 7.1.13
1425ms (variadic passed 10000 2 mb increase) -------- 6ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 23650.00% (1419 ms)
Output for 7.1.12
1266ms (variadic passed 10000 2 mb increase) -------- 3ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 42100.00% (1263 ms)
Output for 7.1.11
1396ms (variadic passed 10000 2 mb increase) -------- 4ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 34800.00% (1392 ms)
Output for 7.1.10
1628ms (variadic passed 10000 2 mb increase) -------- 4ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 40600.00% (1624 ms)
Output for 7.1.9
2046ms (variadic passed 10000 2 mb increase) -------- 4ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 51050.00% (2042 ms)
Output for 7.1.8
1290ms (variadic passed 10000 2 mb increase) -------- 4ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 32150.00% (1286 ms)
Output for 7.1.7
1406ms (variadic passed 10000 2 mb increase) -------- 4ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 35050.00% (1402 ms)
Output for 7.1.6
1274ms (variadic passed 10000 2 mb increase) -------- 5ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 25380.00% (1269 ms)
Output for 7.1.2, 7.1.5
1254ms (variadic passed 10000 2 mb increase) -------- 2ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 62600.00% (1252 ms)
Output for 7.1.4
1677ms (variadic passed 10000 2 mb increase) -------- 5ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 33440.00% (1672 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/3hOfJ on line 59 Iterated was slower by NaN% (0 ms)
Output for 7.1.1
1246ms (variadic passed 10000 2 mb increase) -------- 2ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 62200.00% (1244 ms)
Output for 7.1.0
2240ms (variadic passed 10000 2 mb increase) -------- 5ms (iterated passed 10000 0 byte increase) -------- Variadic was slower by 44700.00% (2235 ms)