3v4l.org

run code in 300+ PHP versions simultaneously
<?php function isValidDate(string $date, string $format = 'm/d/Y', string $yearPadding = '19'): bool { $date = preg_replace_callback( '~^(\d+)(\D)(\d+)\2(\d{2}|\d{4})$~', fn($m) => sprintf('%02d/%02d/%d', $m[1], $m[3], str_pad($m[4], 4, $yearPadding, STR_PAD_LEFT)), $date ); // sanitize $d = DateTime::createFromFormat($format, $date); // attempt to parse return $d && $d->format($format) === $date; // check if formatted string is same as sanitized string } $tests = [ '1-1-1992', '1-1-92', '1-01-1992', '1-01-92', '01-1-1992', '01-1-92', '01-01-1992', '01-01/92', '1/1/1992', '1/1/92', '1/01/1992', '1/01/92', '01/1/199', '01/1/92', '01/01/1992', '01/01/92' ]; var_export(array_map('isValidDate', $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.3.70.0140.00416.61
8.3.60.0140.01018.48
8.3.50.0100.01320.44
8.3.40.0120.00320.37
8.3.30.0140.00719.23
8.3.20.0000.00824.18
8.3.10.0120.00324.66
8.3.00.0090.00926.16
8.2.190.0130.01016.88
8.2.180.0100.01025.92
8.2.170.0000.01519.31
8.2.160.0070.00722.96
8.2.150.0080.00025.66
8.2.140.0100.00724.66
8.2.130.0000.00826.16
8.2.120.0060.00326.16
8.2.110.0070.00322.11
8.2.100.0000.01118.03
8.2.90.0040.00418.00
8.2.80.0030.00619.05
8.2.70.0040.00418.00
8.2.60.0040.00417.93
8.2.50.0080.00318.00
8.2.40.0090.00018.22
8.2.30.0000.00718.30
8.2.20.0050.00220.49
8.2.10.0000.00818.12
8.2.00.0030.00519.34
8.1.280.0070.00725.92
8.1.270.0070.01123.84
8.1.260.0070.00026.35
8.1.250.0140.00728.09
8.1.240.0100.00020.50
8.1.230.0080.00418.08
8.1.220.0060.00318.01
8.1.210.0000.00818.77
8.1.200.0060.00317.72
8.1.190.0080.00017.73
8.1.180.0050.00318.10
8.1.170.0040.00417.78
8.1.160.0000.00718.98
8.1.150.0070.00218.98
8.1.140.0040.00417.65
8.1.130.0070.00018.95
8.1.120.0040.00417.67
8.1.110.0000.00717.79
8.1.100.0060.00317.81
8.1.90.0080.00317.66
8.1.80.0000.00717.72
8.1.70.0000.00817.73
8.1.60.0000.00817.79
8.1.50.0040.00417.82
8.1.40.0040.00417.78
8.1.30.0030.00617.80
8.1.20.0090.00517.84
8.1.10.0040.00917.74
8.1.00.0160.01017.84
8.0.300.0060.00319.12
8.0.290.0000.00717.13
8.0.280.0030.00318.58
8.0.270.0070.00017.14
8.0.260.0030.00318.64
8.0.250.0080.00017.33
8.0.240.0000.00717.32
8.0.230.0060.00317.36
8.0.220.0040.00417.23
8.0.210.0030.00617.24
8.0.200.0060.00017.35
8.0.190.0000.00817.35
8.0.180.0040.00417.29
8.0.170.0040.00417.18
8.0.160.0030.00717.32
8.0.150.0110.00017.23
8.0.140.0200.00317.05
8.0.130.0170.00617.13
8.0.120.0200.00217.25
8.0.110.0120.00317.17
8.0.100.0070.00717.31
8.0.90.0100.00317.29
8.0.80.0190.00417.23
8.0.70.0210.00617.17
8.0.60.0160.00617.21
8.0.50.0210.00417.11
8.0.30.0170.00817.09
8.0.20.0250.00017.41
8.0.10.0160.00717.38
7.4.330.0000.00515.55
7.4.320.0030.00316.86
7.4.300.0030.00316.93
7.4.290.0000.00716.79
7.4.280.0080.00016.94
7.4.270.0150.00716.82
7.4.260.0250.00016.89
7.4.250.0170.00716.92
7.4.240.0110.01116.83
7.4.230.0160.00616.86
7.4.220.0140.00516.80
7.4.210.0260.00016.89
7.4.200.0250.00016.96
7.4.190.0210.00317.03
7.4.180.0220.00016.82
7.4.160.0190.00316.77
7.4.150.0170.00416.80
7.4.140.0140.00716.76
7.4.130.0210.00016.90
7.4.120.0200.00016.91
7.4.110.0170.00316.94
7.4.100.0060.01216.85
7.4.90.0120.00616.84
7.4.80.0060.00916.86
7.4.70.0170.00416.81
7.4.60.0200.00316.77
7.4.50.0110.00616.86
7.4.40.0040.01116.67
7.4.30.0090.00516.74
7.4.20.0120.00616.59
7.4.10.0080.01116.75
7.4.00.0210.00016.77

preferences:
62.58 ms | 401 KiB | 5 Q