3v4l.org

run code in 300+ PHP versions simultaneously
<?php function buildRegexFrom(string $word): string { // Split word to letters $letters = str_split($word); // Creating all side of alternations in our regex foreach ($letters as $key => $letter) if (end($letters) != $letter) $regex[] = "$letter(?={$letters[$key + 1]})|(?<=$letter){$letters[$key + 1]}"; // Return whole cooked pattern return "~(?|((?>".implode('|', $regex).")+)|([$word]))~i"; } function longestSubstring(array $array, string $regex): array { foreach ($array as $value) { preg_match_all($regex, $value, $matches); usort($matches[1], function($a, $b) { return strlen($b) <=> strlen($a); }); // Store longest match being sorted $substrings[] = $matches[1][0]; } return $substrings; } print_r(longestSubstring(['Mymaxmuis', 'axmuis', 'muster'], buildRegexFrom('maxmuster')));

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.140.0110.01118.02
8.4.130.0130.00718.09
8.4.120.0130.00822.34
8.4.110.0160.00520.74
8.4.100.0120.00818.70
8.4.90.0070.00718.84
8.4.80.0160.00518.82
8.4.70.0050.00418.29
8.4.60.0100.00924.14
8.4.50.0090.01120.70
8.4.40.0120.00917.93
8.4.30.0000.00919.65
8.4.20.0030.01717.88
8.4.10.0000.00918.00
8.3.270.0110.01017.09
8.3.260.0130.00716.82
8.3.250.0120.00718.97
8.3.240.0140.00516.95
8.3.230.0120.00816.57
8.3.220.0050.00320.60
8.3.210.0130.00618.62
8.3.200.0060.00316.80
8.3.190.0120.00617.41
8.3.180.0110.00819.24
8.3.170.0030.01616.76
8.3.160.0120.00617.29
8.3.150.0120.00618.98
8.3.140.0090.00017.38
8.3.130.0080.00018.73
8.3.120.0130.00319.06
8.3.110.0090.00620.94
8.3.100.0030.00516.79
8.3.90.0040.00418.80
8.3.80.0060.00318.80
8.3.70.0150.00618.68
8.3.60.0090.00617.00
8.3.50.0130.00921.33
8.3.40.0090.00619.12
8.3.30.0090.00619.01
8.3.20.0040.00420.16
8.3.10.0050.00321.81
8.3.00.0040.00418.03
8.2.290.0100.00920.56
8.2.280.0110.00818.91
8.2.270.0080.00017.10
8.2.260.0150.00416.68
8.2.250.0060.00316.89
8.2.240.0140.00417.13
8.2.230.0030.00522.58
8.2.220.0060.00324.06
8.2.210.0080.00026.77
8.2.200.0040.00418.54
8.2.190.0110.00417.00
8.2.180.0040.01217.00
8.2.170.0120.00422.96
8.2.160.0070.00721.04
8.2.150.0040.00425.66
8.2.140.0000.00924.66
8.2.130.0080.00026.16
8.2.120.0040.00421.25
8.2.110.0000.01021.07
8.2.100.0120.00017.84
8.2.90.0040.00818.09
8.2.80.0000.00818.22
8.2.70.0000.00817.88
8.2.60.0090.00017.88
8.2.50.0030.00517.88
8.2.40.0000.00819.60
8.2.30.0040.00419.45
8.2.20.0040.00418.25
8.2.10.0040.00418.34
8.2.00.0040.00418.49
8.1.330.0050.00522.25
8.1.320.0150.00716.36
8.1.310.0030.00716.93
8.1.300.0030.00718.39
8.1.290.0060.00318.88
8.1.280.0140.00725.92
8.1.270.0000.00824.66
8.1.260.0080.00026.35
8.1.250.0000.00828.09
8.1.240.0070.00322.61
8.1.230.0040.00720.97
8.1.220.0090.00017.88
8.1.210.0030.00918.81
8.1.200.0050.00317.60
8.1.190.0000.00817.48
8.1.180.0060.00318.10
8.1.170.0050.00317.94
8.1.160.0000.00718.96
8.1.150.0040.00420.27
8.1.140.0070.00019.51
8.1.130.0000.00719.08
8.1.120.0020.00517.56
8.1.110.0000.00717.55
8.1.100.0040.00417.52
8.1.90.0040.00417.61
8.1.80.0000.00717.68
8.1.70.0000.00717.58
8.1.60.0000.00817.78
8.1.50.0030.00717.73
8.1.40.0040.00417.71
8.1.30.0040.00417.77
8.1.20.0030.00517.74
8.1.10.0040.00417.77
8.1.00.0070.00017.68
8.0.300.0070.00020.26
8.0.290.0000.00817.00
8.0.280.0030.00318.51
8.0.270.0040.00417.30
8.0.260.0030.00318.95
8.0.250.0050.00317.13
8.0.240.0030.00317.20
8.0.230.0070.00017.26
8.0.220.0030.00317.14
8.0.210.0040.00417.13
8.0.200.0030.00317.15
8.0.190.0040.00417.11
8.0.180.0030.00517.09
8.0.170.0040.00417.16
8.0.160.0000.00817.11
8.0.150.0070.00017.03
8.0.140.0050.00217.06
8.0.130.0050.00013.46
8.0.120.0050.00316.95
8.0.110.0070.00016.98
8.0.100.0040.00416.91
8.0.90.0000.00716.96
8.0.80.0100.00717.06
8.0.70.0000.00817.04
8.0.60.0040.00417.04
8.0.50.0070.00016.95
8.0.30.0110.00717.34
8.0.20.0120.01017.45
8.0.10.0040.00417.09
8.0.00.0110.01217.05
7.4.330.0050.00015.55
7.4.320.0050.00316.84
7.4.300.0000.00616.82
7.4.290.0040.00416.78
7.4.280.0060.00316.73
7.4.270.0000.00716.78
7.4.260.0060.00316.68
7.4.250.0030.00516.82
7.4.240.0070.00016.76
7.4.230.0070.00016.89
7.4.220.0030.01616.95
7.4.210.0060.01216.87
7.4.200.0000.00716.58
7.4.160.0060.01016.76
7.4.150.0070.01717.40
7.4.140.0090.00917.86
7.4.130.0150.00316.71
7.4.120.0150.00616.79
7.4.110.0100.00716.83
7.4.100.0100.00716.82
7.4.90.0140.00316.91
7.4.80.0050.01319.39
7.4.70.0150.00816.74
7.4.60.0060.00916.48
7.4.50.0100.00616.88
7.4.40.0060.01316.64
7.4.30.0090.00916.82
7.4.00.0020.01315.27
7.3.330.0000.00513.55
7.3.320.0050.00013.56
7.3.310.0050.00316.38
7.3.300.0070.00016.57
7.3.290.0040.00416.52
7.3.280.0090.00916.55
7.3.270.0110.00617.40
7.3.260.0080.01116.74
7.3.250.0080.01116.53
7.3.240.0050.01216.83
7.3.230.0120.00616.92
7.3.210.0090.00916.64
7.3.200.0100.00716.71
7.3.190.0040.01316.82
7.3.180.0040.01216.80
7.3.170.0090.01316.90
7.3.160.0070.01016.50
7.3.120.0070.00714.98
7.3.110.0030.01315.29
7.3.100.0130.00315.29
7.3.90.0060.00615.16
7.3.80.0100.00615.21
7.3.70.0030.01014.96
7.3.60.0000.01315.02
7.3.50.0100.00315.11
7.3.40.0090.00314.88
7.3.30.0040.00714.89
7.3.20.0030.01016.96
7.3.10.0050.00916.89
7.3.00.0020.01216.74
7.2.330.0060.01216.90
7.2.320.0070.01016.77
7.2.310.0100.00716.90
7.2.300.0090.00916.93
7.2.290.0030.01416.96
7.2.250.0090.00915.38
7.2.240.0070.01015.14
7.2.230.0090.00615.31
7.2.220.0080.00415.43
7.2.210.0060.00815.27
7.2.200.0030.01215.13
7.2.190.0000.01215.35
7.2.180.0000.01515.12
7.2.170.0120.00415.40
7.2.130.0070.00316.98
7.2.120.0080.00816.82
7.2.110.0000.01216.95
7.2.100.0090.00616.82
7.2.90.0090.00317.27
7.2.80.0140.00017.07
7.2.70.0070.01017.08
7.2.60.0120.00317.33
7.2.50.0090.00317.15
7.2.40.0070.00717.25
7.2.30.0070.00717.38
7.2.20.0030.01217.20
7.2.10.0070.00717.07
7.2.00.0000.01117.20
7.1.330.0090.00615.92
7.1.320.0040.00715.92
7.1.310.0050.00515.93
7.1.300.0080.00815.81
7.1.290.0000.00815.82
7.1.280.0040.00715.68
7.1.270.0030.00716.04
7.1.260.0060.00316.05
7.1.250.0030.01016.14
7.1.200.0040.00415.92
7.1.70.0030.00617.44
7.1.60.0040.00817.54
7.1.50.0000.01417.16
7.1.40.0230.01334.54
7.1.30.0170.02334.86
7.1.20.0130.01334.71
7.1.10.0270.01014.91
7.1.00.0030.01016.91
7.0.200.0060.01116.95
7.0.180.0070.01316.47
7.0.170.0000.01316.46
7.0.160.0070.01016.46
7.0.150.0330.01716.45
7.0.140.0000.01716.45
7.0.130.0000.01316.61
7.0.120.0000.01316.57
7.0.110.0270.01314.74
7.0.100.0270.00714.73
7.0.90.0330.01014.70
7.0.80.0400.01314.75
7.0.70.0070.01016.36
7.0.60.0000.01716.33
7.0.50.0070.00716.52
7.0.40.0300.01015.00
7.0.30.0300.01314.98
7.0.20.0070.00716.54
7.0.10.0300.01014.73
7.0.00.0030.01016.30

preferences:
30.49 ms | 403 KiB | 5 Q