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; $next = self::reverseRecursively($next); $next->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; $list = Node::reverseRecursively($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.0150.00616.50
8.3.50.0150.00016.38
8.3.40.0150.00318.83
8.3.30.0000.01418.80
8.3.20.0080.00020.25
8.3.10.0050.00521.76
8.3.00.0040.00421.92
8.2.180.0120.00618.22
8.2.170.0070.00722.96
8.2.160.0130.00719.08
8.2.150.0050.00324.18
8.2.140.0040.00424.66
8.2.130.0040.00420.96
8.2.120.0040.00426.35
8.2.110.0070.00322.16
8.2.100.0070.00417.84
8.2.90.0000.00819.22
8.2.80.0030.00518.03
8.2.70.0030.00617.63
8.2.60.0060.00317.77
8.2.50.0080.00018.10
8.2.40.0080.00020.61
8.2.30.0080.00021.14
8.2.20.0000.00818.20
8.2.10.0000.00718.02
8.2.00.0040.00418.07
8.1.280.0040.01125.92
8.1.270.0040.00421.92
8.1.260.0040.00426.35
8.1.250.0040.00428.09
8.1.240.0050.00523.82
8.1.230.0060.00617.70
8.1.220.0080.00017.74
8.1.210.0030.00518.77
8.1.200.0060.00317.38
8.1.190.0030.00517.35
8.1.180.0080.00018.10
8.1.170.0080.00020.43
8.1.160.0070.00019.07
8.1.150.0000.00720.67
8.1.140.0030.00619.66
8.1.130.0030.00318.95
8.1.120.0040.00417.58
8.1.110.0000.00717.52
8.1.100.0000.00717.43
8.1.90.0040.00417.52
8.1.80.0070.00017.50
8.1.70.0040.00417.57
8.1.60.0040.00417.60
8.1.50.0000.00817.59
8.1.40.0040.00417.52
8.1.30.0040.00417.70
8.1.20.0000.00817.57
8.1.10.0030.00617.63
8.1.00.0000.00717.45
8.0.300.0000.00718.77
8.0.290.0000.00916.88
8.0.280.0030.00318.50
8.0.270.0000.00717.24
8.0.260.0030.00616.94
8.0.250.0080.00017.05
8.0.240.0000.00817.11
8.0.230.0000.00716.96
8.0.220.0040.00416.87
8.0.210.0030.00516.96
8.0.200.0060.00016.93
8.0.190.0040.00417.00
8.0.180.0070.00017.06
8.0.170.0000.00817.04
8.0.160.0050.00516.94
8.0.150.0040.00417.00
8.0.140.0040.00416.86
8.0.130.0000.00713.48
8.0.120.0070.00016.86
8.0.110.0040.00416.82
8.0.100.0040.00416.87
8.0.90.0050.00217.07
8.0.80.0160.00316.91
8.0.70.0040.00416.86
8.0.60.0000.00716.89
8.0.50.0040.00417.01
8.0.30.0110.00816.86
8.0.20.0150.00517.40
8.0.10.0050.00317.01
8.0.00.0030.01516.82
7.4.330.0000.00515.55
7.4.320.0030.00316.54
7.4.300.0040.00416.43
7.4.290.0030.00316.54
7.4.280.0000.00816.61
7.4.270.0030.00316.67
7.4.260.0080.00016.54
7.4.250.0000.00716.52
7.4.240.0000.00716.62
7.4.230.0040.00416.53
7.4.220.0150.01216.48
7.4.210.0030.01516.42
7.4.200.0040.00416.52
7.4.160.0140.00616.72
7.4.150.0090.00917.40
7.4.140.0100.01017.86
7.4.130.0090.00916.63
7.4.120.0070.01116.61
7.4.110.0000.01716.43
7.4.100.0130.00416.64
7.4.90.0140.00316.45
7.4.80.0130.01019.39
7.4.70.0060.00916.77
7.4.60.0100.00616.50
7.4.50.0050.01016.67
7.4.40.0090.00916.66
7.4.30.0110.00516.50
7.4.10.0130.00716.73
7.4.00.0050.01215.68
7.3.330.0000.00513.26
7.3.320.0030.00313.26
7.3.310.0000.00716.54
7.3.300.0080.00016.40
7.3.290.0060.00916.43
7.3.280.0090.00716.42
7.3.270.0170.00017.40
7.3.260.0110.01016.44
7.3.250.0100.01216.51
7.3.240.0080.01116.39
7.3.230.0110.00716.59
7.3.210.0060.01216.52
7.3.200.0060.01216.31
7.3.190.0120.00916.65
7.3.180.0060.01116.41
7.3.170.0070.01416.57
7.3.160.0190.00316.64
7.3.130.0100.01016.42
7.3.120.0030.01316.39
7.3.110.0070.00716.37
7.3.100.0150.00416.41
7.3.90.0070.01116.45
7.3.80.0040.01116.62
7.3.70.0100.00616.44
7.3.60.0070.00716.50
7.3.50.0090.00216.43
7.3.40.0100.01016.45
7.3.30.0070.01116.46
7.3.20.0030.00718.20
7.3.10.0000.01318.39
7.3.00.0040.01118.09
7.2.330.0140.00416.84
7.2.320.0120.00416.79
7.2.310.0130.00316.72
7.2.300.0100.00716.79
7.2.290.0170.00016.70
7.2.260.0060.01216.49
7.2.250.0090.00916.67
7.2.240.0100.00716.61
7.2.230.0070.01116.50
7.2.220.0110.00716.53
7.2.210.0060.00616.59
7.2.200.0060.01016.62
7.2.190.0100.00016.48
7.2.180.0040.00716.54
7.2.170.0100.01016.55
7.2.160.0070.00516.64
7.2.150.0030.01018.51
7.2.140.0000.01118.39
7.2.130.0100.00618.39
7.2.120.0070.00718.52
7.2.110.0070.00718.65
7.2.100.0030.01318.54
7.2.90.0040.01118.43
7.2.80.0120.00418.53
7.2.70.0070.01418.51
7.2.60.0140.00317.64
7.2.50.0090.00618.40
7.2.40.0000.01018.46
7.2.30.0100.00718.48
7.2.20.0070.01118.46
7.2.10.0070.00718.32
7.2.00.0060.00618.29
7.1.330.0070.00717.46
7.1.320.0080.00817.35
7.1.310.0000.01317.47
7.1.300.0060.00917.54
7.1.290.0080.00817.41
7.1.280.0030.01217.31
7.1.270.0090.00317.30
7.1.260.0030.00717.43
7.1.250.0060.01017.27
7.1.240.0060.00617.21
7.1.230.0000.01117.27
7.1.220.0040.00817.34
7.1.210.0060.00917.50
7.1.200.0060.00816.63
7.1.190.0060.01017.17
7.1.180.0070.01117.43
7.1.170.0000.01117.34
7.1.160.0110.00017.21
7.1.150.0060.00617.48
7.1.140.0090.00617.43
7.1.130.0070.00317.38
7.1.120.0100.01017.39
7.1.110.0060.00917.45
7.1.100.0330.00616.72
7.1.90.0110.00417.54
7.1.80.0080.00317.36
7.1.70.0150.00716.34
7.1.60.0140.01426.09
7.1.50.0170.01626.05
7.1.40.0150.00925.89
7.1.30.0200.01325.85
7.1.20.0110.01125.93
7.1.10.0110.00716.92
7.1.00.0000.01417.08
7.0.330.0070.01117.15
7.0.320.0130.00016.97
7.0.310.0090.00316.96
7.0.300.0030.00917.08
7.0.290.0070.00716.98
7.0.280.0060.00916.87
7.0.270.0030.01016.97
7.0.260.0000.01117.09
7.0.250.0040.00417.14
7.0.240.0070.00717.11
7.0.230.0030.00816.99
7.0.220.0060.00617.13
7.0.210.0040.00817.11
7.0.200.0190.00816.09
7.0.190.0210.00816.90
7.0.180.0070.01116.83
7.0.170.0210.00415.81
7.0.160.0070.00516.68
7.0.150.0070.00916.60
7.0.140.0070.01016.78
7.0.130.0060.01116.63
7.0.120.0050.01416.79
7.0.110.0080.00816.58
7.0.100.0050.01116.64
7.0.90.0060.00716.85
7.0.80.0030.01216.55
7.0.70.0080.00916.76
7.0.60.0100.01416.73
7.0.50.0050.00916.65
7.0.40.0080.00715.85
7.0.30.0130.01115.83
7.0.20.0020.01315.60
7.0.10.0050.01215.65
7.0.00.0090.00615.82
5.6.400.0000.00915.98
5.6.390.0000.01415.76
5.6.380.0070.00716.08
5.6.370.0030.01416.04
5.6.360.0030.00716.10
5.6.350.0000.01515.99
5.6.340.0120.00616.01
5.6.330.0040.01116.05
5.6.320.0100.00016.18
5.6.310.0110.00715.83
5.6.300.0030.01415.96
5.6.290.0040.00715.90
5.6.280.0060.01016.09
5.6.270.0030.01016.05
5.6.260.0130.00015.89
5.6.250.0070.00716.09
5.6.240.0030.01016.00
5.6.230.0000.01515.96
5.6.220.0110.00416.04
5.6.210.0030.00916.34
5.6.200.0070.00316.04
5.6.190.0060.00315.97
5.6.180.0060.01015.99
5.6.170.0120.00616.15
5.6.160.0030.01016.16
5.6.150.0080.00415.94
5.6.140.0040.00715.89
5.6.130.0030.00915.82
5.6.120.0030.01016.11
5.6.110.0070.00315.79
5.6.100.0060.01015.98
5.6.90.0030.00916.00
5.6.80.0060.00315.93
5.6.70.0060.00915.82
5.6.60.0100.00015.89
5.6.50.0040.00815.64
5.6.40.0060.00615.99
5.6.30.0040.00815.88
5.6.20.0070.00716.03
5.6.10.0030.00615.93
5.6.00.0000.01516.09

preferences:
45.72 ms | 401 KiB | 5 Q