3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Pos { var $x; var $y; public function __construct($x, $y){ $this->x = $x; $this->y = $y; } public function distance($pos){ return (abs($this->x - $pos->x) + abs($this->y - $pos->y)); } } 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->y; $this->x = $pos->x; $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, $opPos){ $best = Move::initializeEmpty(); foreach($moves as $m){ $m->setValue($board, $player, $pos, $opPos); $best = $m->compare($best); } return $best; } public function setValue($board, $player, $pos, $opPos){ if ($board[$this->y][$this->x] != CLEAR) $this->value = -10; else{ $this-> value = 1; } } } define("CLEAR", chr(45)); define("P1", chr(114)); define("P2", chr(103)); define("WALL", chr(35)); function nextMove($player,$pos,$board, $opPos){ $moves = array(); array_push($moves, new Move(new Pos($pos->x, $pos->y - 1), "UP", -1)); array_push($moves, new Move(new Pos($pos->x, $pos->y + 1), "DOWN", -1)); array_push($moves, new Move(new Pos($pos->x - 1, $pos->y), "LEFT", -1)); array_push($moves, new Move(new Pos($pos->x + 1, $pos->y), "RIGHT", -1)); return Move::maxValDirection($moves, $board, $player, $pos, $opPos)->direction; } function getPlayerPos($player, $pos){ return ord($player) == ord(P1) ? new Pos($pos[1], $pos[0]) : new Pos($pos[3], $pos[2]); } $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.0030.01318.43
8.3.60.0040.01117.00
8.3.50.0160.00622.05
8.3.40.0110.01118.95
8.3.30.0200.00018.76
8.3.20.0000.00820.29
8.3.10.0000.00821.67
8.3.00.0050.00319.38
8.2.190.0100.00617.00
8.2.180.0150.00718.54
8.2.170.0110.01122.96
8.2.160.0100.00320.52
8.2.150.0000.00825.66
8.2.140.0060.00324.66
8.2.130.0050.00520.60
8.2.120.0000.00926.35
8.2.110.0060.00320.50
8.2.100.0000.01217.93
8.2.90.0040.00419.40
8.2.80.0000.00817.97
8.2.70.0040.00417.63
8.2.60.0090.00017.55
8.2.50.0040.00418.07
8.2.40.0000.00719.38
8.2.30.0000.00720.68
8.2.20.0000.00917.88
8.2.10.0000.00718.09
8.2.00.0000.00818.13
8.1.280.0130.00925.92
8.1.270.0030.00623.97
8.1.260.0070.00028.09
8.1.250.0060.00328.09
8.1.240.0040.00422.32
8.1.230.0120.00017.54
8.1.220.0050.00317.79
8.1.210.0040.00418.77
8.1.200.0000.01117.49
8.1.190.0000.00817.82
8.1.180.0050.00318.10
8.1.170.0000.00918.77
8.1.160.0000.00821.98
8.1.150.0000.00719.06
8.1.140.0020.00519.63
8.1.130.0050.00317.77
8.1.120.0000.00717.43
8.1.110.0050.00317.47
8.1.100.0030.00717.52
8.1.90.0000.00917.54
8.1.80.0040.00417.41
8.1.70.0030.00617.49
8.1.60.0040.00817.59
8.1.50.0000.00817.50
8.1.40.0040.00417.62
8.1.30.0040.00417.61
8.1.20.0080.00017.51
8.1.10.0040.00417.50
8.1.00.0000.00817.57
8.0.300.0000.00818.77
8.0.290.0070.00016.88
8.0.280.0000.00718.53
8.0.270.0000.00717.24
8.0.260.0030.00317.37
8.0.250.0030.00317.06
8.0.240.0030.00316.98
8.0.230.0030.00617.14
8.0.220.0000.00817.03
8.0.210.0000.00717.01
8.0.200.0060.00016.98
8.0.190.0000.00817.15
8.0.180.0040.00416.94
8.0.170.0080.00017.00
8.0.160.0000.00716.92
8.0.150.0030.00516.96
8.0.140.0000.00716.88
8.0.130.0040.00413.54
8.0.120.0040.00416.93
8.0.110.0000.00717.02
8.0.100.0000.00717.04
8.0.90.0000.00716.86
8.0.80.0060.01117.01
8.0.70.0080.00017.02
8.0.60.0000.00717.03
8.0.50.0000.00716.88
8.0.30.0130.00617.26
8.0.20.0090.01617.40
8.0.10.0070.00017.02
8.0.00.0080.01016.98
7.4.330.0030.00316.85
7.4.320.0040.00416.57
7.4.300.0030.00316.65
7.4.290.0050.00316.72
7.4.280.0000.01016.59
7.4.270.0000.00716.54
7.4.260.0040.00416.58
7.4.250.0050.00316.53
7.4.240.0040.00316.64
7.4.230.0040.00416.46
7.4.220.0060.01316.56
7.4.210.0070.00716.73
7.4.200.0000.00816.55
7.4.160.0100.00616.71
7.4.150.0170.00817.40
7.4.140.0110.01117.86
7.4.130.0100.00816.60
7.4.120.0110.00616.72
7.4.110.0130.00716.78
7.4.100.0110.01916.64
7.4.90.0070.01116.82
7.4.80.0090.00919.39
7.4.70.0070.01316.66
7.4.60.0070.01016.40
7.4.50.0030.01216.55
7.4.40.0120.00616.66
7.4.30.0100.00716.55
7.4.10.0150.00316.47
7.4.00.0100.00615.87
7.3.330.0000.00513.23
7.3.320.0000.00513.41
7.3.310.0000.00716.51
7.3.300.0030.00316.24
7.3.290.0080.00716.37
7.3.280.0060.01116.38
7.3.270.0110.00617.40
7.3.260.0090.00916.40
7.3.250.0110.00816.52
7.3.240.0090.00916.47
7.3.230.0120.00616.39
7.3.210.0070.01016.43
7.3.200.0030.01416.58
7.3.190.0150.00916.32
7.3.180.0060.00916.55
7.3.170.0060.01516.54
7.3.160.0070.01016.46
7.3.130.0060.01216.35
7.3.120.0030.01016.43
7.3.110.0060.01316.22
7.3.100.0000.01316.38
7.3.90.0030.00716.55
7.3.80.0060.01316.46
7.3.70.0080.00616.43
7.3.60.0030.01016.43
7.3.50.0100.00616.29
7.3.40.0070.00716.47
7.3.30.0060.00616.38
7.3.20.0090.00618.25
7.3.10.0090.00318.16
7.3.00.0110.00418.19
7.2.330.0150.00316.87
7.2.320.0140.00316.77
7.2.310.0070.01116.47
7.2.300.0070.01116.53
7.2.290.0150.00916.67
7.2.260.0030.01616.72
7.2.250.0140.00716.41
7.2.240.0030.01216.56
7.2.230.0030.00916.81
7.2.220.0110.00016.56
7.2.210.0040.01216.84
7.2.200.0070.01016.46
7.2.190.0060.00916.73
7.2.180.0060.00616.58
7.2.170.0090.00616.58
7.2.160.0070.01016.47
7.2.150.0150.00718.36
7.2.140.0060.00918.29
7.2.130.0030.01318.27
7.2.120.0030.01018.32
7.2.110.0080.01218.30
7.2.100.0090.00618.31
7.2.90.0060.01218.48
7.2.80.0040.00718.47
7.2.70.0060.00918.29
7.2.60.0040.00817.69
7.2.50.0030.01018.26
7.2.40.0030.01018.39
7.2.30.0040.00818.36
7.2.20.0070.00718.18
7.2.10.0040.00718.59
7.2.00.0030.00918.83
7.1.330.0030.01217.38
7.1.320.0040.00717.46
7.1.310.0090.00917.31
7.1.300.0030.01317.27
7.1.290.0100.00317.32
7.1.280.0090.00317.15
7.1.270.0100.01017.38
7.1.260.0030.00717.19
7.1.250.0030.01417.34
7.1.240.0130.00717.40
7.1.230.0060.00617.27
7.1.220.0030.00617.13
7.1.210.0030.01317.20
7.1.200.0080.00516.38
7.1.190.0040.01117.05
7.1.180.0030.00617.48
7.1.170.0060.00917.08
7.1.160.0030.01017.35
7.1.150.0060.00317.12
7.1.140.0030.01317.32
7.1.130.0060.00917.27
7.1.120.0060.00917.25
7.1.110.0110.00417.30
7.1.100.0070.00617.71
7.1.90.0060.00317.31
7.1.80.0030.01317.25
7.1.70.0060.00817.18
7.1.60.0110.00918.34
7.1.50.0040.01316.95
7.1.40.0120.00017.45
7.1.30.0110.00417.39
7.1.20.0150.00017.16
7.1.10.0000.01117.25
7.1.00.0080.04019.92
7.0.330.0100.01016.98
7.0.320.0090.00316.82
7.0.310.0110.00816.82
7.0.300.0050.00516.81
7.0.290.0040.00716.98
7.0.280.0090.00316.85
7.0.270.0060.00916.89
7.0.260.0090.00616.86
7.0.250.0030.01017.12
7.0.240.0060.00917.13
7.0.230.0030.00617.11
7.0.220.0040.00717.05
7.0.210.0120.00316.99
7.0.200.0090.00516.86
7.0.190.0040.01116.81
7.0.180.0030.01316.96
7.0.170.0050.00517.03
7.0.160.0080.00417.00
7.0.150.0040.00716.96
7.0.140.0060.01016.96
7.0.130.0060.00917.08
7.0.120.0040.01116.94
7.0.110.0030.01017.05
7.0.100.0060.00617.04
7.0.90.0030.01016.92
7.0.80.0030.01216.98
7.0.70.0070.00716.85
7.0.60.0070.04718.55
7.0.50.0120.04217.38
7.0.40.0070.02417.48
7.0.30.0190.04617.54
7.0.20.0250.03717.56
7.0.10.0100.04517.53
7.0.00.0050.02717.43
5.6.400.0080.00616.33
5.6.390.0060.00815.71
5.6.380.0040.01215.93
5.6.370.0000.01616.27
5.6.360.0090.00716.03
5.6.350.0040.00715.89
5.6.340.0030.01216.00
5.6.330.0000.01016.11
5.6.320.0030.01316.07
5.6.310.0070.01016.24
5.6.300.0030.01316.08
5.6.290.0070.00715.94
5.6.280.0070.03218.71
5.6.270.0040.01116.14
5.6.260.0000.01616.09
5.6.250.0000.01015.95
5.6.240.0060.01015.78
5.6.230.0120.00316.05
5.6.220.0040.00716.09
5.6.210.0050.04018.25
5.6.200.0070.04617.03
5.6.190.0100.04018.28
5.6.180.0280.04118.16
5.6.170.0200.03718.26
5.6.160.0110.04318.31
5.6.150.0080.03117.09
5.6.140.0050.03416.95
5.6.130.0080.03917.14
5.6.120.0080.03818.55
5.6.110.0080.02218.32
5.6.100.0020.02918.44
5.6.90.0070.02718.46
5.6.80.0100.04218.08
5.6.70.0030.01015.91
5.6.60.0030.00715.66
5.6.50.0100.00615.91
5.6.40.0040.01115.71
5.6.30.0070.00715.99
5.6.20.0090.00615.92
5.6.10.0060.01015.87
5.6.00.0000.01515.64
5.5.380.0140.00415.58
5.5.370.0040.01115.68
5.5.360.0070.00715.86
5.5.350.0150.04818.22
5.5.340.0080.04516.93
5.5.330.0100.03518.03
5.5.320.0020.02918.06
5.5.310.0120.03718.06
5.5.300.0050.03216.96
5.5.290.0020.05116.87
5.5.280.0030.05218.49
5.5.270.0060.02118.35
5.5.260.0070.04818.48
5.5.250.0110.04318.27
5.5.240.0150.03718.07
5.5.230.0000.01215.90
5.5.220.0030.00715.81
5.5.210.0040.01415.82
5.5.200.0110.00015.78
5.5.190.0070.00715.77
5.5.180.0080.00615.80
5.5.170.0120.00415.75
5.5.160.0070.00415.65
5.5.150.0000.01015.83
5.5.140.0090.00415.87
5.5.130.0070.01015.74
5.5.120.0000.01515.68
5.5.110.0040.01115.84
5.5.100.0110.00415.72
5.5.90.0040.01115.75
5.5.80.0040.00715.84
5.5.70.0000.01215.75
5.5.60.0070.00315.72
5.5.50.0040.00715.84
5.5.40.0040.01115.76
5.5.30.0030.00715.61
5.5.20.0110.00715.68
5.5.10.0140.00315.61
5.5.00.0140.00415.74

preferences:
53.33 ms | 401 KiB | 5 Q