3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Run it: php r30.php * Run it with a custom number of rows: php r30.php <number> * Have fun :) */ function createRows($numRows, $rule) { $getNextRow = function ($currRow) use ($rule) { $nextRow = [0, 0]; for ($i = 1, $iMax = count($currRow) - 1; $i < $iMax; $i++) { $nextRow[] = $rule[$currRow[$i - 1] . $currRow[$i] . $currRow[$i + 1]]; } array_push($nextRow, 0, 0); return $nextRow; }; $rows[0] = [0, 0, 1, 0, 0]; for ($i = 1; $i <= $numRows; $i++) { $rows[$i] = $getNextRow($rows[$i - 1]); } return $rows; } function displayRows($rows, $isDownwards, $micSleep) { $rowCount = count($rows); $getRow = function ($rows, $isDownwards) use ($rowCount) { if ($isDownwards === true) { for ($i = 0; $i < $rowCount; $i++) { yield [$i, $rows[$i]]; } } else { for ($i = $rowCount - 1; $i >= 0; $i--) { yield [$i, $rows[$i]]; } } } foreach ($getRow($rows, $isDownwards) as [$pad, $row]) { echo str_repeat(' ', $rowCount - $pad); foreach ($row as $cell) { echo $cell === 1 ? '█' : ' '; } echo PHP_EOL; usleep($micSleep); } } // https://en.wikipedia.org/wiki/Rule_30 const RULE_30 = [ '111' => 0, '110' => 0, '101' => 0, '100' => 1, '011' => 1, '010' => 1, '001' => 1, '000' => 0, ]; $numRows = isset($argv[1]) && (int)$argv[1] > 0 && (int)$argv[1] <= 1000 ? (int)$argv[1] : 80; $rows = createRows($numRows, RULE_30); while (true) { displayRows($rows, true, 5000); displayRows($rows, false, 5000); }

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.1.70.0070.00917.04
7.1.60.0270.00935.14
7.1.50.0350.00634.41
7.1.40.0190.01334.45
7.1.30.0200.01634.31
7.1.20.0270.01134.58
7.1.10.0140.00616.48
7.1.00.0090.01216.43
7.0.200.0070.00716.67
7.0.190.0090.01016.42
7.0.180.0060.01116.02
7.0.170.0060.01216.09
7.0.160.0060.01416.04
7.0.150.0000.01715.99
7.0.140.0100.01015.91
7.0.130.0060.01416.39
7.0.120.0060.01316.53
7.0.110.0040.01515.89
7.0.100.0030.01616.08
7.0.90.0030.01716.01
7.0.80.0110.00916.09
7.0.70.0080.01216.15
7.0.60.0190.00016.06
7.0.50.0060.01516.41
7.0.40.0100.01216.20
7.0.30.0060.01416.37
7.0.20.0060.01116.20
7.0.10.0150.00416.22
7.0.00.0140.00316.33

preferences:
142.7 ms | 1394 KiB | 7 Q