3v4l.org

run code in 300+ PHP versions simultaneously
<?php $cases = [ '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' ]; function test($cases) { $reg1 = "/ (?<int> (?:\G|(?!\n)) \s*\b \d{1,5} \s* )\K (?<time>(?: s|m(on)?|h|d|w)\b)/uix"; $array = $final = []; foreach($cases as $cas){ $out = preg_replace_callback ($reg1, function($matches){ switch($matches['time']){ case 's': $m = 'sec'; break; case 'm': $m = 'min'; break; case 'h': $m = 'hr'; break; case 'd': $m = 'day'; break; case 'w': $m = 'week'; break; case 'mon': $m = 'month'; break; } return $m; }, $cas); $array[] = $out; $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; if(preg_match($regex,$out,$matches)){ $final[] = $matches['time'].$matches['string']; } } return $final; } $output = test($cases); 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.0070.01021.93
8.5.20.0120.00820.39
8.5.10.0050.00620.42
8.5.00.0160.01020.23
8.4.180.0170.00720.13
8.4.170.0060.00520.75
8.4.160.0150.00724.10
8.4.150.0090.00417.14
8.4.140.0150.00718.03
8.4.130.0080.01418.74
8.4.120.0060.00320.80
8.4.110.0090.01120.80
8.4.100.0140.00718.80
8.4.90.0130.00520.67
8.4.80.0170.00419.07
8.4.70.0150.00718.93
8.4.60.0090.01118.83
8.4.50.0070.00218.91
8.4.40.0040.00419.96
8.4.30.0060.01318.02
8.4.20.0180.00417.94
8.4.10.0070.00319.87
8.3.300.0120.01021.02
8.3.290.0140.00620.94
8.3.280.0160.00718.61
8.3.270.0090.01217.23
8.3.260.0140.00617.10
8.3.250.0100.01017.48
8.3.240.0050.00316.92
8.3.230.0130.00617.04
8.3.220.0040.00519.00
8.3.210.0090.01116.91
8.3.200.0060.00317.09
8.3.190.0120.00717.40
8.3.180.0110.00418.82
8.3.170.0140.00717.21
8.3.160.0200.00017.38
8.3.150.0000.00717.43
8.3.140.0080.01121.05
8.3.130.0070.00717.14
8.3.120.0040.00419.30
8.3.110.0030.00620.94
8.3.100.0130.00624.06
8.3.90.0050.00526.77
8.3.80.0030.00618.80
8.3.70.0160.00716.88
8.3.60.0090.00617.25
8.3.50.0230.00321.33
8.3.40.0040.01219.13
8.3.30.0090.00619.17
8.3.20.0040.00420.29
8.3.10.0080.00021.10
8.3.00.0080.00020.77
8.2.300.0070.00624.09
8.2.290.0100.00920.73
8.2.280.0130.00818.67
8.2.270.0160.00316.88
8.2.260.0040.00416.66
8.2.250.0080.00016.99
8.2.240.0030.00617.30
8.2.230.0060.00322.58
8.2.220.0060.00337.54
8.2.210.0000.01426.77
8.2.200.0030.00618.41
8.2.190.0070.01416.88
8.2.180.0140.00718.79
8.2.170.0040.01122.96
8.2.160.0160.00619.54
8.2.150.0000.00824.18
8.2.140.0080.00024.66
8.2.130.0000.00722.42
8.2.120.0080.00026.35
8.2.110.0040.00720.41
8.2.100.0130.00018.28
8.2.90.0050.00318.13
8.2.80.0040.00418.18
8.2.70.0030.00618.13
8.2.60.0000.00818.15
8.2.50.0080.00018.10
8.2.40.0040.00422.21
8.2.30.0030.00519.50
8.2.20.0080.00018.30
8.2.10.0020.00518.38
8.2.00.0080.00018.16
8.1.340.0120.00818.07
8.1.330.0140.00521.95
8.1.320.0110.00918.05
8.1.310.0120.00616.28
8.1.300.0030.00616.68
8.1.290.0000.01118.88
8.1.280.0080.00825.92
8.1.270.0060.00324.04
8.1.260.0080.00028.09
8.1.250.0080.00028.09
8.1.240.0090.00023.96
8.1.230.0060.00619.22
8.1.220.0030.00618.04
8.1.210.0000.00818.77
8.1.200.0000.00917.72
8.1.190.0050.00317.60
8.1.180.0080.00018.10
8.1.170.0000.00818.80
8.1.160.0080.00022.25
8.1.150.0040.00419.06
8.1.140.0040.00419.63
8.1.130.0000.00819.54
8.1.120.0020.00517.60
8.1.110.0060.00317.74
8.1.100.0000.00717.66
8.1.90.0080.00017.71
8.1.80.0040.00417.59
8.1.70.0000.00717.65
8.1.60.0000.00817.77
8.1.50.0060.00317.69
8.1.40.0030.00717.64
8.1.30.0000.00817.86
8.1.20.0050.00317.81
8.1.10.0030.00517.80
8.1.00.0040.00417.68
8.0.300.0080.00021.84
8.0.290.0100.00017.13
8.0.280.0000.00718.49
8.0.270.0000.00717.40
8.0.260.0070.00017.12
8.0.250.0030.00317.32
8.0.240.0070.00017.20
8.0.230.0000.00817.28
8.0.220.0030.00517.22
8.0.210.0000.00717.21
8.0.200.0000.00717.23
8.0.190.0000.00817.32
8.0.180.0060.00317.29
8.0.170.0030.00617.25
8.0.160.0000.00817.27
8.0.150.0040.00417.19
8.0.140.0000.00717.23
8.0.130.0060.00013.64
8.0.120.0060.00317.19
8.0.110.0040.00417.24
8.0.100.0040.00417.35
8.0.90.0030.00617.14
8.0.80.0060.01017.27
8.0.70.0000.01017.19
8.0.60.0040.00417.36
8.0.50.0000.00817.23
8.0.30.0100.00717.54
8.0.20.0170.01217.45
8.0.10.0000.00817.27
8.0.00.0070.01017.20
7.4.330.0060.00015.08
7.4.320.0000.00717.01
7.4.300.0000.00616.86
7.4.290.0000.00716.94
7.4.280.0030.00616.85
7.4.270.0000.00816.94
7.4.260.0000.00716.95
7.4.250.0070.00016.97
7.4.240.0060.00316.86
7.4.230.0030.00316.73
7.4.220.0040.01316.89
7.4.210.0060.00916.97
7.4.200.0030.00317.00
7.4.160.0060.01016.79
7.4.150.0090.00917.40
7.4.140.0090.00917.86
7.4.130.0030.01416.96
7.4.120.0130.00417.01
7.4.110.0070.01016.87
7.4.100.0130.01316.94
7.4.90.0100.00916.92
7.4.80.0140.01119.39
7.4.70.0070.01016.94
7.4.60.0070.01116.88
7.4.50.0090.00916.89
7.4.40.0140.01016.76
7.4.30.0070.01416.68
7.4.10.0060.01215.09
7.4.00.0070.00815.47
7.3.330.0000.00513.49
7.3.320.0030.00313.54
7.3.310.0050.00316.66
7.3.300.0080.00016.71
7.3.290.0080.00616.63
7.3.280.0100.00816.64
7.3.270.0090.00817.40
7.3.260.0130.01016.74
7.3.250.0100.00816.74
7.3.240.0110.00816.71
7.3.230.0080.01216.87
7.3.210.0190.00316.79
7.3.200.0000.01816.69
7.3.190.0090.00916.73
7.3.180.0060.01016.97
7.3.170.0120.00616.84
7.3.160.0110.00716.82
7.3.130.0060.01215.28
7.3.120.0120.00515.04
7.3.110.0060.01114.90
7.3.100.0050.00814.83
7.3.90.0060.00915.05
7.3.80.0000.01415.15
7.3.70.0090.00715.20
7.3.60.0050.00714.97
7.3.50.0050.00815.00
7.3.40.0090.00515.14
7.3.30.0050.01115.04
7.3.20.0060.00817.07
7.3.10.0060.00616.95
7.3.00.0050.00716.77
7.2.330.0130.00616.72
7.2.320.0090.01316.89
7.2.310.0070.01116.87
7.2.300.0070.01216.97
7.2.290.0100.00716.74
7.2.260.0070.01115.27
7.2.250.0110.00715.36
7.2.240.0050.01115.46
7.2.230.0120.00515.34
7.2.220.0080.00715.37
7.2.210.0040.00915.37
7.2.200.0070.00715.11
7.2.190.0020.01115.04
7.2.180.0050.00615.43
7.2.170.0020.01415.24
7.2.160.0070.01015.30
7.2.150.0060.00717.16
7.2.140.0090.00517.11
7.2.130.0080.00717.06
7.2.120.0070.00817.00
7.2.110.0080.00617.16
7.2.100.0030.00817.15
7.2.90.0080.00817.22
7.2.80.0070.00817.21
7.2.70.0060.01117.23
7.2.60.0070.00517.19
7.2.50.0010.01417.19
7.2.40.0050.01017.21
7.2.30.0080.00717.10
7.2.20.0020.01117.32
7.2.10.0090.00817.13
7.2.00.0090.00417.04
7.1.330.0040.00715.93
7.1.320.0050.00816.19
7.1.310.0020.01216.18
7.1.300.0080.00616.10
7.1.290.0050.00816.14
7.1.280.0070.00716.10
7.1.270.0090.00316.03
7.1.260.0020.01015.87
7.1.250.0090.00415.94
7.1.240.0110.00415.67
7.1.230.0070.00416.18
7.1.220.0040.01115.81
7.1.210.0000.01615.91
7.1.200.0050.00716.14
7.1.190.0110.00015.99
7.1.180.0040.01116.20
7.1.170.0030.01016.11
7.1.160.0100.00416.10
7.1.150.0120.00616.02
7.1.140.0070.00716.08
7.1.130.0100.00615.93
7.1.120.0070.00716.16
7.1.110.0060.01016.12
7.1.100.0100.00716.02
7.1.90.0030.01316.20
7.1.80.0070.01116.09
7.1.70.0030.00816.65
7.1.60.0040.00916.83
7.1.50.0040.00816.04
7.1.40.0030.01315.77
7.1.30.0110.00716.22
7.1.20.0090.00615.95
7.1.10.0060.01216.12
7.1.00.0000.04819.13
7.0.330.0030.00715.57
7.0.320.0030.01015.61
7.0.310.0030.00715.39
7.0.300.0030.01215.73
7.0.290.0000.00915.61
7.0.280.0030.00615.77
7.0.270.0000.01615.66
7.0.260.0070.00715.76
7.0.250.0030.00615.69
7.0.240.0060.01015.89
7.0.230.0040.01415.70
7.0.220.0000.01415.71
7.0.210.0030.01015.82
7.0.200.0200.00315.32
7.0.190.0070.01015.50
7.0.180.0120.00315.88
7.0.170.0000.01315.51
7.0.160.0000.01415.67
7.0.150.0080.00415.79
7.0.140.0030.01015.66
7.0.130.0040.01115.75
7.0.120.0030.00915.57
7.0.110.0070.03618.00
7.0.100.0060.03517.93
7.0.90.0090.03518.04
7.0.80.0110.02718.06
7.0.70.0050.03318.04
7.0.60.0020.03617.96
7.0.50.0100.03217.96
7.0.40.0070.03217.04
7.0.30.0200.03117.12
7.0.20.0180.03216.99
7.0.10.0200.03216.97
7.0.00.0200.03317.06
5.6.400.0070.00714.46
5.6.390.0070.01014.50
5.6.380.0040.01414.31
5.6.370.0130.00014.75
5.6.360.0160.00014.61
5.6.350.0080.00314.51
5.6.340.0030.00614.72
5.6.330.0030.00614.14
5.6.320.0030.01214.10
5.6.310.0090.00614.73
5.6.300.0040.01114.66
5.6.290.0060.01214.74
5.6.280.0040.01514.52
5.6.270.0000.01514.80
5.6.260.0110.03417.74
5.6.250.0050.03517.75
5.6.240.0100.03517.82
5.6.230.0030.03717.67
5.6.220.0100.03117.70
5.6.210.0080.03017.79
5.6.200.0150.02817.84
5.6.190.0020.03617.72
5.6.180.0060.03017.89
5.6.170.0080.03017.87
5.6.160.0090.03317.76
5.6.150.0130.03017.76
5.6.140.0080.04117.84
5.6.130.0130.03017.74
5.6.120.0100.02817.98
5.6.110.0050.03417.69
5.6.100.0080.03217.78
5.6.90.0070.03117.79
5.6.80.0020.04017.44
5.6.70.0050.03317.49
5.6.60.0110.03417.27
5.6.50.0030.03417.42
5.6.40.0070.03017.18
5.6.30.0100.02817.27
5.6.20.0020.03417.36
5.6.10.0050.03217.39
5.6.00.0100.03017.57

preferences:
53.08 ms | 2026 KiB | 5 Q