3v4l.org

run code in 300+ PHP versions simultaneously
<?php function nextMonth($date, $increment) { $firstOfDateMonth = \DateTime::createFromFormat('Y-m-d', $date)->modify('first day of this month'); $thirtyFirstOfDateMonth = \DateTime::createFromFormat('Y-m-d', $date)->modify('last day of this month'); $thirtyFirstOfDateMonthNum = $thirtyFirstOfDateMonth->format('d'); $thirtyFirstOfNextMonth = clone $firstOfDateMonth; $thirtyFirstOfNextMonth->modify('+' . (int) $increment . ' month')->modify('last day of this month'); $thirtyFirstOfNextMonthNum = $thirtyFirstOfNextMonth->format('d'); $dayOfDateMonth = \DateTime::createFromFormat('Y-m-d', $date); $dayOfDateMonthNum = $dayOfDateMonth->format('d'); $dt = \DateTime::createFromFormat('Y-m-d', $date); $dt->modify('+' . (int) $increment . ' month'); if ($thirtyFirstOfNextMonthNum < $thirtyFirstOfDateMonthNum && $thirtyFirstOfNextMonthNum < $dayOfDateMonthNum) { $dt = clone $thirtyFirstOfNextMonth; } return $dt->format('Y-m-d'); } echo nextMonth('2009-12-31', 2),"\n"; echo nextMonth('2010-01-31', 1),"\n"; echo nextMonth('2010-01-05', 1),"\n"; echo nextMonth('2010-12-05', 1),"\n"; echo nextMonth('2010-01-31', 13),"\n"; echo nextMonth('2010-01-31', 3),"\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.3.60.0070.01416.63
8.3.50.0110.01416.71
8.3.40.0140.00718.66
8.3.30.0110.00418.92
8.3.20.0080.00018.92
8.3.10.0030.00620.66
8.3.00.0000.00819.51
8.2.180.0080.01116.75
8.2.170.0040.01122.96
8.2.160.0130.00321.14
8.2.150.0030.00524.18
8.2.140.0040.00424.66
8.2.130.0090.00026.16
8.2.120.0050.00319.39
8.2.110.0060.00320.86
8.2.100.0040.00818.09
8.2.90.0000.01019.45
8.2.80.0080.00019.30
8.2.70.0000.01017.88
8.2.60.0060.00318.15
8.2.50.0000.00818.07
8.2.40.0040.00418.30
8.2.30.0040.00418.22
8.2.20.0060.00318.02
8.2.10.0050.00318.01
8.2.00.0110.00017.87
8.1.280.0220.00025.92
8.1.270.0050.00324.66
8.1.260.0040.00426.35
8.1.250.0040.00428.09
8.1.240.0060.00322.61
8.1.230.0060.00621.17
8.1.220.0080.00017.78
8.1.210.0030.00619.04
8.1.200.0060.00317.73
8.1.190.0000.00817.79
8.1.180.0000.00818.10
8.1.170.0030.00619.09
8.1.160.0000.00718.99
8.1.150.0040.00418.83
8.1.140.0000.00817.83
8.1.130.0030.00317.93
8.1.120.0000.00817.82
8.1.110.0000.00917.72
8.1.100.0000.00717.77
8.1.90.0000.00817.75
8.1.80.0040.00417.80
8.1.70.0000.00717.75
8.1.60.0050.00517.89
8.1.50.0030.00617.79
8.1.40.0060.00317.84
8.1.30.0040.00417.91
8.1.20.0060.00317.88
8.1.10.0060.00317.79
8.1.00.0040.00417.80
8.0.300.0040.00420.14
8.0.290.0070.00017.13
8.0.280.0040.00418.55
8.0.270.0000.00717.44
8.0.260.0000.00717.15
8.0.250.0000.00717.29
8.0.240.0000.00817.17
8.0.230.0070.00017.16
8.0.220.0060.00317.20
8.0.210.0040.00417.07
8.0.200.0000.00717.26
8.0.190.0000.00817.17
8.0.180.0080.00017.24
8.0.170.0050.00517.21
8.0.160.0040.00417.12
8.0.150.0040.00417.14
8.0.140.0080.00017.15
8.0.130.0000.00613.53
8.0.120.0000.00717.05
8.0.110.0070.00017.20
8.0.100.0040.00417.16
8.0.90.0040.00417.27
8.0.80.0080.00817.16
8.0.70.0040.00417.12
8.0.60.0000.00917.26
8.0.50.0040.00417.25
8.0.30.0140.00617.26
8.0.20.0120.00817.51
8.0.10.0000.00717.39
8.0.00.0120.00616.89
7.4.330.0030.00313.26
7.4.320.0020.00516.76
7.4.300.0000.00616.75
7.4.290.0030.00316.90
7.4.280.0000.00816.77
7.4.270.0070.00016.91
7.4.260.0030.00313.46
7.4.250.0040.00416.69
7.4.240.0040.00316.78
7.4.230.0080.00016.87
7.4.220.0100.01016.85
7.4.210.0060.00916.84
7.4.200.0040.00416.96
7.4.190.0040.00416.82
7.4.160.0160.00016.78
7.4.150.0130.01216.75
7.4.140.0090.00816.70
7.4.130.0140.00816.86
7.4.120.0100.01016.77
7.4.110.0130.00616.66
7.4.100.0120.00916.79
7.4.90.0060.01316.67
7.4.80.0110.01219.39
7.4.70.0030.01316.93
7.4.60.0080.00816.75
7.4.50.0080.00416.86
7.4.40.0110.00716.82
7.4.30.0130.00316.77
7.4.00.0050.01515.30
7.3.330.0030.00313.48
7.3.320.0000.00713.47
7.3.310.0000.00716.59
7.3.300.0070.00016.42
7.3.290.0130.00616.52
7.3.280.0080.00816.57
7.3.270.0000.01616.57
7.3.260.0070.02016.64
7.3.250.0120.00716.86
7.3.240.0170.00016.69
7.3.230.0100.01316.98
7.3.210.0140.00316.79
7.3.200.0100.00716.92
7.3.190.0170.00416.84
7.3.180.0070.01116.59
7.3.170.0120.01116.49
7.3.160.0030.01316.82
7.3.120.0090.00715.13
7.3.110.0060.00915.20
7.3.100.0120.00615.34
7.3.90.0120.00315.15
7.3.80.0060.00815.16
7.3.70.0000.01115.22
7.3.60.0070.00415.24
7.3.50.0000.00915.27
7.3.40.0060.00915.09
7.3.30.0090.00614.96
7.3.20.0030.00616.75
7.3.10.0070.01016.81
7.3.00.0100.00316.82
7.2.330.0090.00916.98
7.2.320.0070.01016.98
7.2.310.0030.01716.70
7.2.300.0150.00917.09
7.2.290.0130.00617.01
7.2.250.0130.00715.41
7.2.240.0100.00715.16
7.2.230.0060.00914.98
7.2.220.0040.01214.98
7.2.210.0120.00315.23
7.2.200.0030.01415.35
7.2.190.0070.00715.30
7.2.180.0060.00615.39
7.2.170.0110.00415.45
7.2.160.0070.01015.25
7.2.150.0120.00317.15
7.2.140.0070.01016.90
7.2.130.0080.00817.20
7.2.120.0120.00617.11
7.2.110.0060.00917.37
7.2.100.0090.00917.09
7.2.90.0090.00617.29
7.2.80.0000.01617.25
7.2.70.0110.00317.00
7.2.60.0130.00317.30
7.2.50.0100.00317.31
7.2.40.0000.01717.09
7.2.30.0040.01117.21
7.2.20.0120.00317.37
7.2.10.0030.00916.93
7.2.00.0030.01216.99
7.1.330.0030.01015.96
7.1.320.0060.00615.90
7.1.310.0030.00815.91
7.1.300.0070.00715.96
7.1.290.0060.00915.86
7.1.280.0000.01715.86
7.1.270.0030.01315.98
7.1.260.0030.01015.84
7.1.250.0040.01115.79
7.1.240.0030.01015.98
7.1.230.0030.00915.89
7.1.220.0040.01416.05
7.1.210.0100.00715.98
7.1.200.0140.00015.70
7.1.190.0070.01015.93
7.1.180.0070.01015.91
7.1.170.0030.00915.65
7.1.160.0060.00915.81
7.1.150.0040.01116.03
7.1.140.0030.00616.13
7.1.130.0040.00716.15
7.1.120.0070.01316.19
7.1.110.0070.00715.84
7.1.100.0020.01317.15
7.1.90.0130.00315.99
7.1.80.0060.00616.02
7.1.70.0020.00916.63
7.1.60.0050.01517.75
7.1.50.0070.00916.54
7.1.40.0090.00915.81
7.1.30.0130.00616.21
7.1.20.0000.01616.13
7.1.10.0060.01016.07
7.1.00.0060.03119.21
7.0.330.0000.00815.76
7.0.320.0050.00515.65
7.0.310.0040.01515.58
7.0.300.0030.00715.57
7.0.290.0060.00615.35
7.0.280.0040.00815.38
7.0.270.0060.00915.55
7.0.260.0080.01115.70
7.0.250.0030.01315.64
7.0.240.0000.01015.67
7.0.230.0070.00715.66
7.0.220.0040.01215.86
7.0.210.0090.00915.64
7.0.200.0020.00816.32
7.0.190.0000.01215.43
7.0.180.0080.00515.57
7.0.170.0100.00715.54
7.0.160.0030.01015.50
7.0.150.0150.00315.67
7.0.140.0030.04418.87
7.0.130.0060.01015.80
7.0.120.0070.03718.74
7.0.110.0030.04518.77
7.0.100.0070.04218.60
7.0.90.0060.04718.65
7.0.80.0020.03218.59
7.0.70.0040.04518.63
7.0.60.0120.02218.64
7.0.50.0030.03318.80
7.0.40.0070.02516.68
7.0.30.0070.04016.76
7.0.20.0020.03416.66
7.0.10.0100.03816.69
7.0.00.0080.04316.72
5.6.400.0060.00614.77
5.6.390.0000.01414.30
5.6.380.0070.01114.63
5.6.370.0070.01114.77
5.6.360.0000.01114.45
5.6.350.0040.01114.73
5.6.340.0030.01014.37
5.6.330.0140.00014.48
5.6.320.0060.00914.56
5.6.310.0090.00914.64
5.6.300.0030.01314.83
5.6.290.0070.00714.56
5.6.280.0050.04117.57
5.6.270.0060.00614.43
5.6.260.0030.02817.41
5.6.250.0050.03617.46
5.6.240.0100.04317.50
5.6.230.0070.04317.62
5.6.220.0060.02317.58
5.6.210.0090.04017.60
5.6.200.0110.03317.51
5.6.190.0070.04217.66
5.6.180.0060.02817.46
5.6.170.0020.04717.54
5.6.160.0070.04517.55
5.6.150.0020.05017.42
5.6.140.0060.04117.75
5.6.130.0070.04317.66
5.6.120.0040.04517.41
5.6.110.0060.03617.67
5.6.100.0110.03617.55
5.6.90.0080.04217.67
5.6.80.0050.03917.37
5.6.70.0170.02717.25
5.6.60.0100.04217.19
5.6.50.0050.04417.04
5.6.40.0030.04517.15
5.6.30.0060.04117.38
5.6.20.0090.04517.21
5.6.10.0080.03517.28
5.6.00.0050.04517.24
5.5.380.0080.04317.44
5.5.370.0070.04417.51
5.5.360.0070.04217.42
5.5.350.0090.03517.54
5.5.340.0080.04017.49
5.5.330.0090.04317.81
5.5.320.0120.03517.62
5.5.310.0120.04217.59
5.5.300.0050.04317.72
5.5.290.0070.03217.47
5.5.280.0030.04317.75
5.5.270.0020.04717.70
5.5.260.0050.04917.84
5.5.250.0080.04117.50
5.5.240.0080.03517.36
5.5.230.0120.04217.35
5.5.220.0000.03717.24
5.5.210.0110.04117.26
5.5.200.0090.04317.21
5.5.190.0050.04817.26
5.5.180.0030.04517.16
5.5.170.0100.00314.51
5.5.160.0070.04517.33
5.5.150.0080.04017.24
5.5.140.0050.04417.38
5.5.130.0080.03717.35
5.5.120.0110.03117.33
5.5.110.0100.02917.36
5.5.100.0080.04217.05
5.5.90.0070.04117.34
5.5.80.0120.03817.12
5.5.70.0050.02317.05
5.5.60.0060.04217.20
5.5.50.0060.04017.16
5.5.40.0050.04317.27
5.5.30.0040.04317.28
5.5.20.0050.04317.28
5.5.10.0040.04917.22
5.5.00.0080.04317.31
5.4.450.0090.03015.31
5.4.440.0050.04415.40
5.4.430.0120.03515.36
5.4.420.0080.04315.18
5.4.410.0100.03515.10
5.4.400.0090.04115.25
5.4.390.0070.03815.00
5.4.380.0060.03315.25
5.4.370.0110.03915.23
5.4.360.0020.04115.13
5.4.350.0070.03915.20
5.4.340.0050.04215.27
5.4.330.0030.00711.05
5.4.320.0050.03015.04
5.4.310.0020.03415.29
5.4.300.0100.03815.09
5.4.290.0050.04515.11
5.4.280.0080.03515.04
5.4.270.0050.04015.19
5.4.260.0070.03315.07
5.4.250.0060.04515.24
5.4.240.0030.04215.11
5.4.230.0040.02815.37
5.4.220.0050.02815.08
5.4.210.0020.03415.05
5.4.200.0070.04315.28
5.4.190.0000.03415.18
5.4.180.0030.04415.12
5.4.170.0070.04515.19
5.4.160.0130.03315.15
5.4.150.0030.02715.14
5.4.140.0100.03713.85
5.4.130.0070.03813.69
5.4.120.0070.03813.71
5.4.110.0070.03913.79
5.4.100.0070.04113.94
5.4.90.0060.03913.79
5.4.80.0050.04013.75
5.4.70.0080.03613.89
5.4.60.0060.03813.85
5.4.50.0100.03313.67
5.4.40.0070.03813.88
5.4.30.0060.04113.78
5.4.20.0030.03113.79
5.4.10.0070.03213.71
5.4.00.0050.03813.41
5.3.290.0030.04012.88
5.3.280.0060.04112.89
5.3.270.0050.04412.84
5.3.260.0020.04412.95
5.3.250.0060.04012.85
5.3.240.0030.04112.84
5.3.230.0050.04012.85
5.3.220.0020.04412.80
5.3.210.0080.04312.86
5.3.200.0030.02912.82
5.3.190.0030.04312.83
5.3.180.0050.03912.80
5.3.170.0050.03812.82
5.3.160.0080.02212.81
5.3.150.0020.03712.86
5.3.140.0030.04212.81
5.3.130.0060.04312.82
5.3.120.0030.03212.84
5.3.110.0050.03812.87
5.3.100.0070.03912.56
5.3.90.0070.02512.54
5.3.80.0050.04012.55
5.3.70.0080.03812.60
5.3.60.0110.03712.57
5.3.50.0070.03812.62
5.3.40.0050.03712.50
5.3.30.0070.03512.48
5.3.20.0050.03612.37
5.3.10.0030.03912.42
5.3.00.0030.02512.37
5.2.170.0100.06012.00
5.2.160.0030.05012.00
5.2.150.0070.06312.00
5.2.140.0030.04012.00
5.2.130.0030.06312.00
5.2.120.0030.03712.00
5.2.110.0070.05012.00
5.2.100.0070.06312.00
5.2.90.0130.05012.00
5.2.80.0070.06012.00
5.2.70.0170.04312.00
5.2.60.0100.05712.00
5.2.50.0070.05312.00
5.2.40.0030.03312.00
5.2.30.0000.06012.00
5.2.20.0070.05012.00
5.2.10.0070.05712.00
5.2.00.0030.05312.00
5.1.60.0100.04712.00
5.1.50.0030.04712.00
5.1.40.0030.05312.00
5.1.30.0030.05712.00
5.1.20.0030.05312.00
5.1.10.0100.05712.00
5.1.00.0030.05712.00
5.0.50.0000.05012.00
5.0.40.0030.04712.00
5.0.30.0030.05012.00
5.0.20.0030.03312.00
5.0.10.0030.04312.00
5.0.00.0000.06312.00
4.4.90.0030.03012.00
4.4.80.0030.03312.00
4.4.70.0100.02712.00
4.4.60.0000.03712.00
4.4.50.0070.02712.00
4.4.40.0030.03312.00
4.4.30.0000.02012.00
4.4.20.0000.02012.00
4.4.10.0030.03312.00
4.4.00.0000.03312.00
4.3.110.0000.03712.00
4.3.100.0070.02712.00
4.3.90.0070.01712.00
4.3.80.0070.05012.00
4.3.70.0000.02012.00
4.3.60.0030.03312.00
4.3.50.0030.03312.00
4.3.40.0030.04712.00
4.3.30.0030.03012.00
4.3.20.0000.03012.00
4.3.10.0000.03712.00
4.3.00.0000.03712.00

preferences:
39.65 ms | 401 KiB | 5 Q