3v4l.org

run code in 300+ PHP versions simultaneously
<?php $rb = new RBTree; $inputs = array(); for ($i = 0; $i <= 100; ++$i) { $key = mt_rand(); $value = mt_rand(); $rb->put($key, $value); $inputs[] = $key; } for ($i = 0; $i <= 100; ++$i) { $key = mt_rand(0, 100); var_dump($key, $rb->get($key)); echo "\n"; } var_dump(101, $rb->get(101)); 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)
7.2.00.0000.01219.57
7.1.70.0030.00617.17
7.1.60.0000.01217.36
7.1.50.0090.01316.70
7.1.00.0070.06722.28
7.0.200.0090.00916.85
7.0.140.0070.06721.97
7.0.70.0000.04719.99
7.0.60.0100.03719.93
7.0.50.0030.04320.30
7.0.40.0130.03320.10
7.0.30.0130.03720.18
7.0.20.0030.04320.00
7.0.10.0030.04320.17
7.0.00.0030.04320.09
5.6.280.0000.07721.14
5.6.220.0070.04020.71
5.6.210.0100.03720.71
5.6.200.0100.03721.07
5.6.190.0100.07021.16
5.6.180.0100.03721.16
5.6.170.0000.04721.11
5.6.160.0000.04720.98
5.6.150.0000.04720.98
5.6.140.0100.03721.15
5.6.130.0030.04321.10
5.6.120.0030.05321.03
5.6.110.0100.03721.06
5.6.100.0030.04320.97
5.6.90.0030.04321.00
5.6.80.0000.06720.49
5.6.70.0030.07720.45
5.6.60.0000.04320.44
5.6.50.0030.07320.45
5.6.40.0070.03720.43
5.6.30.0070.03320.42
5.6.20.0130.06020.48
5.6.10.0030.06320.33
5.6.00.0100.08020.47
5.5.360.0100.03320.52
5.5.350.0070.04320.48
5.5.340.0070.04020.64
5.5.330.0000.04720.92
5.5.320.0030.04320.84
5.5.310.0030.04020.82
5.5.300.0070.04020.82
5.5.290.0030.04320.68
5.5.280.0130.03320.82
5.5.270.0070.04020.95
5.5.260.0000.04720.89
5.5.250.0070.05720.70
5.5.240.0030.04020.25
5.5.230.0030.07020.30
5.5.220.0070.03720.20
5.5.210.0000.06320.20
5.5.200.0000.04320.28
5.5.190.0100.04020.27
5.5.180.0030.04020.30
5.5.160.0070.08020.18
5.5.150.0070.04320.14
5.5.140.0000.05020.25
5.5.130.0070.08020.16
5.5.120.0130.04720.29
5.5.110.0030.06020.25
5.5.100.0200.06320.11
5.5.90.0030.08020.16
5.5.80.0070.06020.16
5.5.70.0100.05020.10
5.5.60.0030.06319.96
5.5.50.0170.07319.96
5.5.40.0200.04720.20
5.5.30.0070.06020.11
5.5.20.0130.05320.02
5.5.10.0130.05720.05
5.5.00.0070.08320.09
5.4.450.0030.04019.45
5.4.440.0000.04319.28
5.4.430.0000.04319.41
5.4.420.0070.03719.37
5.4.410.0000.04019.29
5.4.400.0070.06719.03
5.4.390.0000.04018.90
5.4.380.0030.03319.21
5.4.370.0000.04018.91
5.4.360.0130.03319.03
5.4.350.0000.04019.23
5.4.340.0000.04719.05
5.4.320.0030.05719.14
5.4.310.0100.06719.03
5.4.300.0030.04719.04
5.4.290.0070.08019.12
5.4.280.0100.07319.04
5.4.270.0070.06319.13
5.4.260.0100.07719.10
5.4.250.0130.07319.04
5.4.240.0000.08719.16
5.4.230.0100.04319.03
5.4.220.0030.04719.02
5.4.210.0100.07719.15
5.4.200.0200.06718.93
5.4.190.0030.06318.93
5.4.180.0070.03719.20
5.4.170.0100.04019.22
5.4.160.0100.06719.11
5.4.150.0130.06719.00
5.4.140.0170.06716.48
5.4.130.0100.06716.54
5.4.120.0070.07316.49
5.4.110.0070.04316.40
5.4.100.0100.05716.55
5.4.90.0070.03716.48
5.4.80.0070.05316.32
5.4.70.0070.07316.42
5.4.60.0070.04016.42
5.4.50.0100.07316.46
5.4.40.0100.06016.41
5.4.30.0100.05716.46
5.4.20.0070.06316.37
5.4.10.0070.04016.41
5.4.00.0000.08315.91
5.3.290.0030.08714.77
5.3.280.0000.06714.57
5.3.270.0030.07714.58
5.3.260.0100.07714.71
5.3.250.0130.07014.71
5.3.240.0070.07014.60
5.3.230.0100.07714.61
5.3.220.0130.07014.75
5.3.210.0030.08314.59
5.3.200.0130.06714.62
5.3.190.0030.04314.54
5.3.180.0070.06014.53
5.3.170.0030.04714.60
5.3.160.0200.06314.64
5.3.150.0100.07314.73
5.3.140.0070.08014.55
5.3.130.0100.07314.70
5.3.120.0030.08314.57
5.3.110.0070.07314.55
5.3.100.0030.06014.07
5.3.90.0100.04314.13
5.3.80.0070.06713.98
5.3.70.0100.04714.21
5.3.60.0100.07713.96
5.3.50.0230.06014.11
5.3.40.0030.08014.12
5.3.30.0000.06313.91
5.3.20.0100.07013.87
5.3.10.0000.06713.82
5.3.00.0100.04313.68
5.2.170.0070.06311.25
5.2.160.0030.06711.05
5.2.150.0030.07011.25
5.2.140.0030.06311.30
5.2.130.0030.05711.10
5.2.120.0000.06711.29
5.2.110.0070.04011.27
5.2.100.0030.03711.16
5.2.90.0100.03011.27
5.2.80.0000.03311.28
5.2.70.0000.03311.26
5.2.60.0070.05311.02
5.2.50.0100.07010.93
5.2.40.0100.05711.07
5.2.30.0070.04011.13
5.2.20.0070.06010.97
5.2.10.0070.04010.96
5.2.00.0100.06010.88
5.1.60.0000.05710.46
5.1.50.0070.05310.46
5.1.40.0030.04310.46
5.1.30.0130.03010.49
5.1.20.0030.05710.46
5.1.10.0030.03010.46
5.1.00.0030.05710.46
5.0.50.0030.04710.46
5.0.40.0070.04010.46
5.0.30.0030.06710.46
5.0.20.0000.03710.46
5.0.10.0030.04710.46
5.0.00.0000.07010.46
4.4.90.0000.03710.46
4.4.80.0030.03010.46
4.4.70.0030.02710.46
4.4.60.0100.03010.46
4.4.50.0030.02710.46
4.4.40.0070.05010.46
4.4.30.0070.03010.46
4.4.20.0000.02310.46
4.4.10.0000.04010.46
4.4.00.0030.05310.46
4.3.110.0000.04010.46
4.3.100.0000.02710.46
4.3.90.0030.03710.46
4.3.80.0030.03710.46
4.3.70.0030.01710.46
4.3.60.0030.03310.46
4.3.50.0000.04010.46
4.3.40.0070.05010.46
4.3.30.0000.03710.46
4.3.20.0000.03710.46
4.3.10.0000.03010.46
4.3.00.0070.03310.46

preferences:
34.56 ms | 401 KiB | 5 Q