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("EMPTY", 100); echo EMPTY; 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)
5.6.150.0000.04318.19
5.6.140.0030.04318.28
5.6.130.0070.07718.15
5.6.120.0000.05321.16
5.6.110.0030.05321.02
5.6.100.0070.08021.09
5.6.90.0070.06321.08
5.6.80.0170.07020.39
5.5.300.0030.06317.97
5.5.290.0170.07018.09
5.5.280.0070.06020.91
5.5.270.0130.03720.73
5.5.260.0200.07020.88
5.5.250.0130.07320.48
5.5.240.0130.05320.14

preferences:
141.99 ms | 1394 KiB | 7 Q