3v4l.org

run code in 300+ PHP versions simultaneously
<?php $tests = [ 'bar 3 m foo', // - 'bass drop 2 d bare', // - '2 3 m foo foo', // - '1 222 4 d baz', // - '5d 4h 3m 2s', // - '2 d 3 m baz', // + '5d 4h 3m 2s foo', // + '2 s foo', // + '222 h baz bar', // + '1 mon foo', // + mon for month? '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 * * ps. (?&int) is there so it doesn't replace the 's' in 'months' etc. * * @param array $tests * @return array */ function normalizeTimeSpec($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)){ $finalArray[] = $matches['time'].$matches['string']; } } return $finalArray; } //$output = normalizeTimeSpec($tests); $output = testTimeSpec(normalizeTimeSpec($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.0050.01122.08
8.5.20.0110.00719.94
8.5.10.0030.00620.08
8.5.00.0050.00320.38
8.4.180.0120.01120.20
8.4.170.0130.00822.21
8.4.160.0120.01022.18
8.4.150.0090.00517.05
8.4.140.0120.00917.99
8.4.130.0140.00719.79
8.4.120.0100.01020.58
8.4.110.0070.00518.68
8.4.100.0110.01117.94
8.4.90.0130.00818.61
8.4.80.0130.00818.02
8.4.70.0040.00418.18
8.4.60.0100.01117.87
8.4.50.0130.01019.89
8.4.40.0070.01419.93
8.4.30.0140.00717.97
8.4.20.0030.00618.13
8.4.10.0100.00719.70
8.3.300.0130.00920.50
8.3.290.0180.00420.83
8.3.280.0090.01218.75
8.3.270.0090.01216.93
8.3.260.0100.01017.10
8.3.250.0150.00419.20
8.3.240.0120.00817.29
8.3.230.0110.00816.90
8.3.220.0090.01117.35
8.3.210.0040.00417.08
8.3.200.0110.00817.09
8.3.190.0060.00517.03
8.3.180.0100.00917.06
8.3.170.0070.01416.98
8.3.160.0070.01117.14
8.3.150.0090.00917.22
8.3.140.0030.01218.75
8.3.130.0060.00917.08
8.3.120.0160.00319.27
8.3.110.0060.00320.94
8.3.100.0150.00624.06
8.3.90.0040.00426.77
8.3.80.0000.01018.93
8.3.70.0060.00917.00
8.3.60.0120.00317.09
8.3.50.0220.01222.24
8.3.40.0040.01119.27
8.3.30.0070.00719.18
8.3.20.0050.00320.29
8.3.10.0080.00020.86
8.3.00.0040.00420.70
8.2.300.0100.01123.97
8.2.290.0100.00920.49
8.2.280.0070.01518.85
8.2.270.0060.01217.18
8.2.260.0070.01317.04
8.2.250.0080.00016.96
8.2.240.0040.00417.21
8.2.230.0090.00322.58
8.2.220.0040.00437.54
8.2.210.0140.00726.77
8.2.200.0030.00616.88
8.2.190.0170.00717.10
8.2.180.0160.00318.68
8.2.170.0070.01422.96
8.2.160.0070.00719.59
8.2.150.0030.00624.18
8.2.140.0030.01024.66
8.2.130.0080.00022.09
8.2.120.0040.00426.35
8.2.110.0030.00719.32
8.2.100.0040.00818.28
8.2.90.0000.00918.34
8.2.80.0000.00918.05
8.2.70.0000.00818.15
8.2.60.0040.00418.28
8.2.50.0090.00019.73
8.2.40.0050.00320.50
8.2.30.0030.00619.46
8.2.20.0040.00418.35
8.2.10.0040.00418.19
8.2.00.0060.00318.01
8.1.340.0110.00923.83
8.1.330.0150.00422.15
8.1.320.0110.00918.03
8.1.310.0040.00416.96
8.1.300.0130.00720.23
8.1.290.0040.00830.84
8.1.280.0110.01125.92
8.1.270.0040.00423.96
8.1.260.0050.00328.09
8.1.250.0040.00428.09
8.1.240.0060.00322.73
8.1.230.0080.00320.97
8.1.220.0080.00017.89
8.1.210.0050.00318.97
8.1.200.0080.00017.60
8.1.190.0000.00917.60
8.1.180.0040.00418.10
8.1.170.0000.00918.87
8.1.160.0000.00822.24
8.1.150.0040.00419.04
8.1.140.0000.00819.80
8.1.130.0000.00717.77
8.1.120.0050.00317.59
8.1.110.0030.00517.57
8.1.100.0040.00417.52
8.1.90.0070.00417.69
8.1.80.0020.00517.67
8.1.70.0060.00317.61
8.1.60.0040.00417.75
8.1.50.0030.00617.63
8.1.40.0050.00317.79
8.1.30.0040.00417.86
8.1.20.0040.00417.77
8.1.10.0000.00817.78
8.1.00.0040.00417.59
8.0.300.0080.00020.03
8.0.290.0080.00017.00
8.0.280.0000.00718.54
8.0.270.0040.00417.29
8.0.260.0070.00017.50
8.0.250.0030.00417.35
8.0.240.0000.00817.31
8.0.230.0070.00017.21
8.0.220.0070.00017.35
8.0.210.0000.00817.27
8.0.200.0030.00317.19
8.0.190.0040.00417.30
8.0.180.0030.00617.27
8.0.170.0030.00517.18
8.0.160.0040.00417.13
8.0.150.0040.00417.12
8.0.140.0040.00417.11
8.0.130.0060.00013.70
8.0.120.0000.00817.23
8.0.110.0040.00417.22
8.0.100.0000.00717.13
8.0.90.0080.00017.17
8.0.80.0160.00617.36
8.0.70.0050.00517.09
8.0.60.0040.00417.27
8.0.50.0080.00017.19
8.0.30.0050.01317.29
8.0.20.0110.01117.40
8.0.10.0070.00017.36
8.0.00.0140.00316.97
7.4.330.0000.00615.13
7.4.320.0070.00016.90
7.4.300.0000.00716.80
7.4.290.0050.00316.94
7.4.280.0000.00716.83
7.4.270.0040.00416.96
7.4.260.0000.00716.94
7.4.250.0040.00416.72
7.4.240.0030.00516.75
7.4.230.0030.00416.74
7.4.220.0130.00316.86
7.4.210.0050.00916.95
7.4.200.0040.00416.77
7.4.160.0040.01216.83
7.4.150.0110.01417.40
7.4.140.0140.00417.86
7.4.130.0100.00816.82
7.4.120.0070.01116.89
7.4.110.0080.00916.73
7.4.100.0100.01616.97
7.4.90.0130.00616.76
7.4.80.0110.00519.39
7.4.70.0080.00816.85
7.4.60.0080.00816.79
7.4.50.0060.01016.77
7.4.40.0060.01116.81
7.4.30.0040.01917.04
7.4.00.0110.00715.10
7.3.330.0050.00013.63
7.3.320.0030.00313.75
7.3.310.0070.00016.56
7.3.300.0040.00416.76
7.3.290.0000.00716.66
7.3.280.0100.00916.64
7.3.270.0120.00617.40
7.3.260.0100.00716.64
7.3.250.0100.00916.74
7.3.240.0100.00916.70
7.3.230.0110.00716.92
7.3.210.0080.00916.67
7.3.200.0030.01516.79
7.3.190.0070.01716.81
7.3.180.0110.00816.70
7.3.170.0090.00916.77
7.3.160.0030.01416.86
7.2.330.0030.01417.00
7.2.320.0060.01216.93
7.2.310.0130.00617.15
7.2.300.0150.00616.73
7.2.290.0030.01416.87
7.2.110.0090.00616.84
7.2.60.0030.01017.04
7.1.200.0070.00715.86
7.1.70.0100.00317.42
7.1.60.0030.00917.23
7.1.00.0070.07322.47
7.0.200.0340.00315.09
7.0.110.0030.06320.26
7.0.100.0130.05320.27
7.0.90.0100.05720.23
7.0.80.0100.06320.28
7.0.70.0270.06320.35
7.0.60.0370.05720.38
7.0.50.0400.05320.32
7.0.41.3330.05320.30
7.0.30.0600.04720.44
7.0.20.0430.05320.32
7.0.10.0370.05320.39
7.0.00.0300.06020.39
5.6.260.0100.05721.12
5.6.250.0000.06721.10
5.6.240.0130.07721.11
5.6.230.0100.06720.87
5.6.220.0100.06020.83
5.6.210.0130.05321.04
5.6.200.0130.05721.05
5.6.190.0130.05721.04
5.6.180.0100.05320.96
5.6.170.0130.06721.03
5.6.160.0000.06720.88
5.6.150.0170.06021.05
5.6.140.0170.05320.82
5.6.130.0030.07320.87
5.6.120.0130.05720.94
5.6.110.0000.07020.84
5.6.100.0230.04720.99
5.6.90.0070.05720.93
5.6.80.0100.06020.27
5.6.70.0100.05720.41
5.6.60.0130.07020.47
5.6.50.0100.05320.33
5.6.40.0070.05320.16
5.6.30.0130.05320.37
5.6.20.0030.06320.38
5.6.10.0130.05320.13
5.6.00.0170.04720.41

preferences:
55.22 ms | 1559 KiB | 5 Q