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 = $this->insert($x->right, $key, $value); elseif ($cmp < 0) $x->left = $this->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.0070.00719.48
7.1.70.0090.00017.40
7.1.60.0060.02219.40
7.1.50.0060.01917.05
7.1.00.0000.08022.49
7.0.200.0000.00916.81
7.0.140.0000.08022.00
7.0.120.0000.04022.05
7.0.70.0100.07721.52
7.0.60.0030.08721.75
7.0.50.0000.09022.09
7.0.40.0070.08320.11
7.0.30.0070.07720.14
7.0.20.0100.08020.03
7.0.10.0130.08320.18
7.0.00.0070.08719.93
5.6.280.0100.07321.07
5.6.220.0000.09020.86
5.6.210.0000.08720.71
5.6.200.0000.09721.29
5.6.190.0070.08021.27
5.6.180.0000.08721.16
5.6.170.0100.08721.35
5.6.160.0030.09021.20
5.6.150.0030.08721.18
5.6.140.0000.08721.14
5.6.130.0100.08021.20
5.6.120.0070.08721.20
5.6.110.0070.08021.25
5.6.100.0030.07721.10
5.6.90.0100.06321.27
5.6.80.0000.05020.56
5.6.70.0130.03320.55
5.6.60.0000.04320.63
5.6.50.0000.04320.64
5.6.40.0030.05720.67
5.6.30.0000.05020.54
5.6.20.0070.04020.59
5.6.10.0000.04320.61
5.6.00.0000.05720.63
5.5.360.0070.08320.48
5.5.350.0170.07320.54
5.5.340.0070.08720.81
5.5.330.0000.09021.09
5.5.320.0100.08021.09
5.5.310.0070.08021.12
5.5.300.0100.05321.04
5.5.290.0070.07320.96
5.5.280.0130.08020.93
5.5.270.0030.08720.99
5.5.260.0030.09021.02
5.5.250.0030.04320.72
5.5.240.0030.06320.20
5.5.230.0030.05720.36
5.5.220.0030.04020.36
5.5.210.0030.04020.33
5.5.200.0030.05720.45
5.5.190.0030.05720.45
5.5.180.0000.03720.33
5.5.160.0000.03720.33
5.5.150.0030.03720.30
5.5.140.0030.03720.44
5.5.130.0000.03720.30
5.5.120.0000.03720.46
5.5.110.0030.03320.27
5.5.100.0000.03720.27
5.5.90.0000.03320.25
5.5.80.0070.02720.24
5.5.70.0030.03320.27
5.5.60.0030.03320.29
5.5.50.0030.03020.32
5.5.40.0100.03720.32
5.5.30.0030.03020.31
5.5.20.0000.03720.25
5.5.10.0030.03320.29
5.5.00.0000.03720.27
5.4.450.0000.08319.30
5.4.440.0030.09019.55
5.4.430.0100.07719.38
5.4.420.0130.07319.44
5.4.410.0070.07019.34
5.4.400.0030.03719.29
5.4.390.0000.04318.97
5.4.380.0070.03719.05
5.4.370.0000.03719.13
5.4.360.0030.03319.18
5.4.350.0000.06018.96
5.4.340.0030.04019.05
5.4.320.0000.04319.12
5.4.310.0000.03319.13
5.4.300.0000.04019.00
5.4.290.0030.03018.98
5.4.280.0000.03318.95
5.4.270.0030.03019.12
5.4.260.0000.03319.12
5.4.250.0030.03319.14
5.4.240.0000.03718.98
5.4.230.0030.03019.15
5.4.220.0030.03319.14
5.4.210.0000.03719.17
5.4.200.0000.04319.31
5.4.190.0000.03319.09
5.4.180.0000.03319.13
5.4.170.0000.06319.13
5.4.160.0030.07719.30
5.4.150.0130.07319.23
5.4.140.0030.08316.51
5.4.130.0130.07316.50
5.4.120.0030.08016.55
5.4.110.0030.07716.55
5.4.100.0070.07016.61
5.4.90.0030.07316.46
5.4.80.0030.07716.46
5.4.70.0070.07316.37
5.4.60.0030.06716.60
5.4.50.0000.08016.39
5.4.40.0000.08016.43
5.4.30.0130.07016.48
5.4.20.0030.08016.52
5.4.10.0030.07716.46
5.4.00.0070.07315.95
5.3.290.0000.06014.86
5.3.280.0000.03714.87
5.3.270.0000.03714.78
5.3.260.0070.07714.78
5.3.250.0000.04714.89
5.3.240.0000.08014.83
5.3.230.0030.08714.78
5.3.220.0000.08714.70
5.3.210.0030.09014.84
5.3.200.0100.07314.67
5.3.190.0030.08014.70
5.3.180.0030.09014.73
5.3.170.0070.08714.67
5.3.160.0130.07314.84
5.3.150.0070.08314.78
5.3.140.0030.08314.70
5.3.130.0030.07314.66
5.3.120.0070.06014.78
5.3.110.0000.09014.70
5.3.100.0000.08714.32
5.3.90.0030.07014.09
5.3.80.0030.07314.23
5.3.70.0030.08014.31
5.3.60.0000.08714.18
5.3.50.0000.07014.00
5.3.40.0030.08314.16
5.3.30.0030.07714.18
5.3.20.0030.08313.77
5.3.10.0000.08313.90
5.3.00.0030.08313.90
5.2.170.0070.06011.54
5.2.160.0030.07011.39
5.2.150.0070.07711.56
5.2.140.0000.07311.58
5.2.130.0030.06311.47
5.2.120.0030.06311.50
5.2.110.0000.07311.31
5.2.100.0000.06311.39
5.2.90.0100.06311.32
5.2.80.0030.07011.50
5.2.70.0070.07711.45
5.2.60.0030.07711.41
5.2.50.0030.07311.40
5.2.40.0000.07711.44
5.2.30.0070.07311.38
5.2.20.0000.06711.27
5.2.10.0000.07711.30
5.2.00.0070.07311.01
5.1.60.0030.06710.46
5.1.50.0030.06710.46
5.1.40.0000.06710.46
5.1.30.0000.08310.73
5.1.20.0030.06310.63
5.1.10.0000.07010.55
5.1.00.0000.07310.50
5.0.50.0000.06710.46
5.0.40.0100.05710.46
5.0.30.0030.07710.46
5.0.20.0000.06310.46
5.0.10.0000.05010.46
5.0.00.0000.08710.46
4.4.90.0070.02710.46
4.4.80.0030.03310.46
4.4.70.0070.02710.46
4.4.60.0030.03310.46
4.4.50.0000.03310.46
4.4.40.0000.05310.46
4.4.30.0030.03310.46
4.4.20.0030.03010.46
4.4.10.0000.04010.46
4.4.00.0030.04010.46
4.3.110.0030.03310.46
4.3.100.0000.03010.46
4.3.90.0000.03310.46
4.3.80.0030.05310.46
4.3.70.0030.03010.46
4.3.60.0000.03710.46
4.3.50.0000.03310.46
4.3.40.0070.04710.46
4.3.30.0030.03010.46
4.3.20.0000.03310.46
4.3.10.0030.03710.46
4.3.00.0000.03310.46

preferences:
33.89 ms | 401 KiB | 5 Q