3v4l.org

run code in 300+ PHP versions simultaneously
<?php function diffInMonth(DateTime $start,DateTime $end): int { $endDate = (clone $end)->setTimeZone($start->getTimeZone()); list($yearStart,$monthStart,$dayStart) = explode(" ",$start->format("Y m dHis")); list($yearEnd,$monthEnd, $dayEnd) = explode(" ",$endDate->format("Y m dHis")); $mothDiff = ($yearEnd - $yearStart) * 12 + $monthEnd - $monthStart; if($dayStart > $dayEnd && $end >= $start) --$mothDiff; elseif($dayStart < $dayEnd && $end < $start) ++$mothDiff; return $mothDiff; } $tests = [ ['start' => '2022-10-04', 'end' => '2022-11-04', 'month' => 1], ['start' => '2020-10-04', 'end' => '2022-11-04', 'month' => 25], ['start' => '2022-11-04', 'end' => '2020-10-04', 'month' => -25], ['start' => '2021-10-04 13:00', 'end' => '2022-11-04 13:00', 'month' => 13], ['start' => '2021-10-04 13:00', 'end' => '2022-11-04 12:59', 'month' => 12], ['start' => '2021-10-04 13:01', 'end' => '2022-11-04 13:00', 'month' => 12], ['start' => '2022-11-01 13:00 Europe/Berlin', 'end' => '2022-12-01 12:00 UTC', 'month' => 1], ]; foreach($tests as $test){ $start = new DateTime($test['start']); $end = new DateTime($test['end']); $month = diffInMonth($start, $end); $msg = $test['start']." - ".$test['end']; $msg .= ' : '.$month.' Month '.($month === $test['month'] ? 'Ok' : 'Error')."<br>\n"; echo $msg; }

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.120.0120.00920.50
8.4.110.0110.00922.53
8.4.100.0130.00718.78
8.4.90.0060.00318.82
8.4.80.0120.01017.96
8.4.70.0120.00818.26
8.4.60.0150.00518.83
8.4.50.0130.00718.82
8.4.40.0040.01219.72
8.4.30.0040.01119.08
8.4.20.0070.00319.79
8.4.10.0060.00324.02
8.3.250.0060.01218.64
8.3.240.0130.00316.59
8.3.230.0060.00516.89
8.3.220.0050.00317.48
8.3.210.0110.00816.70
8.3.200.0060.00616.84
8.3.190.0070.00917.32
8.3.180.0100.00816.71
8.3.170.0120.00618.68
8.3.160.0180.00017.19
8.3.150.0040.00421.00
8.3.140.0080.01116.71
8.3.130.0140.00318.59
8.3.120.0040.01220.72
8.3.110.0040.00416.69
8.3.100.0170.00318.62
8.3.90.0110.00426.77
8.3.80.0060.00317.00
8.3.70.0130.00316.88
8.3.60.0120.00618.56
8.3.50.0070.01118.51
8.3.40.0100.00319.96
8.3.30.0120.00318.91
8.3.20.0040.00424.18
8.3.10.0080.00024.66
8.3.00.0050.00326.16
8.2.290.0090.01020.46
8.2.280.0120.00620.63
8.2.270.0100.01022.35
8.2.260.0000.00816.71
8.2.250.0080.01218.46
8.2.240.0050.00316.87
8.2.230.0090.00620.94
8.2.220.0030.00624.06
8.2.210.0080.00826.77
8.2.200.0060.00316.88
8.2.190.0100.01016.88
8.2.180.0070.01125.92
8.2.170.0100.01022.96
8.2.160.0090.00622.96
8.2.150.0050.00325.66
8.2.140.0040.00424.66
8.2.130.0080.00026.16
8.2.120.0050.00321.05
8.2.110.0000.01022.11
8.2.100.0130.00017.97
8.2.90.0040.00418.00
8.2.80.0080.00018.98
8.2.70.0090.00017.88
8.2.60.0080.00018.05
8.2.50.0080.00018.07
8.2.40.0030.00518.28
8.2.30.0070.00018.17
8.2.20.0000.00720.59
8.2.10.0000.00818.28
8.2.00.0040.00419.48
8.1.330.0120.00722.00
8.1.320.0090.00716.48
8.1.310.0030.00516.97
8.1.300.0030.00618.60
8.1.290.0030.00630.84
8.1.280.0060.01225.92
8.1.270.0000.00724.66
8.1.260.0050.00326.35
8.1.250.0080.00028.09
8.1.240.0060.00320.95
8.1.230.0070.00417.95
8.1.220.0040.00417.79
8.1.210.0060.00318.77
8.1.200.0030.00617.48
8.1.190.0000.00817.48
8.1.180.0040.00418.10
8.1.170.0000.00918.72
8.1.160.0040.00418.98
8.1.150.0050.00218.92
8.1.140.0040.00417.63
8.1.130.0000.00719.04
8.1.120.0110.00717.63
8.1.110.0130.00517.59
8.1.100.0120.00517.71
8.1.90.0100.00717.55
8.1.80.0000.01217.57
8.1.70.0060.00617.52
8.1.60.0060.00617.61
8.1.50.0130.00017.55
8.1.40.0030.01017.59
8.1.30.0040.00817.66
8.1.20.0080.00517.73
8.1.10.0090.00517.70
8.1.00.0160.00317.69
8.0.300.0060.00318.77
8.0.290.0000.00817.13
8.0.280.0070.00018.50
8.0.270.0000.00717.13
8.0.260.0070.00018.54
8.0.250.0110.00517.13
8.0.240.0120.00317.13
8.0.230.0050.01017.20
8.0.220.0090.00517.15
8.0.210.0100.00417.13
8.0.200.0070.01017.21
8.0.190.0000.01216.89
8.0.180.0040.01117.05
8.0.170.0030.01017.01
8.0.160.0060.00616.82
8.0.150.0120.00016.88
8.0.140.0080.00416.70
8.0.130.0100.00217.10
8.0.120.0110.00317.20
8.0.110.0030.00916.93
8.0.100.0090.00317.07
8.0.90.0030.01216.92
8.0.80.0060.00616.99
8.0.70.0000.01317.01
8.0.60.0050.00516.97
8.0.50.0080.00416.95
8.0.30.0050.00517.07
8.0.20.0040.00417.13
8.0.10.0080.00517.30
7.4.330.0020.00215.55
7.4.320.0050.01016.79
7.4.300.0130.00316.65
7.4.290.0170.00016.64
7.4.280.0160.00016.69
7.4.270.0160.00016.78
7.4.260.0140.00316.59
7.4.250.0160.00016.63
7.4.240.0130.00216.75
7.4.230.0170.00016.56
7.4.220.0120.00416.67
7.4.210.0050.01016.59
7.4.200.0160.00016.53
7.4.190.0080.00816.70
7.4.180.0120.00316.74
7.4.160.0070.00816.59
7.4.150.0130.00316.76
7.4.140.0100.00516.66
7.4.130.0150.00016.62
7.4.120.0110.00316.67
7.4.110.0070.00716.80
7.4.100.0060.00616.58
7.4.90.0070.00316.56
7.4.80.0040.00816.38
7.4.70.0130.00016.53
7.4.60.0000.01116.48
7.4.50.0080.00316.19
7.4.40.0100.00016.22
7.4.30.0100.00016.44
7.4.20.0070.00416.17
7.4.10.0060.00616.59
7.4.00.0120.00016.44

preferences:
26.79 ms | 403 KiB | 5 Q