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("ABCD", 100); echo ABCD; 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.0130.00318.68
8.3.60.0180.00016.75
8.3.50.0130.00921.97
8.3.40.0120.00318.88
8.3.30.0090.00618.60
8.3.20.0110.00420.30
8.3.10.0060.00323.56
8.3.00.0030.00519.50
8.2.180.0090.00916.88
8.2.170.0080.00822.96
8.2.160.0170.00320.43
8.2.150.0060.00324.18
8.2.140.0080.00024.66
8.2.130.0000.00920.35
8.2.120.0050.00326.35
8.2.110.0080.00320.53
8.2.100.0060.00618.04
8.2.90.0040.00419.21
8.2.80.0030.00517.97
8.2.70.0000.00817.50
8.2.60.0000.00817.93
8.2.50.0000.00818.07
8.2.40.0000.00719.36
8.2.30.0030.00620.74
8.2.20.0040.00417.69
8.2.10.0000.00818.19
8.2.00.0060.00318.13
8.1.280.0130.00925.92
8.1.270.0040.00423.79
8.1.260.0080.00028.09
8.1.250.0040.00428.09
8.1.240.0030.00623.91
8.1.230.0040.00817.79
8.1.220.0050.00317.77
8.1.210.0000.00918.77
8.1.200.0030.00617.25
8.1.190.0000.00817.70
8.1.180.0000.00818.10
8.1.170.0050.00318.68
8.1.160.0040.00422.08
8.1.150.0040.00418.89
8.1.140.0030.00519.48
8.1.130.0070.00017.60
8.1.120.0000.00717.52
8.1.110.0040.00417.40
8.1.100.0070.00317.35
8.1.90.0000.00817.33
8.1.80.0040.00417.38
8.1.70.0030.00917.45
8.1.60.0070.00317.57
8.1.50.0000.00817.52
8.1.40.0040.00417.59
8.1.30.0060.00317.70
8.1.20.0040.00417.47
8.1.10.0030.00617.59
8.1.00.0040.00417.50
8.0.300.0060.00318.77
8.0.290.0070.00016.88
8.0.280.0000.00718.39
8.0.270.0030.00317.36
8.0.260.0050.00317.27
8.0.250.0000.00616.92
8.0.240.0030.00317.10
8.0.230.0080.00016.96
8.0.220.0030.00617.02
8.0.210.0040.00417.09
8.0.200.0060.00017.08
8.0.190.0000.00717.11
8.0.180.0000.00716.94
8.0.170.0040.00417.02
8.0.160.0000.00717.02
8.0.150.0050.00216.87
8.0.140.0030.00416.91
8.0.130.0000.00613.45
8.0.120.0080.00016.89
8.0.110.0040.00417.01
8.0.100.0040.00417.02
8.0.90.0030.00516.98
8.0.80.0070.00717.03
8.0.70.0000.00817.02
8.0.60.0040.00416.89
8.0.50.0070.00016.97
8.0.30.0110.00917.18
8.0.20.0080.01317.42
8.0.10.0030.00616.94
8.0.00.0050.01316.71
7.4.330.0030.00316.67
7.4.320.0070.00016.45
7.4.300.0000.00716.60
7.4.290.0000.00816.57
7.4.280.0050.00516.62
7.4.270.0000.00716.59
7.4.260.0080.00016.58
7.4.250.0000.00816.59
7.4.240.0020.00516.63
7.4.230.0030.00316.78
7.4.220.0080.01216.65
7.4.210.0090.00616.54
7.4.200.0080.00016.76
7.4.160.0090.00916.63
7.4.150.0110.00817.40
7.4.140.0130.00817.86
7.4.130.0100.00916.60
7.4.120.0140.00816.56
7.4.110.0070.01116.57
7.4.100.0060.01216.57
7.4.90.0110.00716.79
7.4.80.0110.00719.39
7.4.70.0030.01416.62
7.4.60.0070.01116.66
7.4.50.0000.01816.48
7.4.40.0090.00916.52
7.4.30.0070.01716.51
7.4.00.0000.00814.73
7.3.330.0050.00013.48
7.3.320.0070.00013.42
7.3.310.0040.00416.51
7.3.300.0000.00716.34
7.3.290.0080.00716.35
7.3.280.0140.00416.47
7.3.270.0090.00917.40
7.3.260.0130.00516.67
7.3.250.0130.00616.47
7.3.240.0100.00916.59
7.3.230.0160.01016.39
7.3.210.0060.01216.51
7.3.200.0100.00716.45
7.3.190.0080.00816.57
7.3.180.0070.01016.70
7.3.170.0130.01016.72
7.3.160.0070.01116.63
7.2.330.0090.00916.64
7.2.320.0090.01216.56
7.2.310.0100.01016.63
7.2.300.0070.01316.97
7.2.290.0140.00716.64
7.2.60.0030.00916.78
7.2.00.0060.00619.21
7.1.200.0060.00615.96
7.1.100.0060.00618.23
7.1.70.0180.00617.28
7.1.60.0130.01319.36
7.1.50.0060.01616.90
7.1.00.0130.06722.54
7.0.200.0000.00916.62
7.0.60.0070.05719.96
7.0.50.0000.05317.94
7.0.40.0130.07720.40
7.0.30.0330.07320.33
7.0.20.0370.04720.23
7.0.10.0130.08320.08
7.0.00.0130.07720.23
5.6.280.0070.03720.89
5.6.210.0170.06720.53
5.6.200.0070.08018.29
5.6.190.0130.08320.59
5.6.180.0530.04720.50
5.6.170.0230.05320.47
5.6.160.0070.03720.78
5.6.150.0030.04018.27
5.6.140.0070.05018.13
5.6.130.0100.07018.19
5.6.120.0070.06320.93
5.6.110.0070.05321.04
5.6.100.0070.05721.01
5.6.90.0200.05720.91
5.6.80.0130.07720.56
5.5.350.0200.07720.51
5.5.340.0030.04017.96
5.5.330.0030.04720.40
5.5.320.0100.04320.30
5.5.310.0170.05020.37
5.5.300.0070.08317.94
5.5.290.0070.05717.96
5.5.280.0130.08020.79
5.5.270.0070.08320.92
5.5.260.0100.08020.87
5.5.250.0130.06720.61
5.5.240.0230.07320.06

preferences:
58.17 ms | 401 KiB | 5 Q