3v4l.org

run code in 300+ PHP versions simultaneously
<?php function halfer(string $string): array { $result = []; $result['explode2'] = explode("\n", $string, 2); $result['preg_split2'] = preg_split("~\R+~", $string, 2, PREG_SPLIT_NO_EMPTY); $newlinePosition = strpos($string,"\n"); $result['substrs'] = [substr($string, 0, $newlinePosition), substr($string, $newlinePosition)]; $result['nlP'] = preg_split("~\n~" ,$string, $newlinePosition); return $result; } $strings = [ 'two newlines' => "1st line\n2nd line\n3rd line", 'leading newline' => "\n1st line\n2nd line\n3rd line", 'lone trailing newline' => "1st line\n", 'no newlines' => "1st line", 'double newlines' => "1st line\n\n2nd line", '\r\n' => "1st\r\n2nd", ]; foreach ($strings as $label => $string) { echo "$label\n"; echo json_encode(halfer($string), JSON_PRETTY_PRINT); echo "\n---\n"; }

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.4.120.0130.00620.75
8.4.110.0160.00422.36
8.4.100.0070.00518.93
8.4.90.0060.00418.93
8.4.80.0060.00318.73
8.4.70.0030.00518.29
8.4.60.0040.00519.02
8.4.50.0070.01218.86
8.4.40.0060.00917.76
8.4.30.0100.00620.53
8.4.20.0040.00717.98
8.4.10.0080.00017.78
8.3.250.0110.00518.95
8.3.240.0140.00616.98
8.3.230.0080.00816.54
8.3.220.0140.00518.93
8.3.210.0110.00918.78
8.3.200.0030.00516.55
8.3.190.0070.00819.04
8.3.180.0090.00418.97
8.3.170.0150.00317.06
8.3.160.0090.00616.78
8.3.150.0100.01016.72
8.3.140.0000.00816.77
8.3.130.0080.00018.55
8.3.120.0100.00718.95
8.3.110.0040.00416.91
8.3.100.0090.00018.73
8.3.90.0030.01226.77
8.3.80.0030.00617.00
8.3.70.0060.01316.61
8.3.60.0210.00016.60
8.3.50.0120.00316.83
8.3.40.0100.01019.09
8.3.30.0040.01118.92
8.3.20.0050.00324.18
8.3.10.0050.00324.66
8.3.00.0040.00426.16
8.2.290.0120.00620.69
8.2.280.0090.01018.81
8.2.270.0050.00316.70
8.2.260.0090.00617.07
8.2.250.0090.00616.86
8.2.240.0060.00317.49
8.2.230.0100.00720.94
8.2.220.0090.00924.06
8.2.210.0030.00626.77
8.2.200.0060.00616.75
8.2.190.0140.00016.88
8.2.180.0120.00325.92
8.2.170.0070.01719.27
8.2.160.0140.00422.96
8.2.150.0040.00425.66
8.2.140.0060.00324.66
8.2.130.0000.00826.16
8.2.120.0040.00421.10
8.2.110.0060.00322.25
8.2.100.0120.00018.03
8.2.90.0000.00817.88
8.2.80.0030.00618.86
8.2.70.0030.00518.02
8.2.60.0000.00918.22
8.2.50.0060.00318.10
8.2.40.0050.00321.20
8.2.30.0050.00319.43
8.2.20.0050.00318.21
8.2.10.0050.00319.35
8.2.00.0000.00719.23
8.1.330.0090.00721.97
8.1.320.0090.01117.99
8.1.310.0100.00718.53
8.1.300.0090.00019.85
8.1.290.0060.00630.84
8.1.280.0160.01325.92
8.1.270.0070.00023.99
8.1.260.0040.00426.35
8.1.250.0040.00428.09
8.1.240.0060.00322.13
8.1.230.0060.00617.83
8.1.220.0040.00417.74
8.1.210.0000.00918.77
8.1.200.0060.00317.47
8.1.190.0080.00017.48
8.1.180.0060.00318.10
8.1.170.0060.00318.71
8.1.160.0070.00018.97
8.1.150.0070.00018.92
8.1.140.0040.00418.83
8.1.130.0000.00720.09
8.1.120.0040.00417.61
8.1.110.0050.00317.57
8.1.100.0030.00517.59
8.1.90.0040.00417.63
8.1.80.0060.00317.61
8.1.70.0000.00817.62
8.1.60.0000.00817.74
8.1.50.0080.00017.52
8.1.40.0000.00817.73
8.1.30.0030.00917.74
8.1.20.0000.00817.82
8.1.10.0000.00817.69
8.1.00.0040.00417.63
8.0.300.0040.00418.77
8.0.290.0050.00316.63
8.0.280.0030.00318.46
8.0.270.0000.00716.88
8.0.260.0000.00718.48
8.0.250.0040.00417.13
8.0.240.0070.00017.05
8.0.230.0000.00717.07
8.0.220.0000.00816.96
8.0.210.0030.00316.97
8.0.200.0030.00317.14
8.0.190.0000.00717.02
8.0.180.0070.00017.09
8.0.170.0030.00617.01
8.0.160.0030.00516.97
8.0.150.0070.00016.89
8.0.140.0000.00717.02
8.0.130.0040.00413.47
8.0.120.0040.00416.90
8.0.110.0040.00416.95
8.0.100.0000.00816.85
8.0.90.0040.00417.08
8.0.80.0070.00717.02
8.0.70.0040.00416.93
8.0.60.0000.00716.98
8.0.50.0000.00717.10
8.0.30.0100.00716.92
8.0.20.0040.01717.12
8.0.10.0140.00717.12
8.0.00.0100.01017.18
7.4.330.0030.00315.55
7.4.320.0060.00016.74
7.4.300.0040.00416.82
7.4.290.0030.00316.78
7.4.280.0070.00416.75
7.4.270.0040.00416.68
7.4.260.0000.00613.54
7.4.250.0050.00316.68
7.4.240.0000.00816.78
7.4.230.0050.00216.82
7.4.220.0000.00816.84
7.4.210.0060.00916.79
7.4.200.0000.00716.92
7.4.160.0110.01416.90
7.4.150.0100.01216.81
7.4.140.0100.01016.82
7.4.130.0150.00616.64
7.4.120.0110.01016.66
7.4.110.0080.00816.75
7.4.100.0070.00716.71
7.4.90.0070.01416.64
7.4.80.0110.00816.61
7.4.70.0130.00316.64
7.4.60.0070.00716.71
7.4.50.0070.00716.64
7.4.40.0070.01316.63
7.4.30.0070.00716.85
7.4.20.0070.00716.71
7.4.10.0140.00016.70
7.4.00.0040.01116.84
7.3.330.0040.00416.51
7.3.320.0030.00313.55
7.3.310.0000.00716.62
7.3.300.0080.00016.52
7.3.290.0040.01416.49
7.3.270.0130.00616.52
7.3.260.0030.01016.48
7.3.250.0090.01116.48
7.3.240.0100.00616.51
7.3.230.0060.01016.45
7.3.220.0100.00616.41
7.3.210.0040.01116.43
7.3.200.0130.00516.42
7.3.190.0080.01116.42
7.3.180.0030.01116.52
7.3.170.0000.01416.36
7.3.160.0070.00716.41
7.3.150.0060.00916.43
7.3.140.0110.00716.52
7.3.130.0060.01516.45
7.3.120.0070.00716.36
7.3.110.0150.00316.36
7.3.100.0000.01516.46
7.3.90.0070.00716.70
7.3.80.0170.00016.56
7.3.70.0070.00716.58
7.3.60.0000.01316.60
7.3.50.0050.01016.54
7.3.40.0120.00616.57
7.3.30.0070.00716.57
7.3.20.0050.01016.61
7.3.10.0040.01116.60
7.3.00.0060.00916.53

preferences:
38.2 ms | 403 KiB | 5 Q