3v4l.org

run code in 300+ PHP versions simultaneously
<?php $input = "turn off 499,499 through 500,500"; $lights = [[]]; for($i = 0; $i<1000; $i++){ for($j = 0; $j<1000; $j++){ $lights[$i][$j] = 0; } } $inputs = explode("\n",$input); function action($s){ $on = preg_match("/turn on/",$s); $off = preg_match("/turn off/",$s); $toggle = preg_match("/toggle/",$s); if($on > 0){ return 1; } else if($off>0){ return 2; } else if($toggle>0){ return 3; } } for($i = 0; $i < count($inputs); $i++){ $matches = null; preg_match_all("/\d{1,3},\d{1,3}/",$inputs[$i], $matches); $from = $matches[0][0]; $to = $matches[0][1]; $x1 = explode(",",$from)[0]; $y1 = explode(",",$from)[0]; $x2 = explode(",",$to)[0]; $y2 = explode(",",$to)[1]; for($j = $y1; $j<=$y2; $j++){ for($k = $x1; $k<=$x2; $k++){ if(action($inputs[$i])===1){ $lights[$j][$k] = 1; } else if(action($inputs[$i])===2){ $lights[$j][$k] = 0; } else if(action($inputs[$i])===3){ if($lights[$j][$k] == 0){ $lights[$j][$k] = 1; } else{ $lights[$j][$k] = 0; } } } } } $count = 0; for($i = 0; $i<1000; $i++){ for($j = 0; $j<1000; $j++){ if($lights[$i][$j] == 1){ $count++; } } } echo $count; ?>

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)
8.3.60.0270.04732.38
8.3.50.0070.05635.71
8.3.40.0230.04934.58
8.3.30.0170.05534.89
8.3.20.0060.03237.00
8.3.10.0100.04740.25
8.3.00.0030.03037.64
8.2.180.0300.04332.23
8.2.170.0260.04634.71
8.2.160.0200.06536.27
8.2.150.0230.03035.34
8.2.140.0160.02336.78
8.2.130.0100.03436.65
8.2.120.0100.02339.80
8.2.110.0100.05838.09
8.2.100.0170.04033.68
8.2.90.0130.03534.92
8.2.80.0130.03533.63
8.2.70.0070.04133.50
8.2.60.0000.04733.68
8.2.50.0070.04033.50
8.2.40.0070.03937.27
8.2.30.0130.03336.39
8.2.20.0130.03433.54
8.2.10.0100.03733.92
8.2.00.0090.03833.79
8.1.280.0230.06248.77
8.1.270.0240.01346.25
8.1.260.0230.00749.16
8.1.250.0120.01548.16
8.1.240.0130.03046.01
8.1.230.0230.02043.83
8.1.220.0100.02343.29
8.1.210.0070.02542.98
8.1.200.0190.01643.25
8.1.190.0160.01643.10
8.1.180.0100.02343.40
8.1.170.0070.02644.34
8.1.160.0000.03246.50
8.1.150.0130.01944.53
8.1.140.0100.02245.23
8.1.130.0070.02543.34
8.1.120.0140.01743.30
8.1.110.0100.02343.28
8.1.100.0160.01643.29
8.1.90.0230.01743.24
8.1.80.0130.01943.28
8.1.70.0100.02043.11
8.1.60.0100.02643.33
8.1.50.0100.02643.30
8.1.40.0200.01743.31
8.1.30.0100.02743.38
8.1.20.0100.02743.38
8.1.10.0200.05249.05
8.1.00.0200.05348.98
8.0.300.0230.03048.35
8.0.290.0300.02348.00
8.0.280.0130.03949.75
8.0.270.0160.03948.55
8.0.260.0160.03648.61
8.0.250.0160.03648.17
8.0.240.0200.03348.25
8.0.230.0170.03748.30
8.0.220.0130.04048.04
8.0.210.0070.04648.22
8.0.200.0160.03648.20
8.0.190.0130.06648.27
8.0.180.0070.06748.20
8.0.170.0200.05348.20
8.0.160.0160.05548.26
8.0.150.0210.05248.21
8.0.140.0130.06048.14
8.0.130.0100.06444.69
8.0.120.0100.06348.14
8.0.110.0130.05748.20
8.0.100.0100.06148.03
8.0.90.0100.06148.14
8.0.80.0330.06348.16
8.0.70.0200.05348.16
8.0.60.0070.06448.05
8.0.50.0100.06048.14
8.0.30.0300.06648.34
8.0.20.0410.08548.35
8.0.10.0240.04548.30
8.0.00.0350.08248.00
7.4.330.0030.04350.23
7.4.320.0030.05047.87
7.4.300.0170.03747.86
7.4.290.0130.06047.77
7.4.280.0100.06647.77
7.4.270.0200.05547.88
7.4.260.0200.05347.60
7.4.250.0130.06247.76
7.4.240.0150.06147.69
7.4.230.0130.06047.93
7.4.220.0310.10047.88
7.4.210.0360.07347.96
7.4.200.0100.06447.86
7.4.160.0330.08347.86
7.4.150.0560.06747.64
7.4.140.0390.09147.68
7.4.130.0360.09147.79
7.4.120.0350.09647.87
7.4.110.0370.08647.82
7.4.100.0490.11247.84
7.4.90.0290.09347.80
7.4.80.0340.13047.80
7.4.70.0360.10947.86
7.4.60.0370.10647.76
7.4.50.0200.06847.86
7.4.40.0500.07047.82
7.4.30.0530.12447.87
7.4.00.0100.07346.40
7.3.330.0200.06944.91
7.3.320.0300.05644.93
7.3.310.0270.05047.78
7.3.300.0030.07147.81
7.3.290.0360.09647.81
7.3.280.0370.11447.82
7.3.270.0550.07547.78
7.3.260.0570.07447.75
7.3.250.0370.10347.95
7.3.240.0370.13047.82
7.3.230.0600.07347.88
7.3.210.0510.13647.88
7.3.200.0300.09947.97
7.3.190.0330.10747.91
7.3.180.0330.09448.06
7.3.170.0510.12947.82
7.3.160.0390.10447.78
7.2.330.0520.08248.06
7.2.320.0570.08148.31
7.2.310.0310.10148.39
7.2.300.0420.10548.27
7.2.290.0410.08648.30
7.2.110.1070.07752.54
7.2.60.2540.06052.75
7.2.00.0070.06255.13
7.1.200.0490.07251.72
7.1.100.7530.05649.74
7.1.70.0030.06353.39
7.1.60.0070.11453.27
7.1.50.0270.09652.86
7.1.00.0000.15758.35
7.0.200.7500.06748.91
7.0.60.0270.12751.03
7.0.50.0200.13748.99
7.0.40.0070.13020.21
7.0.30.0170.10320.26
7.0.20.0470.14020.35
7.0.10.0100.15320.24
7.0.00.0130.16320.18
5.6.280.0170.09785.80
5.6.210.0230.11785.29
5.6.200.0270.13082.91
5.6.190.0430.15785.14
5.6.180.0400.12385.06
5.6.170.0570.14785.17
5.6.160.0230.12084.88
5.6.150.0100.11382.89
5.6.140.0270.10782.86
5.6.130.0300.15382.91
5.6.120.0130.13785.71
5.6.110.0200.16385.87
5.6.100.0200.10385.61
5.6.90.0370.14385.70
5.6.80.0170.17385.15
5.5.350.0400.15785.09
5.5.340.0300.12382.77
5.5.330.0400.17384.79
5.5.320.0330.11784.76
5.5.310.0400.12784.92
5.5.300.0530.13082.66
5.5.290.0400.09782.65
5.5.280.0470.12385.69
5.5.270.0400.14385.48
5.5.260.0330.16085.49
5.5.250.0430.13385.41
5.5.240.0400.07784.91

preferences:
54.9 ms | 400 KiB | 5 Q