3v4l.org

run code in 300+ PHP versions simultaneously
<?php // would probably stream reading instead of ingesting as array in real life (due to potentially high number of entries) $bookings = array_map('str_getcsv', explode("\n", getCSV())); array_shift($bookings); // getting input $input = explode('-', trim(fgets(fopen('php://stdin', 'r')))); $year = $input[0]; $month = $input[1]; // determining time boundaries of the month $start_date = mktime(0, 0, 0, $month, 1, $year); // first of the month $end_date = mktime(0, 0, 0, $month < 12 ? $month + 1 : 1, 1, $month == 12 ? $year + 1 : $year); // next month's first of the month // length of the period, used for proration $test_period = $end_date - $start_date; $total_capacity = 0; $booked_capacity = 0; $total_revenue = 0; foreach ($bookings as $booking) { $booking_start_date = strtotime($booking[2]); $booking_end_date = $booking[3] ? strtotime($booking[3]) + 86400: FALSE; // end of day // booking is matched if it starts before month ends and either open-ended or ends after month starts if ($booking_start_date < $end_date && (!$booking_end_date || $booking_end_date > $start_date)) { // effective dates within a month to calculate booking value off of $booking_overlap_start = $booking_start_date > $start_date ? $booking_start_date : $start_date; $booking_overlap_end = $booking_end_date && $booking_end_date < $end_date ? $booking_end_date : $end_date; // effective time booked $period = $booking_overlap_end - $booking_overlap_start; // prorating the value based on booked period $total_revenue += $booking[1] * $period / $test_period; $booked_capacity += $booking[0]; } $total_capacity += $booking[0]; } $unreserved_capacity = $total_capacity - $booked_capacity; setlocale(LC_MONETARY, 'en_US'); echo "expected revenue: " . money_format('%.2n', $total_revenue) . ", expected total capacity of the unreserved offices: $unreserved_capacity\n"; function getCSV () { return <<<END Capacity,MonthlyPrice,StartDay,EndDay 1,600,2014-07-01, 1,400,2014-04-02, 1,400,2014-05-01, 5,2800,2014-03-01,2014-04-30 2,1500,2014-05-01,2014-06-30 4,1700,2014-04-01, 3,1300,2014-04-01, 15,6500,2014-05-01,2014-08-31 1,400,2014-05-01, 1,400,2014-05-01, 3,1400,2014-05-01, 18,7200,2014-05-01, 1,800,2014-06-01, 1,700,2014-05-01,2014-06-30 2,1250,2014-04-16,2014-06-02 1,600,2013-11-01,2014-05-31 8,4000,2014-06-02,2014-07-31 2,1300,2014-05-01,2014-10-31 4,2200,2014-05-01, 14,11875,2014-06-01, 2,1500,2014-05-01,2014-08-31 2,1500,2012-06-01, 3,1850,2014-04-09,2014-08-06 2,1100,2014-05-01,2014-09-30 1,625,2014-04-11, 1,1000,2014-02-14, 1,400,2014-05-01, 6,3600,2014-04-02, 2,950,2013-02-01,2014-05-31 4,2500,2013-06-01,2014-04-30 2,1200,2014-07-01,2014-08-31 1,950,2014-06-01,2014-08-31 4,3200,2014-04-01,2014-09-30 1,400,2014-03-27,2014-04-10 4,2600,2014-02-01,2014-04-08 11,5500,2014-05-01, 2,1200,2014-05-01,2014-07-02 1,600,2014-05-01,2014-07-31 1,800,2013-11-01,2014-04-30 1,700,2013-05-01, 2,900,2014-07-01,2014-08-31 2,1400,2014-04-02, 2,1500,2014-05-01, 2,1200,2014-05-01, 2,1500,2014-05-01,2014-10-31 2,900,2014-02-01, 1,400,2014-04-14, 2,900,2014-01-01,2014-06-30 2,1000,2013-12-01,2014-06-30 9,4500,2014-02-06,2014-04-30 4,2500,2013-08-01, 6,2900,2013-05-01,2014-05-31 1,600,2014-04-09, 2,1700,2014-02-14,2014-04-30 2,900,2014-07-01, 1,400,2014-05-01,2014-10-31 2,0,2014-04-15,2014-05-01 4,2500,2014-05-01, 4,3600,2014-05-01, 9,4950,2014-05-01, 2,1100,2014-05-12, 6,2700,2014-05-01,2014-08-31 16,350,2014-04-01,2014-08-31 2,1300,2012-10-01, 1,950,2014-06-01,2014-06-08 3,2000,2014-06-01,2014-06-30 8,3600,2014-07-08, 6,5400,2014-05-12, 4,2700,2013-09-01, 4,2600,2012-06-01,2014-05-31 4,2700,2012-07-01,2014-04-30 1,450,2014-04-02, 4,2700,2014-04-01,2014-04-30 4,2200,2014-06-01,2014-10-31 END; }

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.0150.00016.74
8.3.50.0070.01017.92
8.3.40.0090.00618.73
8.3.30.0120.00318.79
8.3.20.0050.00320.14
8.3.10.0000.00823.52
8.3.00.0050.00319.51
8.2.180.0120.00318.41
8.2.170.0130.00322.96
8.2.160.0000.01420.39
8.2.150.0040.00424.18
8.2.140.0050.00324.66
8.2.130.0070.00319.20
8.2.120.0050.00326.35
8.2.110.0030.00719.30
8.2.100.0040.00817.91
8.2.90.0050.00319.23
8.2.80.0060.00317.97
8.2.70.0040.00417.50
8.2.60.0030.00617.93
8.2.50.0000.00818.10
8.2.40.0040.00419.22
8.2.30.0070.00020.78
8.2.20.0060.00317.86
8.2.10.0040.00418.03
8.2.00.0050.00318.11
8.1.270.0030.00623.95
8.1.260.0080.00028.09
8.1.250.0080.00028.09
8.1.240.0140.00722.26
8.1.230.0060.00618.07
8.1.220.0030.00517.78
8.1.210.0060.00318.77
8.1.200.0000.00917.35
8.1.190.0100.00317.13
8.1.180.0080.00018.10
8.1.170.0060.00318.52
8.1.160.0070.00022.06
8.1.150.0000.00718.80
8.1.140.0000.00919.58
8.1.130.0050.00217.70
8.1.120.0020.00517.53
8.1.110.0040.00417.35
8.1.100.0000.00717.46
8.1.90.0040.00417.46
8.1.80.0040.00417.35
8.1.70.0070.00017.44
8.1.60.0000.00817.64
8.1.50.0030.00517.59
8.1.40.0000.00917.64
8.1.30.0000.00917.63
8.1.20.0000.00817.67
8.1.10.0050.00317.70
8.1.00.0050.00317.44
8.0.300.0000.00818.77
8.0.290.0040.00417.00
8.0.280.0030.00318.40
8.0.270.0000.00717.02
8.0.260.0030.00317.32
8.0.250.0070.00017.16
8.0.240.0000.00717.12
8.0.230.0030.00317.18
8.0.220.0000.01117.04
8.0.210.0100.00016.95
8.0.200.0040.00417.07
8.0.190.0030.00617.13
8.0.180.0040.00417.11
8.0.170.0040.00417.13
8.0.160.0040.00417.11
8.0.150.0000.00917.05
8.0.140.0000.00716.94
8.0.130.0000.00713.50
8.0.120.0000.00817.08
8.0.110.0000.00817.00
8.0.100.0040.00417.06
8.0.90.0000.00817.15
8.0.80.0090.00617.08
8.0.70.0040.00416.95
8.0.60.0050.00317.02
8.0.50.0070.00017.03
8.0.30.0150.00617.32
8.0.20.0080.01217.40
8.0.10.0040.00417.09
8.0.00.0090.00816.81
7.4.330.0080.00017.26
7.4.320.0030.00617.20
7.4.300.0030.00317.09
7.4.290.0060.00617.02
7.4.280.0100.00317.05
7.4.270.0140.00016.93
7.4.260.0080.00317.10
7.4.250.0050.00317.00
7.4.240.0040.00417.08
7.4.230.0040.00416.91
7.4.220.0230.00716.96
7.4.210.0080.01017.17
7.4.200.0000.00717.02
7.4.160.0310.00316.95
7.4.150.0200.00717.40
7.4.140.0230.01017.86
7.4.130.0180.01117.12
7.4.120.0180.01117.20
7.4.110.0190.01117.02
7.4.100.0060.01217.20
7.4.90.0070.01417.14
7.4.80.0060.01519.39
7.4.70.0100.01716.98
7.4.60.0130.00917.17
7.4.50.0110.01117.05
7.4.40.0210.00717.07
7.4.30.0230.00617.19
7.4.00.0060.01115.24
7.3.330.0070.00713.86
7.3.320.0040.00814.25
7.3.310.0040.00416.98
7.3.300.0000.00716.77
7.3.290.0000.00716.94
7.3.280.0160.01217.01
7.3.270.0160.01317.40
7.3.260.0320.00416.96
7.3.250.0130.01116.99
7.3.240.0170.00917.10
7.3.230.0110.01816.97
7.3.210.0160.01016.99
7.3.200.0120.00917.21
7.3.190.0210.01217.04
7.3.180.0180.00517.08
7.3.170.0140.01016.94
7.3.160.0110.01516.93
7.3.120.0070.01014.92
7.3.110.0030.01615.32
7.3.100.0070.01015.20
7.3.90.0070.00315.21
7.3.80.0110.00715.11
7.3.70.0000.01515.05
7.3.60.0070.00315.00
7.3.50.0110.00715.10
7.3.40.0080.00815.02
7.3.30.0090.00615.18
7.3.20.0040.01416.87
7.3.10.0070.01016.70
7.3.00.0070.01016.75
7.2.330.0190.01117.58
7.2.320.0210.00717.28
7.2.310.0230.00817.32
7.2.300.0220.00416.91
7.2.290.0250.01117.07
7.2.250.0030.01615.54
7.2.240.0100.01015.15
7.2.230.0100.00315.59
7.2.220.0040.01115.21
7.2.210.0110.00315.30
7.2.200.0070.01115.28
7.2.190.0070.00315.39
7.2.180.0100.01015.32
7.2.170.0080.00815.47
7.2.130.0090.00617.04
7.2.120.0000.01417.20
7.2.110.0060.00617.07
7.2.100.0090.00617.27
7.2.90.0070.00716.95
7.2.80.0030.01017.07
7.2.70.0130.00317.21
7.2.60.0060.01117.23
7.2.50.0030.00917.23
7.2.40.0070.00717.08
7.2.30.0030.00717.27
7.2.20.0050.00516.96
7.2.10.0000.01117.10
7.2.00.0130.00718.24
7.1.330.0000.01516.07
7.1.320.0070.00716.01
7.1.310.0030.00715.94
7.1.300.0070.00716.02
7.1.290.0070.01115.89
7.1.280.0100.00715.95
7.1.270.0060.01015.86
7.1.260.0070.00716.03
7.1.250.0070.01016.11
7.1.200.0030.01015.95
7.1.100.0000.01418.05
7.1.70.0000.01017.36
7.1.60.0030.02319.36
7.1.50.0100.01317.00
7.1.00.0030.08022.57
7.0.200.0030.00617.00
7.0.60.0070.08320.11
7.0.50.0070.06017.84
7.0.40.0000.04720.11
7.0.30.0300.04020.29
7.0.20.0170.08720.16
7.0.10.0030.06020.17
7.0.00.0030.08720.06
5.6.280.0070.07020.86
5.6.210.0100.07320.69
5.6.200.0170.07318.30
5.6.190.0170.08020.59
5.6.180.0300.06720.52
5.6.170.0270.07720.72
5.6.160.0070.05020.71
5.6.150.0070.08018.27
5.6.140.0100.03318.27
5.6.130.0200.04718.29
5.6.120.0170.08321.04
5.6.110.0000.04321.05
5.6.100.0200.06021.02
5.6.90.0070.08021.08
5.6.80.0130.07320.42
5.5.350.0130.03320.34
5.5.340.0100.08318.00
5.5.330.0030.08720.13
5.5.320.0170.05320.35
5.5.310.0230.07320.24
5.5.300.0070.04018.00
5.5.290.0030.07718.07
5.5.280.0100.03721.00
5.5.270.0070.04320.80
5.5.260.0000.07020.80
5.5.250.0200.07020.63
5.5.240.0300.06720.30

preferences:
57.99 ms | 400 KiB | 5 Q