3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Node { public $color; public $key; public $value; public $left; public $right; public function __construct($key, $value, $color) { $this->key = $key; $this->value = $value; $this->color = $color; } public function compare($key) { if ($this->key < $key) return -1; elseif ($this->key > $key) return 1; else return 0; } } class RBTree { const RED = true; const BLACK = false; private $root; public function isEmpty() { return $this->root == null; } public function put($key, $value) { $this->root = $this->insert($this->root, (int)$key, $value); $this->root->color = self::BLACK; } public function get($key) { $x = $this->search($this->root, (int)$key); return $x ? $x->value : null; } private function isRed($h) { return $h ? $h->color : false; } private function insert($x, $key, $value) { if (!$x) return new Node($key, $value, self::RED); $cmp = $x->compare($key); if ($cmp > 0) $x->right = insert($x->right, $key, $value); elseif ($cmp < 0) $x->left = insert($x->left, $key, $value); else $x->value = $value; if ($this->isRed($x->right) && !$this->isRed($x->left)) $x = $this->rotateLeft($x); if ($this->isRed($x->left) && $this->isRed($x->left->left)) $x = $this->rotateRight($x); if ($this->isRed($x->left) && $this->isRed($x->right)) $this->flipColors($x); return $x; } private function search($x, $key) { while ($x) { $cmp = $x->compare($key); if ($cmp > 0) $x = $x->right; elseif ($cmp < 0) $x = $x->left; else return $x; } return null; } private function flipColors($h) { $h->color = !$h.color; $h->left->color = !h->left->color; $h->right->color = $h->right->color; } private function rotateLeft($h) { $x = $h->right; $h->right = $x->left; $x->left = $h; $x->color = $x->left->color; $x->left->color = self::RED; return $x; } private function rotateRight($h) { $x = $h->left; $h->left = $x->right; $x->right = $h; $x->color = $x->right->color; $x->right->color = self::RED; return $x; }

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.4.140.0100.06716.35
5.4.130.0100.05016.44
5.4.120.0100.05716.34
5.4.110.0130.06316.54
5.4.100.0070.03316.37
5.4.90.0030.06716.43
5.4.80.0130.06716.44
5.4.70.0070.07316.44
5.4.60.0030.08016.42
5.4.50.0070.05316.38
5.4.40.0070.07716.43
5.4.30.0070.07316.46
5.4.20.0070.07016.36
5.4.10.0070.04016.39
5.4.00.0030.06715.74
5.3.240.0030.04014.63
5.3.230.0070.04014.73
5.3.220.0070.07314.45
5.3.210.0070.06314.65
5.3.200.0030.04014.45
5.3.190.0070.05014.56
5.3.180.0030.04714.67
5.3.170.0130.07014.82
5.3.160.0030.06714.60
5.3.150.0030.07714.67
5.3.140.0130.07014.64
5.3.130.0070.07714.66
5.3.120.0030.05714.63
5.3.110.0100.05014.80
5.3.100.0070.07714.11
5.3.90.0130.05714.27
5.3.80.0130.07313.87
5.3.70.0030.06014.09
5.3.60.0070.07014.06
5.3.50.0030.04714.01
5.3.40.0000.06714.09
5.3.30.0070.05714.16
5.3.20.0000.04713.74
5.3.10.0130.06313.69
5.3.00.0100.06313.71

preferences:
135 ms | 1394 KiB | 7 Q