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', # - '5 days 4 minutes', # - '9w8d7h6m5s', # - '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 https://3v4l.org/FIgNC '5m3s bar', # + '7mon6w5d4h3m2s bazinga!', # + '3 seconds 5 hours 5 minutes jeeey hoe :D damn I should sleep...' # + ]; /* * Replaces (s|m|h|d|w|mon) with strtotime compatible abbreviations * * It *should* allow these: https://gist.github.com/DaveRandom/625fb4bf73112474fb5768a0a300e4e5 * * NOTE: Below regex...uh, specially the (?&str) bit probably sucks... * * @param array $tests * @return array */ function normalizeTimeSpec($tests) { $reg1 = <<<'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 | .+ (*SKIP) ~uix REGEX; $array = []; foreach($tests as $case){ $output = preg_replace_callback ($reg1, function($matches){ if (!isset($matches['int'])) { 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; } return $matches['int'].$t; }, $case); $array[] = $output; } return $array; } /* * Test whether given time string passes regex rules (and show the matches array) * This is mainly for Reminders plugin where we allow trailing (but not leading) strings * * @param array $tests * @return array */ function testTimeSpec($tests){ $finalArray = []; # I saw another solution given by @bwoebi - https://3v4l.org/6BoW1 # However that doesn't fail any longer than "5 months 4 weeks" see ^ # pretty sure these can be improved (but it's late and I can't regex any more now...) $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; } $normalized = normalizeTimeSpec($tests); $output = testTimeSpec(normalizeTimeSpec($tests)); print_r($normalized); 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.3.60.0170.00017.13
8.3.50.0110.00821.39
8.3.40.0110.00419.13
8.3.30.0000.01519.17
8.3.20.0030.00520.50
8.3.10.0000.01019.16
8.3.00.0000.00820.91
8.2.180.0110.00416.75
8.2.170.0070.01122.96
8.2.160.0090.00619.41
8.2.150.0050.00324.18
8.2.140.0030.00524.66
8.2.130.0040.00422.27
8.2.120.0080.00026.35
8.2.110.0070.01122.20
8.2.100.0060.00618.46
8.2.90.0030.00620.20
8.2.80.0040.00418.16
8.2.70.0000.00918.00
8.2.60.0060.00318.34
8.2.50.0040.00418.10
8.2.40.0030.00620.59
8.2.30.0040.00419.50
8.2.20.0040.00418.21
8.2.10.0000.00818.29
8.2.00.0030.00618.09
8.1.280.0110.00725.92
8.1.270.0040.00424.04
8.1.260.0040.00428.09
8.1.250.0040.00428.09
8.1.240.0120.00622.18
8.1.230.0080.00720.91
8.1.220.0000.00817.79
8.1.210.0030.00618.77
8.1.200.0030.00617.60
8.1.190.0000.00817.68
8.1.180.0050.00318.10
8.1.170.0080.00018.94
8.1.160.0000.00922.13
8.1.150.0040.00418.98
8.1.140.0040.00419.74
8.1.130.0040.00417.96
8.1.120.0070.00017.67
8.1.110.0000.00817.71
8.1.100.0040.00417.72
8.1.90.0030.00517.62
8.1.80.0000.00817.71
8.1.70.0040.00417.64
8.1.60.0060.00317.65
8.1.50.0000.00817.84
8.1.40.0060.00317.77
8.1.30.0030.00617.92
8.1.20.0060.00317.90
8.1.10.0000.00817.72
8.1.00.0000.00817.67
8.0.300.0040.00420.05
8.0.290.0000.00817.13
8.0.280.0070.00018.48
8.0.270.0000.00717.38
8.0.260.0030.00317.42
8.0.250.0000.00717.32
8.0.240.0040.00417.21
8.0.230.0050.00317.33
8.0.220.0050.00317.30
8.0.210.0050.00317.34
8.0.200.0030.00317.26
8.0.190.0070.00417.32
8.0.180.0040.00417.34
8.0.170.0000.00817.18
8.0.160.0040.00417.27
8.0.150.0040.00417.17
8.0.140.0000.00717.24
8.0.130.0030.00313.64
8.0.120.0080.00017.31
8.0.110.0030.00517.26
8.0.100.0030.00517.12
8.0.90.0000.00817.30
8.0.80.0090.00917.35
8.0.70.0000.01017.31
8.0.60.0040.00417.28
8.0.50.0020.00517.37
8.0.30.0070.01317.37
8.0.20.0100.01117.44
8.0.10.0060.00317.45
8.0.00.0090.00917.04
7.4.330.0030.00315.23
7.4.320.0040.00417.01
7.4.300.0040.00416.99
7.4.290.0050.00316.92
7.4.280.0000.00816.77
7.4.270.0030.00416.86
7.4.260.0000.00716.86
7.4.250.0080.00016.86
7.4.240.0060.00316.87
7.4.230.0050.00216.82
7.4.220.0090.00917.00
7.4.210.0070.01417.00
7.4.200.0040.00416.79
7.4.160.0150.00616.98
7.4.150.0060.01217.40
7.4.140.0100.00817.86
7.4.130.0100.01116.89
7.4.120.0100.01016.87
7.4.110.0130.01317.11
7.4.100.0140.00316.88
7.4.90.0120.01216.84
7.4.80.0140.00319.39
7.4.70.0100.00716.88
7.4.60.0090.00916.89
7.4.50.0070.01016.76
7.4.40.0100.00716.85
7.4.30.0070.01116.84
7.4.10.0070.01215.49
7.4.00.0060.01315.35
7.3.330.0030.00313.64
7.3.320.0030.00313.69
7.3.310.0040.00416.73
7.3.300.0000.00716.76
7.3.290.0080.00816.66
7.3.280.0090.00916.69
7.3.270.0110.00717.40
7.3.260.0100.00916.86
7.3.250.0080.01016.70
7.3.240.0100.00716.73
7.3.230.0130.00716.92
7.3.210.0080.00816.88
7.3.200.0070.01016.72
7.3.190.0100.00716.61
7.3.180.0170.00416.98
7.3.170.0110.00616.63
7.3.160.0060.01316.65
7.3.130.0080.00814.82
7.3.120.0100.00815.28
7.3.110.0050.01015.04
7.3.100.0050.00915.22
7.3.90.0100.00615.04
7.3.80.0070.00415.01
7.3.70.0100.00615.19
7.3.60.0020.00815.20
7.3.50.0080.00615.20
7.3.40.0080.00515.26
7.3.30.0070.00215.04
7.3.20.0050.00916.87
7.3.10.0030.01117.02
7.3.00.0090.00516.85
7.2.330.0140.00916.94
7.2.320.0060.01216.86
7.2.310.0160.00817.07
7.2.300.0170.00717.02
7.2.290.0070.01017.00
7.2.260.0060.01215.18
7.2.250.0050.01315.47
7.2.240.0120.00615.34
7.2.230.0090.00815.19
7.2.220.0040.00815.31
7.2.210.0050.01015.28
7.2.200.0030.01415.19
7.2.190.0030.01115.26
7.2.180.0050.00815.34
7.2.170.0050.00815.35
7.2.160.0030.01015.51
7.2.150.0070.00717.31
7.2.140.0090.00617.16
7.2.130.0040.01317.23
7.2.120.0070.00817.28
7.2.110.0050.00817.25
7.2.100.0080.00517.17
7.2.90.0050.00917.24
7.2.80.0140.00517.03
7.2.70.0040.01017.28
7.2.60.0040.01117.28
7.2.50.0050.01017.13
7.2.40.0040.01217.15
7.2.30.0050.01017.12
7.2.20.0060.01217.15
7.2.10.0030.01417.12
7.2.00.0050.00818.16
7.1.330.0070.00716.23
7.1.320.0050.01115.89
7.1.310.0050.01015.99
7.1.300.0000.01315.98
7.1.290.0050.00915.96
7.1.280.0050.00715.92
7.1.270.0050.00916.16
7.1.260.0030.00816.04
7.1.250.0090.00716.03
7.1.240.0000.01215.77
7.1.230.0060.00316.05
7.1.220.0030.01016.02
7.1.210.0090.00915.88
7.1.200.0100.00115.84
7.1.190.0100.00615.89
7.1.180.0060.00616.07
7.1.170.0080.00616.02
7.1.160.0080.00915.77
7.1.150.0060.00616.02
7.1.140.0030.01516.24
7.1.130.0030.01116.02
7.1.120.0030.00616.17
7.1.110.0070.00716.23
7.1.100.0000.01816.02
7.1.90.0110.00415.82
7.1.80.0030.00616.13
7.1.70.0080.00716.75
7.1.60.0040.00816.96
7.1.50.0000.01116.04
7.1.40.0030.00916.20
7.1.30.0060.00615.92
7.1.20.0090.00616.11
7.1.10.0000.01416.13
7.1.00.0020.04519.20
7.0.330.0070.00715.69
7.0.320.0070.00715.50
7.0.310.0050.00515.57
7.0.300.0090.00615.81
7.0.290.0090.00015.66
7.0.280.0060.00915.57
7.0.270.0060.00315.76
7.0.260.0060.00915.66
7.0.250.0000.01015.75
7.0.240.0030.00915.85
7.0.230.0070.01015.68
7.0.220.0100.00315.88
7.0.210.0040.00715.75
7.0.200.0240.00715.49
7.0.190.0070.00715.55
7.0.180.0120.00415.69
7.0.170.0070.00715.77
7.0.160.0030.00915.39
7.0.150.0070.00715.84
7.0.140.0000.01115.73
7.0.130.0070.00715.75
7.0.120.0030.00615.50
7.0.110.0190.03718.08
7.0.100.0100.04018.09
7.0.90.0080.04217.94
7.0.80.0160.03518.10
7.0.70.0230.03318.01
7.0.60.0130.03818.03
7.0.50.0190.03418.07
7.0.40.0210.03216.96
7.0.30.0200.03817.13
7.0.20.0120.03517.03
7.0.10.0170.03116.95
7.0.00.0230.02517.10
5.6.400.0000.01614.59
5.6.390.0000.01414.30
5.6.380.0030.01214.77
5.6.370.0120.00314.45
5.6.360.0160.00014.71
5.6.350.0030.00914.63
5.6.340.0040.01514.78
5.6.330.0040.00814.63
5.6.320.0060.00614.90
5.6.310.0060.00914.88
5.6.300.0110.00014.58
5.6.290.0060.00914.84
5.6.280.0060.00914.60
5.6.270.0000.01014.53
5.6.260.0120.02818.00
5.6.250.0070.03217.70
5.6.240.0070.03517.63
5.6.230.0110.03317.63
5.6.220.0030.03717.81
5.6.210.0120.03517.71
5.6.200.0080.03017.91
5.6.190.0050.03417.84
5.6.180.0080.03817.66
5.6.170.0080.03217.71
5.6.160.0100.03017.71
5.6.150.0050.03617.64
5.6.140.0110.03017.82
5.6.130.0050.03617.86
5.6.120.0070.04017.85
5.6.110.0070.05017.57
5.6.100.0050.04717.73
5.6.90.0090.03517.81
5.6.80.0110.03017.36
5.6.70.0070.03517.55
5.6.60.0060.03517.43
5.6.50.0130.02517.35
5.6.40.0080.03217.30
5.6.30.0150.02317.40
5.6.20.0100.02817.44
5.6.10.0100.04717.36
5.6.00.0110.03817.45

preferences:
46.31 ms | 401 KiB | 5 Q