3v4l.org

run code in 300+ PHP versions simultaneously
<?php $tests = [ 'bar 3 m foo', // - '5s 4m', // - '5s 10mins 4 days', // - '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; } print_r(normalizeTimeSpec($tests)); print_r(testTimeSpec(normalizeTimeSpec($tests)));

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.130.0130.00718.08
8.4.120.0030.00720.59
8.4.110.0080.00422.49
8.4.100.0050.00917.95
8.4.90.0040.00520.71
8.4.80.0130.00819.01
8.4.70.0140.00918.98
8.4.60.0120.00918.93
8.4.50.0050.00418.81
8.4.40.0130.00720.03
8.4.30.0100.01018.01
8.4.20.0140.00719.70
8.4.10.0090.00019.52
8.3.260.0090.01116.79
8.3.250.0060.00318.83
8.3.240.0110.00716.71
8.3.230.0130.00816.63
8.3.220.0090.01019.13
8.3.210.0140.00717.18
8.3.200.0060.00316.98
8.3.190.0070.00817.61
8.3.180.0090.01119.15
8.3.170.0100.01018.97
8.3.160.0100.01016.90
8.3.150.0040.00418.79
8.3.140.0060.00316.97
8.3.130.0000.00816.75
8.3.120.0040.00419.20
8.3.110.0060.00920.94
8.3.100.0090.00024.06
8.3.90.0080.00026.77
8.3.80.0060.00317.13
8.3.70.0110.01117.00
8.3.60.0110.01117.00
8.3.50.0100.01221.27
8.3.40.0100.01019.04
8.3.30.0000.01519.21
8.3.20.0050.00320.31
8.3.10.0080.00020.88
8.3.00.0060.00322.34
8.2.290.0090.01120.60
8.2.280.0090.01020.63
8.2.270.0150.00317.32
8.2.260.0070.01118.38
8.2.250.0080.00018.63
8.2.240.0090.00018.99
8.2.230.0050.00322.58
8.2.220.0030.00637.54
8.2.210.0200.00026.77
8.2.200.0060.00316.75
8.2.190.0160.00617.13
8.2.180.0040.01725.92
8.2.170.0120.00319.37
8.2.160.0060.00922.96
8.2.150.0060.00324.18
8.2.140.0030.00624.66
8.2.130.0040.00422.37
8.2.120.0040.00426.35
8.2.110.0040.00721.17
8.2.100.0040.00818.28
8.2.90.0090.00018.34
8.2.80.0000.00918.16
8.2.70.0000.01018.16
8.2.60.0030.00618.16
8.2.50.0000.00818.10
8.2.40.0040.00422.13
8.2.30.0040.00419.37
8.2.20.0040.00418.33
8.2.10.0000.00818.28
8.2.00.0000.00818.07
8.1.330.0120.00622.25
8.1.320.0100.00918.29
8.1.310.0110.00416.71
8.1.300.0070.00318.13
8.1.290.0090.00018.88
8.1.280.0060.01225.92
8.1.270.0060.00323.80
8.1.260.0050.00328.09
8.1.250.0080.00028.09
8.1.240.0140.00020.97
8.1.230.0060.00621.10
8.1.220.0000.00821.15
8.1.210.0050.00318.92
8.1.200.0070.00417.73
8.1.190.0040.00417.73
8.1.180.0040.00418.10
8.1.170.0040.00419.09
8.1.160.0040.00422.11
8.1.150.0030.00619.05
8.1.140.0050.00319.74
8.1.130.0040.00417.82
8.1.120.0070.00017.70
8.1.110.0000.00917.70
8.1.100.0040.00417.58
8.1.90.0100.00017.72
8.1.80.0040.00417.70
8.1.70.0000.00717.69
8.1.60.0030.00617.69
8.1.50.0050.00317.76
8.1.40.0030.00517.76
8.1.30.0000.00817.78
8.1.20.0040.00417.91
8.1.10.0050.00317.70
8.1.00.0060.00317.60
8.0.300.0050.00320.05
8.0.290.0080.00017.00
8.0.280.0040.00418.45
8.0.270.0040.00417.24
8.0.260.0000.00717.36
8.0.250.0040.00417.25
8.0.240.0030.00517.32
8.0.230.0040.00417.30
8.0.220.0040.00417.15
8.0.210.0000.00717.27
8.0.200.0070.00017.32
8.0.190.0040.00417.18
8.0.180.0070.00517.19
8.0.170.0040.00417.19
8.0.160.0030.00517.24
8.0.150.0040.00417.20
8.0.140.0030.00517.18
8.0.130.0000.00613.70
8.0.120.0040.00417.27
8.0.110.0030.00617.29
8.0.100.0080.00017.17
8.0.90.0040.00417.29
8.0.80.0100.00617.25
8.0.70.0070.00317.18
8.0.60.0030.00717.36
8.0.50.0080.00017.31
8.0.30.0090.00917.48
8.0.20.0170.00317.40
8.0.10.0050.00217.38
8.0.00.0110.00717.30
7.4.330.0020.00515.08
7.4.320.0070.00016.95
7.4.300.0100.00016.86
7.4.290.0090.00016.85
7.4.280.0000.00816.85
7.4.270.0040.00416.85
7.4.260.0000.00816.75
7.4.250.0040.00416.80
7.4.240.0100.00016.93
7.4.230.0000.00716.98
7.4.220.0060.00916.89
7.4.210.0090.00816.88
7.4.200.0030.00516.60
7.4.160.0110.00716.84
7.4.150.0030.01517.40
7.4.140.0120.00617.86
7.4.130.0060.01116.87
7.4.120.0080.00916.90
7.4.110.0130.01316.75
7.4.100.0060.01917.00
7.4.90.0060.01216.79
7.4.80.0160.00619.39
7.4.70.0070.01017.06
7.4.60.0120.00616.94
7.4.50.0060.01016.73
7.4.40.0110.00716.71
7.4.30.0150.00916.73
7.4.00.0080.00815.19
7.3.330.0000.00513.68
7.3.320.0060.00013.45
7.3.310.0040.00316.81
7.3.300.0000.00916.72
7.3.290.0040.00416.60
7.3.280.0090.00816.67
7.3.270.0090.00917.40
7.3.260.0050.01316.89
7.3.250.0090.00916.78
7.3.240.0120.01116.68
7.3.230.0120.00616.69
7.3.210.0100.00716.80
7.3.200.0060.01216.68
7.3.190.0110.00616.67
7.3.180.0070.01016.75
7.3.170.0040.01916.79
7.3.160.0000.01716.68
7.3.120.0030.01615.09
7.3.110.0070.01115.04
7.3.100.0060.00914.79
7.3.90.0060.00915.32
7.3.80.0030.00715.37
7.3.70.0130.00315.26
7.3.60.0030.01114.82
7.3.50.0070.01015.24
7.3.40.0000.01014.96
7.3.30.0070.00715.21
7.3.20.0000.01117.04
7.3.10.0040.00816.98
7.3.00.0070.00717.07
7.2.330.0140.00516.99
7.2.320.0100.00716.92
7.2.310.0070.01317.07
7.2.300.0090.00916.86
7.2.290.0080.00816.89
7.2.250.0080.01215.34
7.2.240.0140.00715.41
7.2.230.0060.00915.21
7.2.220.0090.00015.05
7.2.210.0100.00715.09
7.2.200.0030.00615.30
7.2.190.0100.00315.39
7.2.180.0030.00715.38
7.2.170.0040.00415.13
7.1.330.0130.00015.79
7.1.320.0000.00815.95
7.1.310.0030.00515.91
7.1.300.0000.00916.09
7.1.290.0030.00715.77
7.1.280.0060.00616.01
7.1.270.0040.00416.08
7.1.260.0030.01015.91
7.1.200.0030.01016.06
7.1.70.0040.00717.61
7.1.60.0040.00817.53
7.1.00.0070.07322.50
7.0.200.0030.00915.04
7.0.110.0270.06320.32
7.0.100.0270.05720.42
7.0.90.0330.05720.32
7.0.80.0370.06020.32
7.0.70.0330.06020.22
7.0.60.0330.05320.27
7.0.50.0300.06020.34
7.0.40.0400.06320.31
7.0.30.0470.04320.23
7.0.20.0370.05720.21
7.0.10.0400.07020.37
7.0.00.0370.05320.26
5.6.260.0070.05720.87
5.6.250.0070.06021.10
5.6.240.0130.05320.95
5.6.230.0170.06320.95
5.6.220.0000.06720.79
5.6.210.0070.06320.96
5.6.200.0100.07021.01
5.6.190.0030.08021.06
5.6.180.0070.06321.11
5.6.170.0030.06721.06
5.6.160.0130.05720.84
5.6.150.0130.06021.01
5.6.140.0200.05021.01
5.6.130.0130.05021.05
5.6.120.0030.06321.05
5.6.110.0130.05320.86
5.6.100.0130.05320.94
5.6.90.0130.05020.80
5.6.80.0100.05320.44
5.6.70.0130.05320.19
5.6.60.0130.05020.38
5.6.50.0070.05720.20
5.6.40.0100.05320.24
5.6.30.0130.05020.19
5.6.20.0170.05020.20
5.6.10.0070.06020.23
5.6.00.0100.05720.18

preferences:
123.29 ms | 403 KiB | 5 Q