3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getFormattedDate(string $date, string $format = 'm/d/Y', string $yearPadding = '19'): string { $sanitizedDate = preg_replace_callback( '~^(\d+)(\D)(\d+)\2(\d+)$~', 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, $sanitizedDate); // attempt to parse if (!$d) { throw new Exception("Could not parse date: $date"); } $formattedDate = $d->format($format); if ($formattedDate !== $sanitizedDate) { throw new Exception("Date not in a desired American format: $date"); } else { return $date; } } $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' ]; foreach ($tests as $test) { try { echo getFormattedDate($test); } catch (Exception $e) { echo $e->getMessage(); } echo "\n"; }

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.0040.00618.61
8.4.120.0120.00923.98
8.4.110.0040.00522.54
8.4.100.0120.01119.00
8.4.90.0140.00619.07
8.4.80.0090.00224.14
8.4.70.0070.00918.65
8.4.60.0070.00418.96
8.4.50.0090.01120.75
8.4.40.0120.00918.22
8.4.30.0030.01620.24
8.4.20.0170.00320.26
8.4.10.0060.00318.44
8.3.260.0140.00616.93
8.3.250.0090.01019.01
8.3.240.0090.00817.26
8.3.230.0160.00416.80
8.3.220.0120.00619.24
8.3.210.0120.00717.00
8.3.200.0040.00516.93
8.3.190.0090.00617.35
8.3.180.0130.00717.04
8.3.170.0060.01318.99
8.3.160.0100.01017.41
8.3.150.0110.00417.13
8.3.140.0110.00416.83
8.3.130.0080.00018.59
8.3.120.0060.01018.82
8.3.110.0090.00018.57
8.3.100.0040.00416.80
8.3.90.0080.00026.77
8.3.80.0080.00416.75
8.3.70.0150.00416.88
8.3.60.0100.00618.43
8.3.50.0070.01120.48
8.3.40.0110.00320.34
8.3.30.0130.00719.21
8.3.20.0040.00424.18
8.3.10.0040.00424.66
8.3.00.0050.00326.16
8.2.290.0090.01020.74
8.2.280.0150.00718.59
8.2.270.0150.00417.59
8.2.260.0040.01516.67
8.2.250.0090.00618.80
8.2.240.0120.00416.95
8.2.230.0060.00320.94
8.2.220.0040.00424.06
8.2.210.0050.00326.77
8.2.200.0100.00016.63
8.2.190.0070.00716.75
8.2.180.0160.00025.92
8.2.170.0110.00419.16
8.2.160.0180.00422.96
8.2.150.0000.00725.66
8.2.140.0090.00624.66
8.2.130.0060.00326.16
8.2.120.0040.00426.16
8.2.110.0040.00722.20
8.2.100.0060.00618.16
8.2.90.0040.00419.20
8.2.80.0030.00518.13
8.2.70.0090.00018.13
8.2.60.0030.00518.05
8.2.50.0050.00318.07
8.2.40.0080.00018.28
8.2.30.0040.00418.18
8.2.20.0050.00520.50
8.2.10.0060.00318.12
8.2.00.0000.00819.33
8.1.330.0120.00822.21
8.1.320.0090.01016.77
8.1.310.0100.01018.45
8.1.300.0100.00016.59
8.1.290.0030.00630.84
8.1.280.0030.01225.92
8.1.270.0000.00823.99
8.1.260.0020.00526.35
8.1.250.0090.00028.09
8.1.240.0030.00622.64
8.1.230.0120.00017.73
8.1.220.0000.00917.90
8.1.210.0030.00518.77
8.1.200.0030.00617.50
8.1.190.0050.00317.72
8.1.180.0040.00418.10
8.1.170.0040.00418.84
8.1.160.0040.00418.94
8.1.150.0030.00618.92
8.1.140.0040.00417.76
8.1.130.0000.00719.03
8.1.120.0040.00417.76
8.1.110.0030.00517.68
8.1.100.0030.00617.74
8.1.90.0000.00717.70
8.1.80.0080.00017.68
8.1.70.0030.00317.85
8.1.60.0070.00317.75
8.1.50.0060.00317.77
8.1.40.0000.00817.80
8.1.30.0000.00917.91
8.1.20.0140.01117.83
8.1.10.0170.00617.80
8.1.00.0160.00917.77
8.0.300.0030.00618.77
8.0.290.0050.00317.25
8.0.280.0000.00818.56
8.0.270.0000.00717.19
8.0.260.0030.00318.50
8.0.250.0030.00517.31
8.0.240.0000.00717.35
8.0.230.0000.00717.36
8.0.220.0000.00717.30
8.0.210.0040.00417.24
8.0.200.0030.00317.39
8.0.190.0040.00417.29
8.0.180.0040.00417.22
8.0.170.0060.00317.27
8.0.160.0130.00817.18
8.0.150.0210.00017.28
8.0.140.0160.00517.16
8.0.130.0160.00417.25
8.0.120.0140.00517.29
8.0.110.0150.00517.21
8.0.100.0180.00717.19
8.0.90.0180.00317.31
8.0.80.0150.00717.16
8.0.70.0170.00317.23
8.0.60.0170.00617.29
8.0.50.0170.00417.36
8.0.30.0130.01017.30
8.0.20.0190.00317.42
8.0.10.0210.00017.29
7.4.330.0030.00315.55
7.4.320.0060.00316.75
7.4.300.0080.00016.91
7.4.290.0000.00816.77
7.4.280.0160.00516.96
7.4.270.0190.00316.86
7.4.260.0190.00616.84
7.4.250.0240.00416.71
7.4.240.0170.00916.91
7.4.230.0200.00716.82
7.4.220.0210.00316.91
7.4.210.0110.00816.89
7.4.200.0140.00516.96
7.4.190.0110.00716.84
7.4.180.0120.00416.68
7.4.160.0140.00416.91
7.4.150.0180.00516.95
7.4.140.0210.00016.71
7.4.130.0060.01616.90
7.4.120.0200.00216.61
7.4.110.0190.00816.77
7.4.100.0180.00616.89
7.4.90.0240.00016.73
7.4.80.0000.02116.79
7.4.70.0160.00416.68
7.4.60.0130.00716.93
7.4.50.0160.00316.65
7.4.40.0120.00416.61
7.4.30.0080.00816.83
7.4.20.0120.00316.66
7.4.10.0110.00816.66
7.4.00.0150.00316.66

preferences:
121.91 ms | 403 KiB | 5 Q