3v4l.org

run code in 300+ PHP versions simultaneously
<?php $tests = [ 'bar 3 m foo -', '2 s foo +', '222 h baz bar +', 'bass drop 2 d bare -', '2 3 m foo foo -', '1 222 4 d baz -', '2 d 3 m baz +', '5d 4h 3m 2s foo +', '5d 4h 3m 2s', '1 mon foo', '1w bar', '1 month baz', '2 months foobar', '4 months 2 months foo' //repeating same string is allowed by strtotime, though it sums up ]; /* * Replaces (s|m|h|d|w|mon) with strtotime compatible abbreviations * @param array $tests * @return array */ function normaliseTimeSpec($tests) { $reg1 = "/ (?<int> (?:\G|(?!\n)) \s*\b \d{1,5} \s* )\K (?<time> (?: s|m(on)?|h|d|w)\b ) /uix"; $array = []; foreach($tests as $case){ $out = preg_replace_callback ($reg1, function($matches){ 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; } return $t; }, $case); $array[] = $out; } return $array; } /* * Test whether given time string passes regex rules & match * @param array $tests * @return array */ function testTimeSpec($tests){ $finalArray = []; $regex = <<<'REGEX' /(?(DEFINE) (?<int> (\s*\b)? (\d{1,5})? (\s*)? ) (?<timepart> (?&int) ( s(ec(ond)?s?)? | m(in(ute)?s?|onths?)? | h(rs?|ours?)? | d(ays?)? | w(eeks?)? ) \b ) ) ^(?<time> (?:(?&timepart)(*SKIP).)+ ) (?<string>.+)$ /uix REGEX; foreach($tests as $case){ if(preg_match($regex, $case, $matches)){ $final[] = $matches['time'].$matches['string']; } } return $final; } $output = testTimeSpec(normaliseTimeSpec($tests)); print_r($output);

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.03
8.5.20.0110.00620.23
8.5.10.0090.00220.19
8.5.00.0150.00820.44
8.4.180.0130.01019.98
8.4.170.0080.01520.74
8.4.160.0090.01324.05
8.4.150.0060.00717.16
8.4.140.0120.01017.82
8.4.130.0100.00718.77
8.4.120.0090.00320.72
8.4.110.0120.01018.92
8.4.100.0110.00819.05
8.4.90.0100.01022.52
8.4.80.0130.00718.97
8.4.70.0130.00719.00
8.4.60.0130.00918.59
8.4.50.0140.00918.84
8.4.40.0130.00719.98
8.4.30.0170.00317.86
8.4.20.0100.00319.76
8.4.10.0030.00619.68
8.3.300.0140.00920.95
8.3.290.0090.01220.88
8.3.280.0080.01218.69
8.3.270.0120.00817.13
8.3.260.0130.00716.73
8.3.250.0130.00517.26
8.3.240.0100.00919.13
8.3.230.0080.00517.22
8.3.220.0090.01018.87
8.3.210.0070.01216.82
8.3.200.0060.00317.19
8.3.190.0060.00917.65
8.3.180.0130.00619.34
8.3.170.0110.00717.07
8.3.160.0140.00417.27
8.3.150.0060.00919.20
8.3.140.0000.00819.05
8.3.130.0060.00318.86
8.3.120.0060.00319.13
8.3.110.0050.00520.94
8.3.100.0150.00324.06
8.3.90.0060.00326.77
8.3.80.0060.00318.89
8.3.70.0090.00617.13
8.3.60.0120.00316.88
8.3.50.0100.01121.27
8.3.40.0090.00619.08
8.3.30.0060.00919.12
8.3.20.0030.00520.34
8.3.10.0030.00620.93
8.3.00.0050.00320.71
8.2.300.0100.01022.37
8.2.290.0120.00718.96
8.2.280.0130.00618.49
8.2.270.0110.00818.59
8.2.260.0100.01016.85
8.2.250.0040.00418.78
8.2.240.0100.00718.98
8.2.230.0060.00322.58
8.2.220.0060.00337.54
8.2.210.0190.00026.77
8.2.200.0000.00918.54
8.2.190.0160.01017.13
8.2.180.0140.00418.79
8.2.170.0040.01122.96
8.2.160.0110.00319.52
8.2.150.0040.00424.18
8.2.140.0040.00424.66
8.2.130.0030.00522.25
8.2.120.0030.00626.35
8.2.110.0030.00620.65
8.2.100.0080.00618.13
8.2.90.0000.00918.13
8.2.80.0030.00517.97
8.2.70.0070.00318.18
8.2.60.0050.00318.28
8.2.50.0060.00318.10
8.2.40.0080.00022.28
8.2.30.0000.00819.54
8.2.20.0060.00318.16
8.2.10.0050.00318.30
8.2.00.0000.00818.02
8.1.340.0160.00521.70
8.1.330.0090.01116.43
8.1.320.0130.00616.45
8.1.310.0060.00316.88
8.1.300.0060.00918.49
8.1.290.0060.00330.84
8.1.280.0060.01625.92
8.1.270.0090.00023.92
8.1.260.0080.00028.09
8.1.250.0000.00828.09
8.1.240.0070.00324.01
8.1.230.0080.00819.13
8.1.220.0080.00017.91
8.1.210.0000.00818.77
8.1.200.0030.00617.60
8.1.190.0090.00017.73
8.1.180.0040.00418.10
8.1.170.0040.00418.96
8.1.160.0000.00722.21
8.1.150.0060.00319.00
8.1.140.0040.00419.73
8.1.130.0000.00717.93
8.1.120.0040.00417.59
8.1.110.0060.00317.66
8.1.100.0030.00617.57
8.1.90.0000.00917.58
8.1.80.0040.00417.72
8.1.70.0000.00817.57
8.1.60.0000.00817.80
8.1.50.0040.00417.76
8.1.40.0060.00317.78
8.1.30.0040.00417.86
8.1.20.0060.00317.90
8.1.10.0060.00317.70
8.1.00.0030.00617.65
8.0.300.0000.00919.90
8.0.290.0080.00317.00
8.0.280.0000.00718.54
8.0.270.0070.00317.27
8.0.260.0000.00717.50
8.0.250.0040.00417.33
8.0.240.0000.00717.22
8.0.230.0030.00617.30
8.0.220.0000.00817.28
8.0.210.0050.00217.16
8.0.200.0030.00317.32
8.0.190.0000.00817.19
8.0.180.0040.00717.21
8.0.170.0030.00617.30
8.0.160.0070.00017.23
8.0.150.0030.00517.19
8.0.140.0020.00517.22
8.0.130.0030.00313.62
8.0.120.0040.00417.30
8.0.110.0000.00817.26
8.0.100.0040.00417.30
8.0.90.0040.00417.33
8.0.80.0090.00917.19
8.0.70.0050.00517.19
8.0.60.0000.00717.34
8.0.50.0000.00817.14
8.0.30.0110.00817.48
8.0.20.0070.01517.44
8.0.10.0060.00317.47
8.0.00.0120.01217.30
7.4.330.0000.00615.09
7.4.320.0030.00516.95
7.4.300.0000.00816.86
7.4.290.0030.00316.79
7.4.280.0040.00416.84
7.4.270.0050.00316.89
7.4.260.0000.00816.97
7.4.250.0040.00416.81
7.4.240.0000.00816.77
7.4.230.0070.00016.73
7.4.220.0130.00317.01
7.4.210.0100.00716.75
7.4.200.0050.00216.97
7.4.160.0100.00816.71
7.4.150.0080.01617.40
7.4.140.0100.01017.86
7.4.130.0050.01216.99
7.4.120.0070.01216.83
7.4.110.0120.00616.88
7.4.100.0130.00716.86
7.4.90.0030.01516.80
7.4.80.0120.01219.39
7.4.70.0150.00316.73
7.4.60.0060.01216.80
7.4.50.0030.01416.71
7.4.40.0080.00816.84
7.4.30.0110.01116.80
7.4.00.0070.01015.43
7.3.330.0000.00613.51
7.3.320.0050.00013.61
7.3.310.0000.00716.81
7.3.300.0070.00016.75
7.3.290.0060.01216.68
7.3.280.0100.00916.66
7.3.270.0060.01217.40
7.3.260.0130.00416.84
7.3.250.0120.00616.69
7.3.240.0090.01116.86
7.3.230.0060.01016.80
7.3.210.0130.01016.72
7.3.200.0110.00616.80
7.3.190.0100.00616.86
7.3.180.0040.01316.83
7.3.170.0130.00616.84
7.3.160.0060.02016.86
7.2.330.0090.00916.91
7.2.320.0130.00317.00
7.2.310.0040.01616.83
7.2.300.0150.00616.94
7.2.290.0070.01017.04
7.2.00.0070.01719.84
7.1.70.0040.00417.40
7.1.60.0090.01317.32
7.1.00.0030.07722.36
7.0.200.0370.00715.17
7.0.110.0270.07720.34
7.0.100.0430.05020.32
7.0.90.0300.05720.30
7.0.80.9200.06020.38
7.0.70.0270.06020.34
7.0.60.0300.06020.27
7.0.50.0430.04720.38
7.0.40.0230.05720.18
7.0.30.0370.04720.38
7.0.20.0270.05720.35
7.0.10.0270.06020.34
7.0.00.0230.06020.39
5.6.260.0000.06721.08
5.6.250.0100.05720.89
5.6.240.0030.06320.85
5.6.230.0070.06321.08
5.6.220.0030.06321.10
5.6.210.0130.05320.70
5.6.200.0130.05721.09
5.6.190.0130.06320.82
5.6.180.0030.06020.86
5.6.170.0130.05020.94
5.6.160.0100.05321.02
5.6.150.0130.05321.11
5.6.140.0130.05321.00
5.6.130.0100.05321.01
5.6.120.0170.05021.04
5.6.110.0100.05721.02
5.6.100.0030.06320.85
5.6.90.0100.06020.86
5.6.80.0200.04020.38
5.6.70.0070.05320.39
5.6.60.0170.07320.42
5.6.50.0070.05720.23
5.6.40.0030.06020.41
5.6.30.0200.06320.17
5.6.20.0170.06020.23
5.6.10.0170.05020.43
5.6.00.0070.05320.18

preferences:
51.02 ms | 1550 KiB | 5 Q