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; } } 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){ 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){ $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)->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.60.0090.00917.13
8.3.50.0120.00922.02
8.3.40.0080.00818.97
8.3.30.0040.01118.54
8.3.20.0080.00020.17
8.3.10.0000.00821.87
8.3.00.0060.00319.15
8.2.180.0040.01116.75
8.2.170.0090.00622.96
8.2.160.0160.00020.38
8.2.150.0040.00424.18
8.2.140.0030.00524.66
8.2.130.0030.00720.43
8.2.120.0000.00826.35
8.2.110.0100.00020.52
8.2.100.0080.00417.93
8.2.90.0000.00819.22
8.2.80.0040.00417.97
8.2.70.0030.00517.63
8.2.60.0060.00317.91
8.2.50.0050.00318.07
8.2.40.0070.00019.34
8.2.30.0030.00520.73
8.2.20.0060.00317.80
8.2.10.0040.00418.25
8.2.00.0000.00818.19
8.1.280.0040.01425.92
8.1.270.0080.01123.96
8.1.260.0080.00028.09
8.1.250.0040.00428.09
8.1.240.0030.00622.14
8.1.230.0000.01219.44
8.1.220.0040.00417.74
8.1.210.0050.00318.77
8.1.200.0070.00417.61
8.1.190.0030.00617.89
8.1.180.0060.00318.10
8.1.170.0030.00618.78
8.1.160.0050.00222.19
8.1.150.0040.00418.98
8.1.140.0000.00819.64
8.1.130.0070.00017.76
8.1.120.0050.00217.44
8.1.110.0050.00317.36
8.1.100.0050.00517.43
8.1.90.0030.00517.52
8.1.80.0030.00617.41
8.1.70.0000.00717.42
8.1.60.0030.00617.61
8.1.50.0080.00017.49
8.1.40.0040.00417.57
8.1.30.0000.00817.76
8.1.20.0080.00017.67
8.1.10.0030.00617.49
8.1.00.0040.00417.56
8.0.300.0070.00018.77
8.0.290.0040.00416.88
8.0.280.0000.00818.55
8.0.270.0000.00717.25
8.0.260.0000.00617.20
8.0.250.0030.00317.12
8.0.240.0050.00317.06
8.0.230.0050.00317.08
8.0.220.0060.00317.05
8.0.210.0030.00317.01
8.0.200.0030.00317.08
8.0.190.0000.00816.96
8.0.180.0040.00417.06
8.0.170.0080.00016.99
8.0.160.0060.00317.01
8.0.150.0040.00416.96
8.0.140.0070.00016.88
8.0.130.0060.00013.41
8.0.120.0000.00916.89
8.0.110.0000.00716.97
8.0.100.0070.00016.89
8.0.90.0040.00416.82
8.0.80.0080.00816.96
8.0.70.0050.00317.02
8.0.60.0080.00017.00
8.0.50.0040.00416.97
8.0.30.0110.00717.12
8.0.20.0110.01017.40
8.0.10.0000.00817.26
8.0.00.0130.00717.01
7.4.330.0000.00516.70
7.4.320.0000.00616.49
7.4.300.0060.00016.67
7.4.290.0030.00516.52
7.4.280.0030.00616.57
7.4.270.0030.00516.72
7.4.260.0030.00316.64
7.4.250.0040.00416.46
7.4.240.0020.00516.61
7.4.230.0040.00416.68
7.4.220.0160.00416.72
7.4.210.0070.00716.62
7.4.200.0040.00416.78
7.4.160.0100.00616.43
7.4.150.0160.01017.40
7.4.140.0120.00717.86
7.4.130.0090.01216.76
7.4.120.0120.00616.51
7.4.110.0140.00316.59
7.4.100.0130.00716.64
7.4.90.0120.00916.70
7.4.80.0090.01119.39
7.4.70.0070.01416.80
7.4.60.0090.00916.68
7.4.50.0070.01016.53
7.4.40.0130.00716.27
7.4.30.0160.00316.73
7.4.10.0030.01914.90
7.4.00.0070.00715.01
7.3.330.0000.00613.46
7.3.320.0030.00313.50
7.3.310.0070.00016.57
7.3.300.0030.00316.43
7.3.290.0080.00716.46
7.3.280.0120.00716.44
7.3.270.0110.01017.40
7.3.260.0140.00316.62
7.3.250.0130.00916.45
7.3.240.0080.01216.50
7.3.230.0120.01216.50
7.3.210.0060.01316.36
7.3.200.0130.00616.31
7.3.190.0110.00516.46
7.3.180.0060.00916.51
7.3.170.0160.00716.62
7.3.160.0100.01016.47
7.3.130.0100.01014.89
7.3.120.0100.01014.93
7.3.110.0040.00814.98
7.3.100.0060.00615.16
7.3.90.0110.00015.18
7.3.80.0000.01215.20
7.3.70.0000.01414.97
7.3.60.0090.00014.99
7.3.50.0060.00915.01
7.3.40.0060.00314.95
7.3.30.0090.00614.95
7.3.20.0030.00716.68
7.3.10.0100.00716.36
7.3.00.0050.01016.48
7.2.330.0070.01016.94
7.2.320.0110.01116.54
7.2.310.0100.00716.76
7.2.300.0060.01416.87
7.2.290.0120.00616.75
7.2.260.0140.00715.18
7.2.250.0040.01615.39
7.2.240.0070.00715.29
7.2.230.0120.00314.97
7.2.220.0090.00015.17
7.2.210.0000.01514.83
7.2.200.0070.00715.29
7.2.190.0040.00815.16
7.2.180.0000.00914.91
7.2.170.0040.01115.18
7.2.160.0100.00615.03
7.2.150.0030.00916.98
7.2.140.0030.01016.79
7.2.130.0070.00516.56
7.2.120.0020.00916.64
7.2.110.0080.01016.53
7.2.100.0100.00616.71
7.2.90.0100.01216.78
7.2.80.0120.00616.79
7.2.70.0080.00816.66
7.2.60.0060.00716.59
7.2.50.0070.01116.63
7.2.40.0070.01016.81
7.2.30.0190.00916.71
7.2.20.0120.01116.63
7.2.10.0110.00616.72
7.2.00.0120.00917.63
7.1.330.0000.01315.86
7.1.320.0060.00615.62
7.1.310.0030.01015.77
7.1.300.0030.00915.77
7.1.290.0110.00415.73
7.1.280.0040.01115.66
7.1.270.0070.00415.88
7.1.260.0030.01415.65
7.1.250.0060.00815.65
7.1.240.0090.00615.53
7.1.230.0000.00815.91
7.1.220.0070.00315.91
7.1.210.0110.00316.02
7.1.200.0030.01015.87
7.1.190.0000.01315.62
7.1.180.0090.00615.64
7.1.170.0060.00615.75
7.1.160.0040.01115.76
7.1.150.0030.01015.54
7.1.140.0030.01315.86
7.1.130.0090.00315.85
7.1.120.0070.00715.68
7.1.110.0040.00715.79
7.1.100.0070.00717.10
7.1.90.0030.00915.90
7.1.80.0000.01515.91
7.1.70.0010.00616.52
7.1.60.0060.01117.64
7.1.50.0110.01225.18
7.1.40.0070.00315.75
7.1.30.0090.00315.53
7.1.20.0000.01215.89
7.1.10.0030.01415.75
7.1.00.0030.04519.01
7.0.330.0030.00915.29
7.0.320.0070.00415.52
7.0.310.0040.01115.27
7.0.300.0110.00415.48
7.0.290.0030.01015.24
7.0.280.0030.01015.20
7.0.270.0040.00815.31
7.0.260.0090.00615.29
7.0.250.0080.00415.61
7.0.240.0000.01015.42
7.0.230.0030.00915.47
7.0.220.0000.01015.18
7.0.210.0000.01215.40
7.0.200.0060.00416.11
7.0.190.0070.00315.59
7.0.180.0060.00315.37
7.0.170.0030.00915.36
7.0.160.0000.00815.19
7.0.150.0000.01515.58
7.0.140.0100.00715.63
7.0.130.0060.00615.55
7.0.120.0030.01015.47
7.0.110.0060.00915.24
7.0.100.0070.01015.20
7.0.90.0040.01515.35
7.0.80.0080.00815.38
7.0.70.0060.00615.26
7.0.60.0060.04717.71
7.0.50.0030.03316.77
7.0.40.0050.04916.96
7.0.30.0180.04316.72
7.0.20.0150.04816.96
7.0.10.0080.04016.80
7.0.00.0050.03216.85
5.6.400.0030.01014.70
5.6.390.0030.00714.69
5.6.380.0000.01314.54
5.6.370.0040.00814.52
5.6.360.0160.00014.48
5.6.350.0060.00614.73
5.6.340.0100.00314.75
5.6.330.0070.01014.65
5.6.320.0040.00714.50
5.6.310.0060.00914.28
5.6.300.0040.01414.88
5.6.290.0040.01114.52
5.6.280.0080.03817.74
5.6.270.0120.00314.57
5.6.260.0070.01114.51
5.6.250.0150.00314.57
5.6.240.0030.01414.15
5.6.230.0030.01314.27
5.6.220.0070.00314.50
5.6.210.0060.04417.50
5.6.200.0050.04316.20
5.6.190.0070.04317.32
5.6.180.0260.03517.38
5.6.170.0190.04217.66
5.6.160.0060.04317.52
5.6.150.0060.03516.35
5.6.140.0080.04016.38
5.6.130.0030.03216.52
5.6.120.0030.03717.84
5.6.110.0020.03617.78
5.6.100.0050.02317.68
5.6.90.0100.03817.73
5.6.80.0030.03917.33
5.6.70.0030.01014.45
5.6.60.0060.00914.26
5.6.50.0090.00614.44
5.6.40.0060.00314.57
5.6.30.0060.00614.17
5.6.20.0030.00814.45
5.6.10.0040.01114.29
5.6.00.0030.01314.38
5.5.380.0080.00514.66
5.5.370.0000.01514.39
5.5.360.0060.00614.64
5.5.350.0190.03917.58
5.5.340.0080.03516.28
5.5.330.0070.04017.30
5.5.320.0080.02517.52
5.5.310.0100.03817.31
5.5.300.0050.04516.08
5.5.290.0070.04216.20
5.5.280.0020.05217.68
5.5.270.0030.02917.71
5.5.260.0050.02617.60
5.5.250.0040.03917.41
5.5.240.0120.04217.33
5.5.230.0060.00314.14
5.5.220.0060.00614.47
5.5.210.0060.00914.51
5.5.200.0090.00314.37
5.5.190.0030.00614.52
5.5.180.0000.00814.43
5.5.170.0090.00614.13
5.5.160.0110.00314.16
5.5.150.0030.01014.37
5.5.140.0040.01114.35
5.5.130.0090.00614.09
5.5.120.0140.00014.59
5.5.110.0120.00314.21
5.5.100.0030.00614.36
5.5.90.0060.01014.24
5.5.80.0060.00914.41
5.5.70.0130.00314.11
5.5.60.0070.00713.94
5.5.50.0100.00714.53
5.5.40.0040.01114.34
5.5.30.0070.00714.41
5.5.20.0070.01014.47
5.5.10.0070.00714.11
5.5.00.0040.01414.05

preferences:
30.59 ms | 401 KiB | 5 Q