3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Move { var $direction; var $value; var $x; var $y; public static function initializeEmpty(){ return (new Move(array(0, 0), "NONE", -1)); } public function __construct($pos, $direction, $value){ $this->y = $pos[0]; $this->x = $pos[1]; $this->value = $value; $this->direction = $direction; } public function compare($move){ return $move->value > $this->value ? $move : $this; } public static function maxValDirection($moves, $board, $player, $pos){ $best = Move::initializeEmpty(); foreach($moves as $m){ $m->setValue($board, $player, $pos); $best = $m->compare($best); } return $best; } public function setValue($board, $player, $pos){ echo "0"; if ($board[$y][$x] != "-") $this->value = -1; else $this->value = 1; } } define("MAXSIZE", 100); echo MAXSIZE; define(P1, "r"); define(P2, "l"); define(WALL, "#"); function nextMove($player,$pos,$board){ $moves = array(); array_push($moves, new Move(array($pos[0] - 1, $pos[1]), "UP", -1)); array_push($moves, new Move(array($pos[0] + 1, $pos[1]), "DOWN", -1)); array_push($moves, new Move(array($pos[0], $pos[1] - 1), "LEFT", -1)); array_push($moves, new Move(array($pos[0], $pos[1] + 1), "RIGHT", -1)); return Move::maxValDirection($moves, $board, $player, $pos)->direction; } $m1 = Move::initializeEmpty(); $m2 = new Move(array(0, 1), "RIGHT", 10); print_r(Move::maxValDirection(array($m1, $m2), "", "", "")); ?>

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.70.0070.01018.55
8.3.60.0140.00416.63
8.3.50.0140.00522.04
8.3.40.0120.00318.80
8.3.30.0120.00318.67
8.3.20.0040.00420.33
8.3.10.0040.00423.67
8.3.00.0000.00919.50
8.2.190.0100.01016.88
8.2.180.0070.01517.00
8.2.170.0040.01222.96
8.2.160.0100.00320.36
8.2.150.0000.00824.18
8.2.140.0050.00224.66
8.2.130.0060.00320.47
8.2.120.0040.00426.35
8.2.110.0110.00419.21
8.2.100.0110.00017.97
8.2.90.0030.00619.26
8.2.80.0060.00317.97
8.2.70.0030.00517.63
8.2.60.0000.00817.93
8.2.50.0000.00818.10
8.2.40.0040.00420.27
8.2.30.0000.00820.75
8.2.20.0030.00617.77
8.2.10.0040.00418.23
8.2.00.0050.00218.11
8.1.280.0120.00625.92
8.1.270.0040.00423.89
8.1.260.0040.00428.09
8.1.250.0040.00428.09
8.1.240.0080.00022.63
8.1.230.0080.00417.64
8.1.220.0000.00817.88
8.1.210.0080.00018.77
8.1.200.0060.00317.48
8.1.190.0030.00617.22
8.1.180.0000.00818.10
8.1.170.0080.00018.76
8.1.160.0070.00022.14
8.1.150.0050.00218.93
8.1.140.0000.00919.50
8.1.130.0050.00317.66
8.1.120.0040.00417.47
8.1.110.0040.00417.37
8.1.100.0060.00317.41
8.1.90.0000.00917.46
8.1.80.0070.00017.46
8.1.70.0000.00917.48
8.1.60.0070.00417.63
8.1.50.0030.00617.59
8.1.40.0050.00317.45
8.1.30.0040.00417.59
8.1.20.0050.00217.61
8.1.10.0040.00417.57
8.1.00.0050.00317.38
8.0.300.0000.00718.77
8.0.290.0040.00416.88
8.0.280.0030.00518.39
8.0.270.0070.00017.27
8.0.260.0000.00617.34
8.0.250.0040.00417.13
8.0.240.0030.00317.04
8.0.230.0020.00517.17
8.0.220.0040.00417.00
8.0.210.0000.00717.00
8.0.200.0070.00017.06
8.0.190.0000.00717.07
8.0.180.0040.00416.97
8.0.170.0050.00217.04
8.0.160.0000.00716.96
8.0.150.0000.00716.99
8.0.140.0030.00616.98
8.0.130.0060.00013.42
8.0.120.0050.00316.89
8.0.110.0000.00716.92
8.0.100.0040.00416.98
8.0.90.0040.00416.93
8.0.80.0000.01516.95
8.0.70.0000.00816.98
8.0.60.0040.00417.09
8.0.50.0040.00416.82
8.0.30.0090.01017.17
8.0.20.0080.01317.40
8.0.10.0050.00317.18
8.0.00.0100.00916.73
7.4.330.0000.00516.83
7.4.320.0050.00316.57
7.4.300.0000.00716.49
7.4.290.0070.00016.56
7.4.280.0090.00316.68
7.4.270.0050.00316.72
7.4.260.0000.00816.55
7.4.250.0000.00816.66
7.4.240.0030.00516.71
7.4.230.0000.00716.70
7.4.220.0110.00916.74
7.4.210.0060.01316.71
7.4.200.0070.00016.74
7.4.160.0160.00416.40
7.4.150.0090.00917.40
7.4.140.0120.00717.86
7.4.130.0090.00816.58
7.4.120.0100.00916.65
7.4.110.0120.00616.61
7.4.100.0150.00316.57
7.4.90.0110.00616.48
7.4.80.0140.00819.39
7.4.70.0100.00716.61
7.4.60.0100.00716.57
7.4.50.0100.00716.64
7.4.40.0130.00416.46
7.4.30.0120.01216.64
7.4.10.0160.00315.13
7.4.00.0080.00814.96
7.3.330.0030.00313.29
7.3.320.0000.00513.48
7.3.310.0060.00316.44
7.3.300.0030.00316.49
7.3.290.0070.01116.38
7.3.280.0070.01016.46
7.3.270.0170.00717.40
7.3.260.0120.00616.43
7.3.250.0100.00816.54
7.3.240.0100.00816.65
7.3.230.0110.01416.46
7.3.210.0110.00716.55
7.3.200.0030.01316.70
7.3.190.0000.01716.52
7.3.180.0130.00916.57
7.3.170.0120.00916.38
7.3.160.0100.00616.41
7.3.130.0090.00615.09
7.3.120.0060.01014.86
7.3.110.0070.00914.87
7.3.100.0040.00814.76
7.3.90.0070.00914.92
7.3.80.0100.00514.80
7.3.70.0030.01114.81
7.3.60.0060.00814.74
7.3.50.0070.00814.73
7.3.40.0050.00614.76
7.3.30.0030.01014.75
7.3.20.0080.00616.59
7.3.10.0070.00816.67
7.3.00.0080.00716.67
7.2.330.0070.01116.64
7.2.320.0150.00316.66
7.2.310.0030.01516.69
7.2.300.0100.01016.55
7.2.290.0060.01416.67
7.2.260.0130.00615.34
7.2.250.0090.00814.96
7.2.240.0080.00815.27
7.2.230.0070.00815.06
7.2.220.0060.00815.19
7.2.210.0090.00715.08
7.2.200.0040.01115.01
7.2.190.0030.00915.09
7.2.180.0080.00614.98
7.2.170.0050.01015.08
7.2.160.0040.00915.15
7.2.150.0070.00516.97
7.2.140.0030.01117.08
7.2.130.0100.00816.83
7.2.120.0040.01116.95
7.2.110.0070.00716.77
7.2.100.0080.00816.99
7.2.90.0100.00816.91
7.2.80.0060.01116.88
7.2.70.0070.00916.90
7.2.60.0060.00916.93
7.2.50.0080.00917.03
7.2.40.0080.00816.92
7.2.30.0070.00916.95
7.2.20.0070.00516.95
7.2.10.0070.00916.97
7.2.00.0060.01017.50
7.1.330.0070.00715.88
7.1.320.0080.00715.82
7.1.310.0070.00715.77
7.1.300.0060.00715.79
7.1.290.0060.00915.75
7.1.280.0070.00715.80
7.1.270.0040.01215.59
7.1.260.0080.00615.74
7.1.250.0090.00815.78
7.1.240.0060.00715.61
7.1.230.0060.00815.90
7.1.220.0110.00615.69
7.1.210.0090.00915.73
7.1.200.0090.00915.77
7.1.190.0050.00915.74
7.1.180.0100.00615.75
7.1.170.0070.00915.74
7.1.160.0030.01315.82
7.1.150.0100.00715.77
7.1.140.0070.01015.75
7.1.130.0060.01115.75
7.1.120.0120.00515.70
7.1.110.0040.01015.87
7.1.100.0100.00516.50
7.1.90.0090.00915.87
7.1.80.0140.00315.91
7.1.70.0100.01116.30
7.1.60.0100.01016.97
7.1.50.0100.00916.17
7.1.40.0130.00315.84
7.1.30.0120.00215.48
7.1.20.0150.00415.64
7.1.10.0110.00515.73
7.1.00.0110.03018.02
7.0.330.0130.00415.38
7.0.320.0080.00915.39
7.0.310.0120.00215.29
7.0.300.0110.00615.44
7.0.290.0100.00515.41
7.0.280.0080.00915.38
7.0.270.0050.00815.30
7.0.260.0060.00815.40
7.0.250.0090.00915.45
7.0.240.0080.00615.45
7.0.230.0100.00715.42
7.0.220.0080.00815.25
7.0.210.0130.00415.45
7.0.200.0060.00915.83
7.0.190.0130.00715.42
7.0.180.0090.01015.27
7.0.170.0070.01115.36
7.0.160.0080.00815.32
7.0.150.0070.00815.16
7.0.140.0110.00615.38
7.0.130.0080.00815.52
7.0.120.0110.00515.36
7.0.110.0120.00315.43
7.0.100.0080.00815.50
7.0.90.0070.01015.48
7.0.80.0100.00715.25
7.0.70.0100.00515.23
7.0.60.0130.02916.79
7.0.50.0080.02616.18
7.0.40.0040.03515.71
7.0.30.0130.02515.87
7.0.20.0160.02015.63
7.0.10.0070.03315.60
7.0.00.0050.02315.50
5.6.400.0090.00314.50
5.6.390.0040.00714.48
5.6.380.0060.00614.55
5.6.370.0020.01414.38
5.6.360.0060.00514.35
5.6.350.0080.00514.44
5.6.340.0050.00714.22
5.6.330.0030.01114.50
5.6.320.0080.00514.30
5.6.310.0020.01314.38
5.6.300.0030.01414.30
5.6.290.0070.01114.69
5.6.280.0020.01916.45
5.6.270.0030.01014.60
5.6.260.0090.00814.57
5.6.250.0030.00814.42
5.6.240.0040.01014.26
5.6.230.0050.00914.57
5.6.220.0070.00914.25
5.6.210.0080.03316.38
5.6.200.0020.02615.70
5.6.190.0110.02816.36
5.6.180.0220.02016.21
5.6.170.0140.02016.43
5.6.160.0020.02216.47
5.6.150.0060.01715.57
5.6.140.0100.01915.68
5.6.130.0030.03315.57
5.6.120.0040.02116.55
5.6.110.0100.02816.58
5.6.100.0090.02616.51
5.6.90.0050.02416.59
5.6.80.0090.02516.45
5.6.70.0040.01014.34
5.6.60.0100.00514.37
5.6.50.0080.00514.29
5.6.40.0040.00714.43
5.6.30.0080.00714.56
5.6.20.0050.00914.54
5.6.10.0100.00514.49
5.6.00.0050.00914.32
5.5.380.0030.00812.74
5.5.370.0030.00912.94
5.5.360.0030.00612.98
5.5.350.0110.03115.36
5.5.340.0030.02314.50
5.5.330.0050.02315.39
5.5.320.0080.03015.29
5.5.310.0100.01815.22
5.5.300.0010.02114.48
5.5.290.0030.03014.68
5.5.280.0060.03115.56
5.5.270.0060.02915.53
5.5.260.0080.03115.37
5.5.250.0030.03315.41
5.5.240.0120.02615.31
5.5.230.0080.00512.77
5.5.220.0060.00712.78
5.5.210.0050.00512.87
5.5.200.0020.00912.72
5.5.190.0050.00712.89
5.5.180.0020.00912.84
5.5.170.0020.00912.75
5.5.160.0020.01012.66
5.5.150.0060.00812.59
5.5.140.0070.00512.61
5.5.130.0030.00812.91
5.5.120.0060.00512.79
5.5.110.0050.00612.64
5.5.100.0070.00412.79
5.5.90.0040.00912.78
5.5.80.0050.00812.78
5.5.70.0030.01012.53
5.5.60.0040.00912.82
5.5.50.0080.00512.86
5.5.40.0080.00612.71
5.5.30.0070.00512.84
5.5.20.0020.00912.50
5.5.10.0020.00912.65
5.5.00.0050.00812.75

preferences:
55.98 ms | 401 KiB | 5 Q