3v4l.org

run code in 300+ PHP versions simultaneously
<?php ini_set('display_errors', 'on'); define('DAY_WORK', 32400); // 9 * 60 * 60 define('HOUR_START_DAY', '08:30:00'); define('HOUR_END_DAY', '18:00:00'); // get begin and end dates of the full period $date_begin = '2015-10-02 08:00:00'; $date_end = '2015-10-04 18:00:00'; // keep the initial dates for later use $d1 = new DateTime($date_begin); $d2 = new DateTime($date_end); // and get the datePeriod from the 1st to the last day $period_start = new DateTime($d1->format('Y-m-d 00:00:00')); $period_end = new DateTime($d2->format('Y-m-d 23:59:59')); $interval = new DateInterval('P1D'); //$interval = new DateInterval('weekdays'); // 1 day interval to get all days between the period $period = new DatePeriod($period_start, $interval, $period_end); $worked_time = 0; $nb = 0; // for every worked day, add the hours you want foreach($period as $date){ $week_day = $date->format('w'); // 0 (for Sunday) through 6 (for Saturday) if (!in_array($week_day,array(0, 6))) { // if this is the first day or the last dy, you have to count only the worked hours if ($date->format('Y-m-d') == $d1->format('Y-m-d')) { $end_of_day_format = $date->format('Y-m-d '.HOUR_END_DAY); $d1_format = $d1->format('Y-m-d H:i:s'); $end_of_day = new DateTime($end_of_day_format); $diff = $end_of_day->diff($d1)->format("%H:%I:%S"); $diff = split(':', $diff); $diff = $diff[0]*3600 + $diff[1]*60 + $diff[0]; $worked_time += $diff; } else if ($date->format('Y-m-d') == $d2->format('Y-m-d')) { $start_of_day = new DateTime($date->format('Y-m-d '.HOUR_START_DAY)); $d2_format = $d2->format('Y-m-d H:i:s'); $end_of_day = new DateTime($end_of_day_format); $diff = $start_of_day->diff($d2)->format('%H:%I:%S'); $diff = split(':', $diff); $diff = $diff[0]*3600 + $diff[1]*60 + $diff[0]; $worked_time += $diff; } else { // otherwise, just count the full day of work $worked_time += DAY_WORK; } } if ($nb> 10) die("die ".$nb); } echo sprintf('Works from %s to %s, You worked %d hour(s)', $date_begin, $date_end, $worked_time/60/60);

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.0060.01216.98
8.3.50.0130.01018.18
8.3.40.0150.00319.00
8.3.30.0070.00719.00
8.3.20.0000.00820.20
8.3.10.0060.00323.61
8.3.00.0030.00517.75
8.2.180.0190.00318.32
8.2.170.0030.01322.96
8.2.160.0130.00620.52
8.2.150.0080.00024.18
8.2.140.0000.00824.66
8.2.130.0000.00826.16
8.2.120.0060.00317.75
8.2.110.0030.00722.25
8.2.100.0030.00917.80
8.2.90.0000.00819.34
8.2.80.0000.00817.97
8.2.70.0000.00817.88
8.2.60.0060.00317.80
8.2.50.0030.00518.07
8.2.40.0060.00319.11
8.2.30.0040.00420.77
8.2.20.0040.00417.89
8.2.10.0040.00418.26
8.2.00.0040.00418.25
8.1.270.0040.00423.83
8.1.260.0080.00026.35
8.1.250.0030.00628.09
8.1.240.0000.00922.70
8.1.230.0040.00817.68
8.1.220.0040.00417.80
8.1.210.0000.00818.77
8.1.200.0090.00317.72
8.1.190.0040.00417.38
8.1.180.0000.00818.10
8.1.170.0040.00418.99
8.1.160.0000.00722.15
8.1.150.0000.00719.02
8.1.140.0000.00819.71
8.1.130.0070.00017.80
8.1.120.0040.00417.74
8.1.110.0040.00417.73
8.1.100.0000.00717.62
8.1.90.0040.00417.59
8.1.80.0060.00317.60
8.1.70.0000.00717.65
8.1.60.0000.01117.80
8.1.50.0040.00417.72
8.1.40.0060.00317.76
8.1.30.0000.00817.80
8.1.20.0040.00417.82
8.1.10.0040.00417.77
8.1.00.0040.00817.73
8.0.300.0050.00218.77
8.0.290.0000.00717.13
8.0.280.0000.00718.60
8.0.270.0040.00417.46
8.0.260.0000.00617.40
8.0.250.0040.00417.17
8.0.240.0000.00817.25
8.0.230.0030.00317.36
8.0.220.0050.00217.18
8.0.210.0040.00417.09
8.0.200.0030.00617.24
8.0.190.0040.00417.31
8.0.180.0040.00417.14
8.0.170.0000.00817.22
8.0.160.0000.00717.12
8.0.150.0050.00317.16
8.0.140.0000.00717.13
8.0.130.0000.00613.57
8.0.120.0030.00617.20
8.0.110.0050.00217.23
8.0.100.0050.00317.26
8.0.90.0030.00317.17
8.0.80.0030.01217.21
8.0.70.0030.00517.15
8.0.60.0040.00417.11
8.0.50.0040.00417.08
8.0.30.0080.01117.48
8.0.20.0090.01017.46
8.0.10.0080.00017.37
8.0.00.0110.01116.96
7.4.330.0020.00215.08
7.4.320.0060.00016.66
7.4.300.0030.00316.63
7.4.290.0000.00716.71
7.4.280.0060.00516.60
7.4.270.0000.00716.70
7.4.260.0000.01016.79
7.4.250.0000.00716.76
7.4.240.0060.00216.78
7.4.230.0000.00716.54
7.4.220.0140.01116.63
7.4.210.0060.00916.80
7.4.200.0040.00316.51
7.4.160.0070.01516.53
7.4.150.0150.00317.40
7.4.140.0150.00417.86
7.4.130.0080.00916.73
7.4.120.0090.01216.73
7.4.110.0080.00916.92
7.4.100.0120.01216.89
7.4.90.0100.00616.82
7.4.80.0110.00719.39
7.4.70.0090.00916.62
7.4.60.0140.01016.79
7.4.50.0080.00016.95
7.4.40.0070.01016.96
7.4.30.0060.01116.57
7.4.00.0030.01315.36
7.3.330.0060.00013.27
7.3.320.0000.00513.38
7.3.310.0030.00316.55
7.3.300.0070.00016.52
7.3.290.0000.00816.51
7.3.280.0090.00716.55
7.3.270.0070.01017.40
7.3.260.0070.01016.84
7.3.250.0110.00716.67
7.3.240.0080.01016.55
7.3.230.0180.00416.76
7.3.210.0090.00916.68
7.3.200.0530.01017.00
7.3.190.0070.01016.61
7.3.180.0120.00616.63
7.3.170.0100.01016.57
7.3.160.0110.00516.66
7.2.330.0140.00616.98
7.2.320.0140.00717.07
7.2.310.0120.00616.71
7.2.300.0090.00917.11
7.2.290.0030.01616.85
7.2.60.0000.01717.06
7.2.00.0120.00919.30
7.1.200.0080.00815.60
7.1.100.0000.01118.48
7.1.70.0070.00016.79
7.1.60.0110.01519.43
7.1.50.0100.01316.82
7.1.00.0000.08022.44
7.0.200.0320.00414.77
7.0.60.0070.08719.97
7.0.50.0070.03717.98
7.0.40.0000.08020.10
7.0.30.0170.08720.09
7.0.20.0400.07320.09
7.0.10.0100.08020.17
7.0.00.0030.04020.18
5.6.280.0070.03021.15
5.6.210.0100.06020.50
5.6.200.0070.08718.13
5.6.190.0000.05020.61
5.6.180.0170.04020.55
5.6.170.0100.04720.48
5.6.160.0130.08020.46
5.6.150.0130.05318.13
5.6.140.0130.03718.10
5.6.130.0000.05318.09
5.6.120.0070.05020.91
5.6.110.0030.07321.01
5.6.100.0130.05321.03
5.6.90.0130.08321.02
5.6.80.0100.08020.39
5.5.350.0170.04320.44
5.5.340.0030.07317.89
5.5.330.0070.07020.21
5.5.320.0270.07020.30
5.5.310.0200.04320.30
5.5.300.0070.04017.91
5.5.290.0030.04717.98
5.5.280.0100.06320.79
5.5.270.0100.06720.91
5.5.260.0100.05720.66
5.5.250.0000.07320.63
5.5.240.0000.08020.21

preferences:
56.69 ms | 400 KiB | 5 Q