3v4l.org

run code in 300+ PHP versions simultaneously
<?php $trailingString = '7mon6w5d4h3m2s bazinga!'; $leadingString = 'bazinga! in 9w8d7h6m5s'; $both = 'foo in 9d8h5m bar'; $noText = '2 w 3 m 4 d 9 mon'; /* * Replaces (s|m|h|d|w|mon) with strtotime compatible abbreviations * Optionally allows leading and/or trailing strings and returns an array with separated result set * * It should allow these and alikes: https://gist.github.com/DaveRandom/625fb4bf73112474fb5768a0a300e4e5 * * @param string $input, bool $requireLeadingString, bool $requireTrailingString * @return array $array */ function getTimeSpec(string $input, bool $requireLeadingString = false, bool $requireTrailingString = false): array { $expr1 = "/(.*)\s+(?:in)\s+(.*)/ui"; $expr2 = <<<'REGEX' ~ \s? (?<int> \d{1,5}) \s? (?<time> (?: s (?=(?:ec(?:ond)?s?)?(?:\b|\d)) | m (?=(?:in(?:ute)?s?)?(?:\b|\d)) | h (?=(?:(?:ou)?rs?)?(?:\b|\d)) | d (?=(?:ays?)?(?:\b|\d)) | w (?=(?:eeks?)?(?:\b|\d)) | mon (?=(?:(?:th)?s?)?(?:\b|\d)) ) ) [^\d]*?(?=\b|\d) # do only extract start of string | (?<text> .+) ~uix REGEX; $finalArray = $parsedTimeSpec = []; $leading = $trailing = ""; # If leading text is required, it should separate time and text by "in" # ie. "foo in 9 weeks 5 days" if($requireLeadingString && preg_match($expr1, $input, $parts)){ $leading = $parts['1'] ?? ''; $input = $parts['2']; } $time = preg_replace_callback ($expr2, function($matches) use (&$leading, &$trailing, &$requireTrailingString, &$parsedTimeSpec) { if ($requireTrailingString && isset($matches['text'])) { $trailing = trim($matches['text']); return ''; } switch($matches['time']){ case 's': $t = ' sec '; break; case 'm': $t = ' min '; break; case 'h': $t = ' hour '; break; case 'd': $t = ' day '; break; case 'w': $t = ' week '; break; case 'mon': $t = ' month '; break; } $completeTimeString = $matches['int'].$t; $parsedTimeSpec["$t"] = $matches['int']; return $completeTimeString; }, $input); if ($time != "") { $finalArray['time'] = $parsedTimeSpec; } if ($trailing != "") { $finalArray['trailing'] = $trailing; } if ($leading != "") { $finalArray['leading'] = $leading; } return $finalArray; } $timeSpecWithLeadingString = getTimeSpec($leadingString, true); $timeSpecWithTrailingString = getTimeSpec($trailingString, false, true); $timeSpecWithBoth = getTimeSpec($both, true, true); $timeSpecWithoutText = getTimeSpec($noText, false, false); print_r($timeSpecWithLeadingString); print_r($timeSpecWithTrailingString); print_r($timeSpecWithBoth); print_r($timeSpecWithoutText);

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.5.30.0110.00622.17
8.5.20.0090.00920.38
8.5.10.0130.00520.23
8.5.00.0180.00620.07
8.4.180.0170.00922.30
8.4.170.0130.00924.01
8.4.160.0110.01323.93
8.4.150.0070.00517.14
8.4.140.0100.01219.57
8.4.130.0140.01018.18
8.4.120.0100.01020.66
8.4.110.0150.00722.59
8.4.100.0030.00717.95
8.4.90.0110.01018.01
8.4.80.0100.00918.04
8.4.70.0040.00817.85
8.4.60.0150.00818.82
8.4.50.0120.01018.13
8.4.40.0180.00419.84
8.4.30.0110.01117.98
8.4.20.0040.00718.08
8.4.10.0100.01019.71
8.3.300.0130.00820.68
8.3.290.0120.01122.63
8.3.280.0170.00520.25
8.3.270.0130.00817.15
8.3.260.0140.00616.92
8.3.250.0120.00719.16
8.3.240.0140.00516.92
8.3.230.0050.00417.01
8.3.220.0050.00517.45
8.3.210.0050.00416.93
8.3.200.0050.00417.08
8.3.190.0100.01017.01
8.3.180.0100.00517.37
8.3.170.0150.00317.22
8.3.160.0060.01216.78
8.3.150.0080.00818.98
8.3.140.0040.00417.18
8.3.130.0070.00416.91
8.3.120.0030.00620.69
8.3.110.0100.01020.94
8.3.100.0090.00624.06
8.3.90.0130.00326.77
8.3.80.0040.00817.97
8.3.70.0200.00318.68
8.3.60.0110.01116.88
8.3.50.0090.01021.27
8.3.40.0060.00919.21
8.3.30.0040.01118.92
8.3.20.0050.00320.46
8.3.10.0080.00020.78
8.3.00.0040.00420.80
8.2.300.0130.00823.96
8.2.290.0080.00720.47
8.2.280.0100.00918.84
8.2.270.0210.00017.24
8.2.260.0040.00420.72
8.2.250.0030.00518.59
8.2.240.0080.00417.49
8.2.230.0000.01022.58
8.2.220.0000.00837.54
8.2.210.0120.00626.77
8.2.200.0090.00018.54
8.2.190.0090.00618.43
8.2.180.0070.01416.88
8.2.170.0040.01122.96
8.2.160.0100.00319.47
8.2.150.0000.00824.18
8.2.140.0030.00524.66
8.2.130.0050.00322.25
8.2.120.0040.00426.35
8.2.110.0090.00021.16
8.2.100.0080.00418.28
8.2.90.0000.00819.47
8.2.80.0080.00017.97
8.2.70.0040.00417.88
8.2.60.0040.00418.16
8.2.50.0030.00618.10
8.2.40.0000.00820.72
8.2.30.0040.00419.37
8.2.20.0030.00618.36
8.2.10.0040.00418.35
8.2.00.0080.00018.11
8.1.340.0150.00818.09
8.1.330.0120.00722.00
8.1.320.0070.00416.62
8.1.310.0030.00718.78
8.1.300.0140.00716.74
8.1.290.0060.00330.84
8.1.280.0160.00325.92
8.1.270.0040.00423.95
8.1.260.0050.00228.09
8.1.250.0000.00828.09
8.1.240.0060.00321.58
8.1.230.0060.00617.89
8.1.220.0040.00418.00
8.1.210.0060.00318.77
8.1.200.0000.00917.60
8.1.190.0040.00417.61
8.1.180.0050.00318.10
8.1.170.0090.00018.96
8.1.160.0030.00522.25
8.1.150.0000.00818.98
8.1.140.0060.00319.66
8.1.130.0000.00717.79
8.1.120.0000.00717.67
8.1.110.0050.00317.72
8.1.100.0000.00817.68
8.1.90.0040.00417.68
8.1.80.0000.00917.71
8.1.70.0040.00417.67
8.1.60.0040.00417.71
8.1.50.0090.00017.76
8.1.40.0000.00917.71
8.1.30.0060.00317.79
8.1.20.0030.00517.83
8.1.10.0000.00917.78
8.1.00.0030.00617.61
8.0.300.0040.00418.77
8.0.290.0040.00417.13
8.0.280.0040.00418.61
8.0.270.0040.00317.35
8.0.260.0030.00617.54
8.0.250.0070.00317.27
8.0.240.0060.00317.34
8.0.230.0000.00717.21
8.0.220.0030.00517.32
8.0.210.0000.00717.38
8.0.200.0030.00317.34
8.0.190.0050.00317.30
8.0.180.0050.00317.16
8.0.170.0030.00617.23
8.0.160.0040.00417.16
8.0.150.0040.00417.19
8.0.140.0040.00417.18
8.0.130.0030.00313.72
8.0.120.0040.00417.34
8.0.110.0040.00417.36
8.0.100.0040.00417.36
8.0.90.0000.00817.17
8.0.80.0180.00317.27
8.0.70.0050.00517.43
8.0.60.0000.00817.19
8.0.50.0030.00517.11
8.0.30.0110.00817.27
8.0.20.0110.00917.52
8.0.10.0030.00517.42
8.0.00.0110.00817.03
7.4.330.0030.00315.13
7.4.320.0000.00817.01
7.4.300.0030.00316.77
7.4.290.0000.00816.87
7.4.280.0000.00916.86
7.4.270.0050.00316.88
7.4.260.0080.00016.87
7.4.250.0040.00416.85
7.4.240.0030.00516.70
7.4.230.0060.00316.99
7.4.220.0100.01017.07
7.4.210.0120.00316.99
7.4.200.0000.00816.97
7.4.160.0080.00816.95
7.4.150.0120.00917.40
7.4.140.0090.00917.86
7.4.130.0120.00616.92
7.4.120.0090.00816.98
7.4.110.0160.00616.87
7.4.100.0100.00716.74
7.4.90.0120.00616.79
7.4.80.0140.00319.39
7.4.70.0140.00316.86
7.4.60.0080.00816.88
7.4.50.0110.00416.83
7.4.40.0080.00816.89
7.4.30.0060.01116.91
7.4.10.0070.01015.43
7.4.00.0060.01215.36
7.3.330.0030.00313.69
7.3.320.0070.00013.51
7.3.310.0000.00716.65
7.3.300.0070.00016.73
7.3.290.0060.01116.69
7.3.280.0110.00616.72
7.3.270.0200.01617.40
7.3.260.0110.00716.83
7.3.250.0090.00816.78
7.3.240.0100.00916.72
7.3.230.0070.01116.82
7.3.210.0090.01216.96
7.3.200.0060.01016.75
7.3.190.0070.01016.73
7.3.180.0130.01016.85
7.3.170.0100.01316.73
7.3.160.0130.00616.77
7.3.130.0070.01115.12
7.3.120.0070.01115.21
7.3.110.0080.00715.20
7.3.100.0050.00815.18
7.3.90.0100.00615.16
7.3.80.0090.00315.30
7.3.70.0080.00515.28
7.3.60.0030.01015.17
7.3.50.0120.00215.23
7.3.40.0030.00815.16
7.3.30.0050.00714.85
7.3.20.0070.00616.73
7.3.10.0060.00916.84
7.3.00.0100.00517.04
7.2.330.0030.01416.87
7.2.320.0070.01016.87
7.2.310.0060.01317.09
7.2.300.0130.01016.92
7.2.290.0100.00716.84
7.2.260.0090.00915.33
7.2.250.0080.01015.38
7.2.240.0070.00815.55
7.2.230.0060.01015.59
7.2.220.0030.01215.41
7.2.210.0030.01215.29
7.2.200.0050.00515.08
7.2.190.0050.01015.35
7.2.180.0050.00715.24
7.2.170.0050.00815.05
7.2.160.0080.00615.39
7.2.150.0050.00717.17
7.2.140.0040.01017.34
7.2.130.0050.01017.12
7.2.120.0050.01017.19
7.2.110.0050.00817.09
7.2.100.0050.01117.15
7.2.90.0030.01117.18
7.2.80.0050.00717.31
7.2.70.0050.00917.20
7.2.60.0050.01017.19
7.2.50.0030.01017.23
7.2.40.0060.00717.10
7.2.30.0060.00717.16
7.2.20.0020.01317.10
7.2.10.0040.01217.05
7.2.00.0070.00817.84
7.1.330.0080.00616.02
7.1.320.0030.01215.96
7.1.310.0080.00416.03
7.1.300.0020.01115.96
7.1.290.0050.00715.73
7.1.280.0070.00615.90
7.1.270.0050.00816.09
7.1.260.0010.01215.89
7.1.250.0020.00915.98
7.1.240.0050.00616.02
7.1.230.0050.00915.98
7.1.220.0070.00215.91
7.1.210.0040.00615.97
7.1.200.0060.00816.08
7.1.190.0090.00416.16
7.1.180.0060.00615.91
7.1.170.0080.00616.01
7.1.160.0020.01016.22
7.1.150.0050.01016.12
7.1.140.0070.00716.08
7.1.130.0050.00916.03
7.1.120.0050.00716.06
7.1.110.0100.00515.98
7.1.100.0050.00816.90
7.1.90.0030.01016.06
7.1.80.0080.00915.94
7.1.70.0050.00916.61
7.1.60.0080.00516.62
7.1.50.0080.00916.20
7.1.40.0090.00316.14
7.1.30.0080.00516.11
7.1.20.0060.00715.96
7.1.10.0050.01115.96
7.1.00.0040.03218.12
7.0.330.0050.00815.50
7.0.320.0040.01115.54
7.0.310.0040.00715.76
7.0.300.0090.00515.45
7.0.290.0050.01015.55
7.0.280.0050.00515.66
7.0.270.0070.00715.64
7.0.260.0070.00915.67
7.0.250.0020.00915.74
7.0.240.0060.01015.80
7.0.230.0050.01015.72
7.0.220.0070.00715.56
7.0.210.0080.00815.56
7.0.200.0050.00815.53
7.0.190.0050.01115.62
7.0.180.0070.00515.73
7.0.170.0030.01015.47
7.0.160.0030.01015.78
7.0.150.0070.00915.70
7.0.140.0050.00815.59
7.0.130.0020.00915.59
7.0.120.0060.00715.74
7.0.110.0260.02017.22
7.0.100.0160.02017.28
7.0.90.0210.02717.33
7.0.80.0190.02317.18
7.0.70.0220.02817.18
7.0.60.0240.02917.09
7.0.50.0260.03217.22
7.0.40.0220.02215.78
7.0.30.0230.03415.99
7.0.20.0260.01815.90
7.0.10.0190.02015.95
7.0.00.0190.03416.06
5.6.400.0070.00514.03
5.6.390.0030.01013.93
5.6.380.0040.00614.13
5.6.370.0030.00913.91
5.6.360.0030.01014.01
5.6.350.0030.01014.27
5.6.340.0000.01313.89
5.6.330.0070.00714.01
5.6.320.0020.01214.10
5.6.310.0050.01214.18
5.6.300.0010.01014.20
5.6.290.0080.00513.99
5.6.280.0060.01014.15
5.6.270.0040.01114.07
5.6.260.0080.02216.31
5.6.250.0060.02616.30
5.6.240.0050.02516.33
5.6.230.0120.02116.49
5.6.220.0050.03616.37
5.6.210.0070.03316.46
5.6.200.0070.03716.41
5.6.190.0090.02316.37
5.6.180.0050.03616.50
5.6.170.0100.02716.28
5.6.160.0090.02516.38
5.6.150.0070.02616.21
5.6.140.0110.02416.43
5.6.130.0100.02916.37
5.6.120.0110.03116.29
5.6.110.0090.02716.24
5.6.100.0100.03316.31
5.6.90.0080.02616.29
5.6.80.0080.01916.27
5.6.70.0080.02216.05
5.6.60.0050.02416.15
5.6.50.0060.02416.08
5.6.40.0090.02216.04
5.6.30.0070.02416.09
5.6.20.0090.02016.10
5.6.10.0020.02616.13
5.6.00.0050.02516.13

preferences:
110.96 ms | 2224 KiB | 5 Q