3v4l.org

run code in 300+ PHP versions simultaneously
<?php class MineSweeper{ private $data = NULL; private $map; function debug(){ header('Content-Type:text/plain'); } function createMap($data){ $this->data = $data; if(!preg_match('/^[\*\.\r\n]+$/', $this->data)){ throw new Exception('Invalid input provided. Only asterik (*) and/or dot (.) is allowed.'); } // breaking input to lines $lines = preg_split('/\r\n/', $this->data); $tmp_line = NULL; // holding previous line for comparsion // lines index foreach ($lines as $lnum=>$line){ // lines should be equal in length if ($tmp_line != NULL && strlen($tmp_line) != strlen($line) ){ throw new Exception('Invalid input provided, please correct the format. Not all rows are equal.'); }else { $tmp_line = $line; // removing back spac and line break and spliting into charatcers (means multi dimension array) $lines[$lnum] = str_split(str_replace('\r\n','', $line)); } } // N= lines // M = Characters $M = count($lines[0]); $this->map = new MineMap($lines); } function display(){ $this->map->display(); } } class MineMap{ private $lines = array(); private $N; private $M; function __construct($lines){ $this->lines = $lines; $this->N = count($lines); $this->M = count($lines[0]); foreach($this->lines as $lnum => $line){ $this->lines[$lnum] = array_map(function($str){ return (trim($str) == "*") ? trim($str) : 0; }, $line); } foreach($this->lines as $lnum => $line){ foreach($line as $index => $str){ if ($str === "*"){ $this->mineFound($lnum, $index); } } } } function incValue($n, $m){ if ($m < $this->M && $n < $this->N && $n >= 0 && $m >= 0){ $this->lines[$n][$m]++; } } function mineFound($n, $m){ $this->incValue($n, $m+1); $this->incValue($n, $m-1); $this->incValue($n+1, $m-1); $this->incValue($n+1, $m); $this->incValue($n+1, $m+1); $this->incValue($n-1, $m-1); $this->incValue($n-1, $m); $this->incValue($n-1, $m+1); } function display(){ echo "<table cellspacin='5px'>"; foreach ($this->lines as $line){ echo "<tr>"; foreach($line as $str){ echo "<td style=''><button data='$str' class='btn btn-primary'>&nbsp;&nbsp;&nbsp;</td>"; } echo "</tr>"; } echo "</table>"; } }

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.0110.00716.50
8.3.50.0050.01022.83
8.3.40.0120.00318.51
8.3.30.0070.00718.92
8.3.20.0080.00020.35
8.3.10.0100.00723.65
8.3.00.0060.00319.13
8.2.180.0120.00316.32
8.2.170.0120.00322.96
8.2.160.0140.00020.47
8.2.150.0080.00024.18
8.2.140.0080.00024.66
8.2.130.0000.00826.16
8.2.120.0050.00321.02
8.2.110.0040.00422.12
8.2.100.0000.01120.52
8.2.90.0000.00819.09
8.2.80.0040.00417.97
8.2.70.0090.00317.50
8.2.60.0060.00317.65
8.2.50.0040.00418.07
8.2.40.0080.00019.76
8.2.30.0050.00218.00
8.2.20.0040.00417.52
8.2.10.0000.00718.03
8.2.00.0040.00417.58
8.1.280.0080.00825.92
8.1.270.0090.00023.91
8.1.260.0030.00526.35
8.1.250.0040.00428.09
8.1.240.0030.00622.11
8.1.230.0080.00318.98
8.1.220.0040.00417.74
8.1.210.0050.00318.77
8.1.200.0060.00617.10
8.1.190.0060.00317.11
8.1.180.0000.00818.10
8.1.170.0050.00318.53
8.1.160.0030.00621.98
8.1.150.0000.00718.79
8.1.140.0040.00417.36
8.1.130.0070.00017.73
8.1.120.0070.00317.44
8.1.110.0040.00417.37
8.1.100.0000.00717.39
8.1.90.0030.00617.34
8.1.80.0040.00417.36
8.1.70.0030.00317.27
8.1.60.0030.00617.51
8.1.50.0040.00417.38
8.1.40.0080.00017.32
8.1.30.0050.00317.46
8.1.20.0060.00317.53
8.1.10.0000.00817.39
8.1.00.0080.00017.32
8.0.300.0040.00418.77
8.0.290.0000.00716.63
8.0.280.0040.00418.43
8.0.270.0000.00717.23
8.0.260.0060.00017.09
8.0.250.0040.00416.95
8.0.240.0040.00416.89
8.0.230.0030.00316.79
8.0.220.0060.00016.82
8.0.210.0030.00316.84
8.0.200.0000.00716.74
8.0.190.0060.00316.86
8.0.180.0070.00016.83
8.0.170.0000.00716.86
8.0.160.0070.00016.70
8.0.150.0060.00316.67
8.0.140.0000.00816.86
8.0.130.0030.00313.27
8.0.120.0000.00816.79
8.0.110.0000.00716.71
8.0.100.0030.00516.64
8.0.90.0030.00316.78
8.0.80.0030.01316.88
8.0.70.0030.00616.91
8.0.60.0030.00516.84
8.0.50.0000.00716.70
8.0.30.0100.01216.92
8.0.20.0190.00717.40
8.0.10.0050.00316.92
8.0.00.0110.01116.68
7.4.330.0030.00315.00
7.4.320.0000.00716.45
7.4.300.0070.00016.42
7.4.290.0000.00716.51
7.4.280.0000.00716.51
7.4.270.0070.00016.50
7.4.260.0000.00716.38
7.4.250.0040.00416.45
7.4.240.0000.00716.48
7.4.230.0070.00016.45
7.4.220.0090.00916.62
7.4.210.0050.01116.60
7.4.200.0040.00416.55
7.4.160.0130.01316.30
7.4.150.0190.00617.40
7.4.140.0090.01217.86
7.4.130.0080.01116.44
7.4.120.0080.00916.36
7.4.110.0140.00416.57
7.4.100.0090.00916.41
7.4.90.0100.01016.30
7.4.80.0090.00919.39
7.4.70.0110.00716.46
7.4.60.0100.01316.52
7.4.50.0030.00516.13
7.4.40.0030.01316.36
7.4.30.0030.01316.58
7.4.00.0070.00715.02
7.3.330.0000.00613.18
7.3.320.0000.00513.05
7.3.310.0030.00316.28
7.3.300.0030.00316.21
7.3.290.0000.01516.19
7.3.280.0080.01116.20
7.3.270.0190.00817.40
7.3.260.0100.00716.48
7.3.250.0130.00716.22
7.3.240.0090.01216.44
7.3.230.0070.01016.41
7.3.210.0110.01116.21
7.3.200.0130.00319.39
7.3.190.0100.01316.59
7.3.180.0120.00616.23
7.3.170.0160.00016.40
7.3.160.0070.00716.25
7.2.330.0170.00016.59
7.2.320.0120.00816.60
7.2.310.0140.00716.50
7.2.300.0060.01116.34
7.2.290.0130.00616.45
7.2.00.0060.00619.04
7.1.100.0090.00917.90
7.1.70.0000.00916.69
7.1.60.0060.00919.40
7.1.50.0030.02016.86
7.1.00.0030.09022.27
7.0.200.0040.00416.81
7.0.140.0130.06722.13
7.0.60.0030.08719.98
7.0.50.0000.04318.00
7.0.40.0100.03720.06
7.0.30.0230.03720.27
7.0.20.0370.07020.15
7.0.10.0070.04320.09
7.0.00.0030.09320.23
5.6.280.0000.07321.10
5.6.210.0000.08720.50
5.6.200.0070.08718.22
5.6.190.0170.07720.61
5.6.180.4170.04320.61
5.6.170.0170.04020.62
5.6.160.0030.07720.55
5.6.150.0070.04018.16
5.6.140.0100.07018.27
5.6.130.0000.08318.16
5.6.120.0030.04021.00
5.6.110.0170.04020.97
5.6.100.0170.07321.05
5.6.90.0070.08321.03
5.6.80.0070.07720.55
5.6.70.3530.02720.38
5.5.350.0200.04320.43
5.5.340.0100.07718.05
5.5.330.0030.06320.40
5.5.320.0370.07720.38
5.5.310.0200.05320.37
5.5.300.0000.07318.08
5.5.290.0030.06017.99
5.5.280.0070.09020.91
5.5.270.0030.05320.86
5.5.260.0070.04020.70
5.5.250.0030.06320.50
5.5.240.0300.06720.30
5.4.450.1300.03719.41
5.4.440.0930.06319.52
5.4.430.1300.05019.40
5.4.420.0000.06319.57
5.4.410.0200.03719.46
5.4.400.0730.03019.07
5.4.390.0930.03719.22
5.4.380.0930.07318.59
5.4.370.0970.05718.74
5.4.360.0800.05318.59
5.4.350.0800.05718.46
5.4.340.0770.05318.60
5.4.320.0080.03512.53
5.4.310.0070.03612.53
5.4.300.0050.03912.53
5.4.290.0050.04012.52
5.4.280.0040.04012.41
5.4.270.0060.03512.42
5.4.260.0090.03512.42
5.4.250.0060.03712.42
5.4.240.0050.03712.42
5.4.230.0050.03912.41
5.4.220.0100.03312.41
5.4.210.0080.03412.41
5.4.200.0090.04512.41
5.4.190.0050.03812.41
5.4.180.0050.03812.41
5.4.170.0050.03812.42
5.4.160.0040.03812.41
5.4.150.0060.03712.41
5.4.140.0050.04112.09
5.4.130.0070.03512.08
5.4.120.0090.03212.04
5.4.110.0090.03312.04
5.4.100.0080.03412.04
5.4.90.0050.03712.04
5.4.80.0050.03712.04
5.4.70.0100.03012.04
5.4.60.0060.03412.04
5.4.50.0060.03412.04
5.4.40.0070.03412.02
5.4.30.0050.05012.02
5.4.20.0040.03812.02
5.4.10.0090.03712.02
5.4.00.0070.03511.50
5.3.290.0060.03912.80
5.3.280.0080.03712.71
5.3.270.0060.04012.73
5.3.260.0080.03712.72
5.3.250.0060.03712.72
5.3.240.0070.03512.72
5.3.230.0050.03812.71
5.3.220.0030.03912.68
5.3.210.0080.04812.69
5.3.200.0080.03512.68
5.3.190.0060.03912.68
5.3.180.0090.03312.68
5.3.170.0090.04112.68
5.3.160.0070.03612.68
5.3.150.0070.03812.68
5.3.140.0080.03412.67
5.3.130.0100.03412.66
5.3.120.0040.03912.66
5.3.110.0040.04112.66
5.3.100.0090.03412.16
5.3.90.0040.03812.14
5.3.80.0120.03312.13
5.3.70.0100.04612.13
5.3.60.0090.04812.11
5.3.50.0060.04212.05
5.3.40.0080.05012.05
5.3.30.0050.04312.02
5.3.20.0070.03411.80
5.3.10.0060.03411.77
5.3.00.0080.03411.75
5.2.170.0060.0299.24
5.2.160.0070.0279.24
5.2.150.0050.0309.24
5.2.140.0040.0369.23
5.2.130.0050.0289.20
5.2.120.0060.0279.20
5.2.110.0040.0299.20
5.2.100.0060.0279.20
5.2.90.0030.0319.20
5.2.80.0040.0329.19
5.2.70.0040.0329.20
5.2.60.0050.0309.15
5.2.50.0030.0329.11
5.2.40.0050.0299.09
5.2.30.0080.0299.07
5.2.20.0070.0269.06
5.2.10.0050.0278.97
5.2.00.0080.0268.83
5.1.60.0050.0228.11
5.1.50.0040.0258.11
5.1.40.0030.0258.09
5.1.30.0040.0268.44
5.1.20.0040.0278.47
5.1.10.0060.0258.20
5.1.00.0030.0268.19
5.0.50.0030.0216.67
5.0.40.0050.0176.53
5.0.30.0030.0316.35
5.0.20.0020.0206.31
5.0.10.0050.0186.29
5.0.00.0030.0316.28
4.4.90.0020.0164.78
4.4.80.0030.0154.75
4.4.70.0020.0164.76
4.4.60.0020.0164.75
4.4.50.0040.0144.77
4.4.40.0030.0254.71
4.4.30.0030.0154.76
4.4.20.0040.0144.85
4.4.10.0040.0144.84
4.4.00.0020.0264.75
4.3.110.0040.0144.67
4.3.100.0020.0164.67
4.3.90.0050.0134.63
4.3.80.0020.0254.58
4.3.70.0030.0154.63
4.3.60.0040.0134.63
4.3.50.0030.0154.63
4.3.40.0030.0244.53
4.3.30.0000.0183.30
4.3.20.0040.0143.28
4.3.10.0020.0153.23
4.3.00.0200.01715.85

preferences:
45.01 ms | 400 KiB | 5 Q