3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Graph { private $graph = []; private $nodes = []; public function __construct(array $edges) { foreach ($edges as $edge => $weight) { $start = $edge[0]; $end = $edge[1]; $this->graph[$start][$end] = $weight; $this->graph[$end][$start] = $weight; $this->nodes[$start] = [ 'L' => INF, 'Q' => null, 'final' => false, ]; $this->nodes[$end] = [ 'L' => INF, 'Q' => null, 'final' => false, ]; } } public function find($start, $end) { $this->initStartNode($start); $nodes = $this->getNextNodes($start); $startLength = $this->getLength($start); foreach($nodes as $node => $weight) { $currentLength = $this->getLength($node); if ($startLength + $weight < $currentLength) { $this->setLength($node, $startLength + $weight); $this->setFromNode($node, $start); } } // var_dump($this->getGraph()); var_dump($this->getNodes()); die(); } protected function initStartNode($node) { $this->setLength($node, 0); $this->setFromNode($node, '-'); $this->setFinal($node); } protected function getNextNodes($node) { return $this->graph[$node]; } protected function setLength($node, $value) { $this->nodes[$node]['L'] = $value; } protected function getLength($node) { return $this->nodes[$node]['L']; } protected function setFromNode($node, $value) { $this->nodes[$node]['Q'] = $value; } protected function setFinal($node) { $this->nodes[$node]['final'] = true; } public function getGraph() { return $this->graph; } public function getNodes() { return $this->nodes; } } $g = new Graph([ 'AB' => 5, 'AC' => 2, 'CB' => 2, 'CD' => 8, 'BE' => 7, 'DE' => 1, ]); $result = $g->find('A', 'E'); // var_dump($result); // var_dump($g->getGraph()); var_dump($g->getNodes());

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.60.0140.00718.56
8.3.50.0080.00818.30
8.3.40.0030.01318.97
8.3.30.0120.00618.73
8.3.20.0050.00320.25
8.3.10.0060.00320.40
8.3.00.0080.00021.69
8.2.180.0040.01118.41
8.2.170.0120.00922.96
8.2.160.0110.00420.35
8.2.150.0040.00424.18
8.2.140.0040.00424.66
8.2.130.0040.00422.20
8.2.120.0030.00526.35
8.2.110.0090.00022.12
8.2.100.0030.00920.53
8.2.90.0030.01017.44
8.2.80.0030.00619.46
8.2.70.0000.00817.93
8.2.60.0040.00418.16
8.2.50.0050.00319.41
8.2.40.0030.00620.42
8.2.30.0040.00420.36
8.2.20.0040.00418.09
8.2.10.0000.00818.09
8.2.00.0000.00718.31
8.1.280.0140.00725.92
8.1.270.0080.00018.93
8.1.260.0080.00026.35
8.1.250.0030.00628.09
8.1.240.0040.00423.87
8.1.230.0080.00419.23
8.1.220.0050.00317.74
8.1.210.0060.00318.77
8.1.200.0030.00617.36
8.1.190.0050.00317.35
8.1.180.0040.00418.10
8.1.170.0000.00818.72
8.1.160.0000.00718.98
8.1.150.0040.00420.31
8.1.140.0040.00419.58
8.1.130.0070.00019.05
8.1.120.0000.00717.53
8.1.110.0050.00317.38
8.1.100.0040.00417.46
8.1.90.0040.00417.49
8.1.80.0070.00017.47
8.1.70.0030.00317.49
8.1.60.0080.00017.61
8.1.50.0000.00717.63
8.1.40.0000.00817.58
8.1.30.0000.00817.66
8.1.20.0050.00217.53
8.1.10.0080.00017.48
8.1.00.0030.00517.48
8.0.300.0040.00719.91
8.0.290.0030.00616.88
8.0.280.0050.00218.47
8.0.270.0000.00817.19
8.0.260.0000.00617.26
8.0.250.0030.00317.09
8.0.240.0060.00317.02
8.0.230.0070.00017.07
8.0.220.0000.00716.89
8.0.210.0000.00716.95
8.0.200.0030.00317.05
8.0.190.0030.00717.07
8.0.180.0040.00416.92
8.0.170.0000.00817.00
8.0.160.0060.00316.98
8.0.150.0000.00716.88
8.0.140.0000.00716.92
8.0.130.0000.00713.36
8.0.120.0000.00916.99
8.0.110.0020.00516.96
8.0.100.0000.00716.99
8.0.90.0040.00417.05
8.0.80.0120.00416.96
8.0.70.0040.00416.88
8.0.60.0000.00716.98
8.0.50.0040.00416.82
8.0.30.0100.00816.88
8.0.20.0080.01417.40
8.0.10.0040.00417.14
8.0.00.0110.00717.09
7.4.330.0000.00615.55
7.4.320.0030.00316.63
7.4.300.0000.00716.54
7.4.290.0000.00916.62
7.4.280.0000.00816.63
7.4.270.0070.00016.59
7.4.260.0000.00716.50
7.4.250.0030.00316.54
7.4.240.0040.00416.57
7.4.230.0000.00716.30
7.4.220.0000.01816.76
7.4.210.0120.00316.64
7.4.200.0070.00016.67
7.4.160.0090.00716.53
7.4.150.0070.01117.40
7.4.140.0110.00717.86
7.4.130.0090.00916.64
7.4.120.0110.01216.67
7.4.110.0100.00816.55
7.4.100.0080.01116.70
7.4.90.0170.00716.31
7.4.80.0210.00319.39
7.4.70.0130.01216.71
7.4.60.0060.01016.59
7.4.50.0060.01116.66
7.4.40.0190.00316.67
7.4.30.0170.00316.38
7.4.00.0100.00715.09
7.3.330.0050.00013.31
7.3.320.0030.00313.34
7.3.310.0040.00416.50
7.3.300.0000.00716.38
7.3.290.0030.00316.44
7.3.280.0100.00816.47
7.3.270.0090.00917.40
7.3.260.0120.00916.58
7.3.250.0070.01316.56
7.3.240.0050.01216.48
7.3.230.0030.01416.68
7.3.210.0140.00316.40
7.3.200.0120.00616.41
7.3.190.0120.01016.77
7.3.180.0090.00916.54
7.3.170.0110.00516.60
7.3.160.0030.01616.49
7.3.10.0040.01216.46
7.3.00.0070.01016.80
7.2.330.0150.00616.78
7.2.320.0060.01216.79
7.2.310.0160.00516.76
7.2.300.0170.00716.42
7.2.290.0130.01016.93
7.2.130.0110.00716.95
7.2.120.0080.00816.98
7.2.110.0000.01017.07
7.2.100.0090.00917.08
7.2.90.0030.01017.03
7.2.80.0130.00017.13
7.2.70.0060.00917.07
7.2.60.0030.01217.16
7.2.50.0030.00917.13
7.2.40.0000.01517.00
7.2.30.0040.00716.81
7.2.20.0060.00617.09
7.2.10.0000.01317.00
7.2.00.0000.01217.14
7.1.250.0070.00715.82
7.1.70.0050.00217.26
7.1.60.0040.00717.37
7.1.20.0230.07038.25
7.1.10.0100.06722.17
7.1.00.0100.05722.29
7.0.200.0030.01016.56
7.0.160.0100.07721.89
7.0.150.0130.05321.80
7.0.140.0030.06321.91
7.0.130.0170.05021.79
7.0.120.0100.05321.93
7.0.110.0130.05721.77
7.0.100.0170.07321.81
7.0.90.0130.06321.98
7.0.80.0070.08021.81
7.0.70.0070.06321.86
7.0.60.0070.08021.86
7.0.50.0070.07721.88
7.0.40.0070.05721.72
7.0.30.0100.05321.98
7.0.20.0070.06321.89
7.0.10.0070.06321.86
7.0.00.0000.07021.83

preferences:
56.15 ms | 400 KiB | 5 Q