3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Node { public $val; public $next; public function __construct($val, $next) { $this->val = $val; $this->next = $next; } public function __toString() { $a = []; $c = $this; while ($c != null) { $a[] = $c->val; $c = $c->next; } return implode(", ", $a)."\n"; } public static function reverse($list) { $newl = null; $curr = $list; while ($curr != null) { $next = $curr->next; $curr->next = $newl; $newl = $curr; $curr = $next; } return $newl; } public static function reverseRecursively($list) { if ($list == null || $list->next == null) { return $list; } $next = $list->next; $list->next = null; $newl = self::reverseRecursively($next); $newl->next = $list; return $newl; } } $list = new Node(1, new Node(2, new Node(3, new Node(4, new Node(5, null))))); echo $list; $list = Node::reverse($list); echo $list; exit();

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.0120.00616.63
8.3.50.0040.01116.20
8.3.40.0000.01418.79
8.3.30.0080.00818.81
8.3.20.0000.00720.24
8.3.10.0030.00621.77
8.3.00.0000.00822.09
8.2.180.0090.00916.34
8.2.170.0040.01122.96
8.2.160.0130.00319.04
8.2.150.0060.00324.18
8.2.140.0080.00024.66
8.2.130.0070.00021.02
8.2.120.0080.00026.35
8.2.110.0060.00321.24
8.2.100.0110.00018.34
8.2.90.0050.00319.36
8.2.80.0000.00917.97
8.2.70.0040.00417.75
8.2.60.0080.00018.05
8.2.50.0090.00018.16
8.2.40.0040.00420.64
8.2.30.0080.00021.00
8.2.20.0040.00418.14
8.2.10.0040.00418.25
8.2.00.0000.00718.02
8.1.280.0120.00925.92
8.1.270.0040.00422.24
8.1.260.0070.00026.35
8.1.250.0050.00228.09
8.1.240.0060.00323.98
8.1.230.0110.00017.47
8.1.220.0000.00817.74
8.1.210.0000.00818.77
8.1.200.0100.00017.35
8.1.190.0060.00317.25
8.1.180.0000.00818.10
8.1.170.0050.00518.66
8.1.160.0000.00718.98
8.1.150.0040.00420.55
8.1.140.0000.01017.48
8.1.130.0050.00318.79
8.1.120.0000.00717.39
8.1.110.0000.00817.35
8.1.100.0000.00717.50
8.1.90.0030.00517.40
8.1.80.0000.00717.37
8.1.70.0000.00717.49
8.1.60.0000.00817.43
8.1.50.0030.00617.47
8.1.40.0080.00017.49
8.1.30.0040.00417.63
8.1.20.0000.00817.70
8.1.10.0000.00817.46
8.1.00.0040.00417.50
8.0.300.0040.00418.77
8.0.290.0030.00716.75
8.0.280.0030.00318.53
8.0.270.0070.00017.18
8.0.260.0000.00716.91
8.0.250.0030.00317.07
8.0.240.0040.00417.05
8.0.230.0070.00017.02
8.0.220.0050.00216.95
8.0.210.0000.00717.04
8.0.200.0000.00616.92
8.0.190.0080.00017.02
8.0.180.0040.00416.93
8.0.170.0000.00716.97
8.0.160.0040.00417.02
8.0.150.0000.00716.94
8.0.140.0000.00716.97
8.0.130.0000.00713.40
8.0.120.0040.00416.97
8.0.110.0060.00316.91
8.0.100.0040.00416.94
8.0.90.0000.00717.02
8.0.80.0130.00717.02
8.0.70.0030.00516.77
8.0.60.0070.00016.90
8.0.50.0000.00816.80
8.0.30.0050.01517.22
8.0.20.0110.00817.40
8.0.10.0050.00217.05
8.0.00.0070.01016.79
7.4.330.0000.00615.55
7.4.320.0030.00316.61
7.4.300.0030.00616.61
7.4.290.0030.00316.53
7.4.280.0070.00016.65
7.4.270.0070.00016.47
7.4.260.0040.00416.62
7.4.250.0040.00416.62
7.4.240.0050.00216.66
7.4.230.0030.00316.50
7.4.220.0100.01016.67
7.4.210.0110.00416.71
7.4.200.0030.00416.55
7.4.160.0050.01116.59
7.4.150.0100.01317.40
7.4.140.0130.00417.86
7.4.130.0090.00916.70
7.4.120.0070.01416.60
7.4.110.0060.00916.37
7.4.100.0070.01516.64
7.4.90.0100.01016.46
7.4.80.0080.00819.39
7.4.70.0060.01116.59
7.4.60.0030.01416.60
7.4.50.0060.00916.63
7.4.40.0030.01316.40
7.4.30.0030.01316.55
7.4.00.0090.00414.67
7.3.330.0050.00013.42
7.3.320.0030.00313.32
7.3.310.0030.00316.27
7.3.300.0030.00316.42
7.3.290.0060.01016.43
7.3.280.0060.01016.46
7.3.270.0060.01217.40
7.3.260.0080.00916.66
7.3.250.0080.01016.45
7.3.240.0120.00616.58
7.3.230.0100.00716.67
7.3.210.0130.00316.56
7.3.200.0120.00316.74
7.3.190.0110.00616.49
7.3.180.0070.01116.53
7.3.170.0060.01116.40
7.3.160.0050.01116.48
7.2.330.0040.01316.76
7.2.320.0170.01416.87
7.2.310.0100.00916.42
7.2.300.0110.00616.38
7.2.290.0150.00916.61
7.2.60.0120.00317.21
7.2.00.0060.01219.68
7.1.200.0070.00015.61
7.1.100.0030.01018.18
7.1.70.0060.01317.09
7.1.60.0260.01635.18
7.1.50.0310.01234.79
7.1.40.0170.02734.38
7.1.30.0290.01634.63
7.1.20.0250.01834.60
7.1.10.0060.01016.50
7.1.00.0000.01416.73
7.0.200.0030.01616.76
7.0.190.0160.00016.46
7.0.180.0020.01916.43
7.0.170.0070.01416.19
7.0.160.0090.00916.22
7.0.150.0070.01016.33
7.0.140.0080.01116.24
7.0.130.0030.01516.45
7.0.120.0160.00616.56
7.0.110.0060.01616.47
7.0.100.0090.01316.41
7.0.90.0000.01916.23
7.0.80.0040.01416.60
7.0.70.0100.01316.24
7.0.60.0030.01816.16
7.0.50.0060.01616.40
7.0.40.0120.00916.51
7.0.30.0110.01116.38
7.0.20.0210.00016.29
7.0.10.0110.01116.35
7.0.00.0080.01116.63

preferences:
39.08 ms | 401 KiB | 5 Q