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("CLEAR", "-"); echo CLEAR; 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.0120.00618.40
8.3.60.0090.01217.00
8.3.50.0270.00822.05
8.3.40.0060.00918.92
8.3.30.0120.00318.84
8.3.20.0040.00420.33
8.3.10.0040.00423.67
8.3.00.0050.00319.38
8.2.190.0120.00316.58
8.2.180.0090.01218.29
8.2.170.0060.00922.96
8.2.160.0140.00020.53
8.2.150.0040.00424.18
8.2.140.0040.00424.66
8.2.130.0040.00426.16
8.2.120.0140.00019.60
8.2.110.0030.00720.47
8.2.100.0040.00817.93
8.2.90.0050.00319.22
8.2.80.0040.00417.97
8.2.70.0030.00617.50
8.2.60.0060.00317.93
8.2.50.0000.00818.07
8.2.40.0070.00019.32
8.2.30.0000.00820.80
8.2.20.0080.00017.87
8.2.10.0080.00018.11
8.2.00.0040.00418.12
8.1.280.0110.00725.92
8.1.270.0050.00323.79
8.1.260.0050.00226.35
8.1.250.0050.00228.09
8.1.240.0090.00023.82
8.1.230.0080.00417.89
8.1.220.0050.00317.74
8.1.210.0030.00618.77
8.1.200.0060.00317.38
8.1.190.0000.00817.70
8.1.180.0000.00918.10
8.1.170.0040.00418.77
8.1.160.0050.00322.00
8.1.150.0000.00818.89
8.1.140.0030.00519.60
8.1.130.0070.00017.63
8.1.120.0000.00717.35
8.1.110.0030.00517.45
8.1.100.0090.00017.47
8.1.90.0030.00617.45
8.1.80.0060.00317.53
8.1.70.0030.00717.36
8.1.60.0100.00317.48
8.1.50.0000.00817.44
8.1.40.0040.00417.47
8.1.30.0070.00317.62
8.1.20.0000.00817.58
8.1.10.0050.00317.61
8.1.00.0060.00317.52
8.0.300.0000.00818.77
8.0.290.0020.00517.00
8.0.280.0000.00818.57
8.0.270.0040.00417.33
8.0.260.0080.00017.32
8.0.250.0000.00717.07
8.0.240.0030.00317.09
8.0.230.0040.00417.02
8.0.220.0050.00316.99
8.0.210.0030.00517.03
8.0.200.0000.00617.12
8.0.190.0040.00417.13
8.0.180.0040.00417.07
8.0.170.0030.00516.94
8.0.160.0040.00417.11
8.0.150.0000.00717.00
8.0.140.0040.00416.87
8.0.130.0000.00513.46
8.0.120.0030.00516.97
8.0.110.0070.00016.91
8.0.100.0040.00417.05
8.0.90.0040.00416.93
8.0.80.0150.00016.90
8.0.70.0080.00016.99
8.0.60.0040.00416.84
8.0.50.0000.00716.85
8.0.30.0070.01217.12
8.0.20.0120.00917.40
8.0.10.0040.00417.14
8.0.00.0070.01316.79
7.4.330.0050.00016.77
7.4.320.0000.00816.48
7.4.300.0070.00016.47
7.4.290.0030.00316.57
7.4.280.0030.00716.48
7.4.270.0000.00816.69
7.4.260.0030.00316.64
7.4.250.0040.00416.55
7.4.240.0020.00616.46
7.4.230.0030.00316.67
7.4.220.0140.00716.66
7.4.210.0100.01016.66
7.4.200.0050.00216.67
7.4.160.0130.00316.61
7.4.150.0160.00317.40
7.4.140.0130.00817.86
7.4.130.0140.00716.70
7.4.120.0130.00816.69
7.4.110.0100.01016.57
7.4.100.0120.00616.64
7.4.90.0130.01016.52
7.4.80.0150.00619.39
7.4.70.0110.00616.84
7.4.60.0080.00816.63
7.4.50.0090.00616.60
7.4.40.0070.01016.50
7.4.30.0110.00916.58
7.4.00.0110.00415.02
7.3.330.0000.00513.30
7.3.320.0030.00313.26
7.3.310.0000.00716.33
7.3.300.0030.00316.56
7.3.290.0070.00816.38
7.3.280.0110.00516.46
7.3.270.0090.00917.40
7.3.260.0110.00816.44
7.3.250.0050.01316.54
7.3.240.0100.01016.53
7.3.230.0150.01116.69
7.3.210.0130.00416.52
7.3.200.0000.01616.46
7.3.190.0140.00316.45
7.3.180.0060.01016.55
7.3.170.0060.01216.48
7.3.160.0080.00816.51
7.2.330.0100.00716.89
7.2.320.0040.01416.79
7.2.310.0070.01016.64
7.2.300.0070.01816.93
7.2.290.0160.00716.88
7.2.60.0060.00816.98
7.2.00.0070.01019.24
7.1.200.0000.01315.64
7.1.100.0030.00617.81
7.1.70.0110.01117.26
7.1.60.0070.01819.36
7.1.50.0030.01616.89
7.1.00.0070.07322.43
7.0.200.0000.00816.80
7.0.60.0070.04321.72
7.0.50.0070.05017.96
7.0.40.0030.09320.09
7.0.30.0330.07320.23
7.0.20.0300.04020.07
7.0.10.0100.06320.30
7.0.00.0070.07020.30
5.6.280.0070.07020.84
5.6.210.0130.06720.54
5.6.200.0070.04018.29
5.6.190.0070.08720.61
5.6.180.0370.05320.63
5.6.170.0270.05720.45
5.6.160.0030.04020.45
5.6.150.0030.04018.29
5.6.140.0030.05318.18
5.6.130.0070.07718.18
5.6.120.0100.08021.01
5.6.110.0030.08321.02
5.6.100.0100.05721.00
5.6.90.0100.07721.03
5.6.80.0100.07720.40
5.5.350.0030.07020.45
5.5.340.0130.05017.99
5.5.330.0070.05020.40
5.5.320.0030.07320.27
5.5.310.0270.04020.27
5.5.300.0170.07018.01
5.5.290.0030.04017.98
5.5.280.0100.08020.64
5.5.270.0070.05320.74
5.5.260.0070.09020.70
5.5.250.0030.04020.64
5.5.240.4300.03720.39

preferences:
53.34 ms | 401 KiB | 5 Q