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}/",$input, $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($input)===1){ $lights[$j][$k] = 1; } else if(action($input)===2){ $lights[$j][$k] = 0; } else if(action($input)===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.0340.06832.38
8.3.50.0170.06035.67
8.3.40.0200.06635.71
8.3.30.0410.05734.80
8.2.180.0260.06632.50
8.2.170.0300.06134.60
8.2.160.0230.05835.93
8.1.280.0430.07348.00
7.4.10.0100.10146.11
7.4.00.0220.06546.40
7.3.130.0290.10246.32
7.3.120.0200.11146.38
7.3.110.0200.11246.03
7.3.100.0140.06846.21
7.3.90.0300.06646.54
7.3.80.0160.06846.42
7.3.70.0230.06046.21
7.3.60.0200.09346.35
7.3.50.0230.06946.04
7.3.40.0240.06846.49
7.3.30.0260.07646.34
7.3.20.0100.07252.52
7.3.10.0200.07152.35
7.3.00.0800.06752.65
7.2.260.0100.09246.66
7.2.250.0340.09746.52
7.2.240.0230.07246.58
7.2.230.0200.08646.62
7.2.220.0070.08146.17
7.2.210.0150.08546.46
7.2.200.0310.06146.46
7.2.190.0230.07346.28
7.2.180.0290.08246.22
7.2.170.0170.08346.56
7.2.160.0170.08746.44
7.2.150.0100.07552.69
7.2.140.0170.06752.63
7.2.130.0130.07652.71
7.2.120.0130.07952.59
7.2.110.0890.09452.69
7.2.100.0130.09152.39
7.2.90.0250.06952.82
7.2.80.0180.07952.59
7.2.70.0170.07152.95
7.2.60.0750.06752.80
7.2.50.0190.00412.46
7.2.40.0200.07652.70
7.2.30.0400.07752.74
7.2.20.0370.07752.80
7.2.10.0070.08952.88
7.2.00.0290.07854.05
7.1.330.0030.15651.61
7.1.320.0100.16751.54
7.1.310.0200.13851.82
7.1.300.0070.16551.46
7.1.290.0230.15551.80
7.1.280.0130.14751.61
7.1.270.0370.13451.71
7.1.260.0100.16151.71
7.1.250.0200.16451.45
7.1.240.3070.14251.38
7.1.230.0200.14751.50
7.1.220.0170.15951.58
7.1.210.0160.14351.82
7.1.200.0400.09551.65
7.1.190.0240.14851.50
7.1.180.0260.14851.63
7.1.170.1400.13451.75
7.1.160.0300.15051.86
7.1.150.0240.14751.61
7.1.140.0170.16051.70
7.1.130.0200.14951.61
7.1.120.0300.14651.73
7.1.110.0190.15851.60
7.1.100.4460.11250.60
7.1.90.0490.13351.82
7.1.80.0290.14151.71
7.1.70.0100.11152.64
7.1.60.0190.12652.26
7.1.50.0140.12252.17
7.1.40.0170.15151.70
7.1.30.0220.14251.57
7.1.20.0070.01412.46
7.1.10.0150.14851.66
7.1.00.0180.14354.96
7.0.330.0030.15851.39
7.0.320.0200.16651.22
7.0.310.0200.16351.48
7.0.300.0100.15951.38
7.0.290.0110.16851.33
7.0.280.0260.14851.21
7.0.270.0250.15051.43
7.0.260.0270.14351.39
7.0.250.0170.15551.46
7.0.240.0170.15051.62
7.0.230.0240.14851.59
7.0.220.0130.15151.55
7.0.210.0340.16051.30
7.0.200.0750.12550.24
7.0.190.0290.14951.47
7.0.180.0300.13851.30
7.0.170.0270.16351.38
7.0.160.0130.15851.54
7.0.150.0070.17151.10
7.0.140.0520.16551.48
7.0.130.0180.14651.25
7.0.120.0140.00512.46
7.0.110.0100.15851.44
7.0.100.0630.15151.46
7.0.90.0330.15351.44
7.0.80.0130.16451.45
7.0.70.0320.15451.07
7.0.60.0180.15451.38
7.0.50.0330.12350.16
7.0.40.0130.15616.91
7.0.30.0210.13817.08
7.0.20.0340.14517.02
7.0.10.0140.15916.95
7.0.00.0160.14616.95
5.6.400.0370.14779.05
5.6.390.0320.14479.04
5.6.380.0430.12979.24
5.6.370.0540.12279.36
5.6.360.0350.13979.03
5.6.350.0420.12678.85
5.6.340.0580.12379.14
5.6.330.0150.00712.46
5.6.320.0340.06549.23
5.6.310.0550.12278.85
5.6.300.0420.15379.28
5.6.290.0400.14579.04
5.6.280.0230.12982.28
5.6.270.0360.14279.41
5.6.260.0580.12179.27
5.6.250.0540.15779.09
5.6.240.0310.14479.21
5.6.230.0580.11979.05
5.6.220.0450.12779.04
5.6.210.0290.12682.20
5.6.200.0400.15480.93
5.6.190.0390.14782.08
5.6.180.0260.13582.21
5.6.170.0590.13181.99
5.6.160.0350.15081.98
5.6.150.0460.12480.85
5.6.140.0290.15680.85
5.6.130.0380.14980.98
5.6.120.0340.15882.50
5.6.110.0400.13582.37
5.6.100.0300.12482.39
5.6.90.0200.14982.38
5.6.80.0330.15082.10
5.6.70.0450.12778.82
5.6.60.0360.15278.93
5.6.50.0340.17378.92
5.6.40.0600.14679.13
5.6.30.0540.13178.91
5.6.20.0410.12779.05
5.6.10.0480.12279.11
5.6.00.0400.13378.90
5.5.380.0520.13778.84
5.5.370.0400.13379.04
5.5.360.0430.13379.04
5.5.350.0450.13982.09
5.5.340.0420.14380.99
5.5.330.0360.12181.97
5.5.320.0600.13382.02
5.5.310.0350.12781.99
5.5.300.0420.13880.77
5.5.290.0380.13280.96
5.5.280.0340.14882.46
5.5.270.0300.15482.23
5.5.260.0350.14082.31
5.5.250.0400.14782.13
5.5.240.0420.10381.92
5.5.230.0480.13778.71
5.5.220.0400.13778.98
5.5.210.0570.11579.16
5.5.200.0350.13879.29
5.5.190.0390.13379.20
5.5.180.0520.13579.02
5.5.170.0470.12479.11
5.5.160.0390.13879.11
5.5.150.0600.11778.86
5.5.140.0660.10378.93
5.5.130.0400.13578.75
5.5.120.0360.14379.00
5.5.110.0310.15379.07
5.5.100.0470.13179.19
5.5.90.0470.12779.16
5.5.80.0260.14979.13
5.5.70.0580.11378.96
5.5.60.0490.12779.07
5.5.50.0410.15279.01
5.5.40.0480.11879.07
5.5.30.0360.15879.01
5.5.20.0520.13978.92
5.5.10.0300.13478.75
5.5.00.0400.15479.12

preferences:
36.51 ms | 401 KiB | 5 Q