3v4l.org

run code in 300+ PHP versions simultaneously
<?php class BusinessDaysCalculator { const MONDAY = 1; const TUESDAY = 2; const WEDNESDAY = 3; const THURSDAY = 4; const FRIDAY = 5; const SATURDAY = 6; const SUNDAY = 7; /** * @param DateTime $startDate Date to start calculations from * @param DateTime[] $holidays Array of holidays, holidays are no conisdered business days. * @param int[] $nonBusinessDays Array of days of the week which are not business days. */ public function __construct(DateTime $startDate, array $holidays, array $nonBusinessDays) { $this->date = $startDate; $this->holidays = $holidays; $this->nonBusinessDays = $nonBusinessDays; } public function addBusinessDays($howManyDays) { $i = 0; while ($i < $howManyDays) { $this->date->modify("+1 day"); if ($this->isBusinessDay($this->date)) { $i++; } } } public function getDate() { return $this->date; } private function isBusinessDay(DateTime $date) { if (in_array((int)$date->format('N'), $this->nonBusinessDays)) { return false; //Date is a nonBusinessDay. } foreach ($this->holidays as $day) { if ($date->format('d-m-Y') == $day->format('d-m-Y')) { return false; //Date is a holiday. } } return true; //Date is a business day. } } $calculator = new BusinessDaysCalculator( new DateTime(), // Today [new DateTime("01-06-2014"), new DateTime("02-06-2014")], [BusinessDaysCalculator::SATURDAY, BusinessDaysCalculator::FRIDAY] ); $calculator->addBusinessDays(4); // Add three business days var_dump($calculator->getDate());

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.0120.00318.56
8.3.50.0150.00616.45
8.3.40.0120.00419.01
8.3.30.0040.01118.98
8.3.20.0080.00021.85
8.3.10.0070.00021.77
8.3.00.0060.00319.02
8.2.180.0140.00718.54
8.2.170.0070.00722.96
8.2.160.0070.00722.09
8.2.150.0070.00024.18
8.2.140.0030.00524.66
8.2.130.0040.00422.20
8.2.120.0060.00326.35
8.2.110.0040.00422.17
8.2.100.0120.00017.91
8.2.90.0080.00019.33
8.2.80.0000.00818.05
8.2.70.0040.00417.63
8.2.60.0030.00618.18
8.2.50.0050.00318.18
8.2.40.0030.00520.67
8.2.30.0070.00019.29
8.2.20.0070.00018.19
8.2.10.0000.00718.27
8.2.00.0000.00718.27
8.1.270.0040.00424.04
8.1.260.0040.00426.35
8.1.250.0080.00028.09
8.1.240.0090.00022.62
8.1.230.0120.00019.22
8.1.220.0050.00317.74
8.1.210.0040.00418.77
8.1.200.0110.00317.60
8.1.190.0030.00617.60
8.1.180.0090.00018.10
8.1.170.0030.00518.84
8.1.160.0040.00419.15
8.1.150.0040.00420.88
8.1.140.0000.00719.77
8.1.130.0000.00717.63
8.1.120.0030.00717.67
8.1.110.0040.00417.71
8.1.100.0060.00317.75
8.1.90.0030.00517.60
8.1.80.0040.00417.70
8.1.70.0000.00717.62
8.1.60.0040.00417.67
8.1.50.0000.00817.76
8.1.40.0040.00417.63
8.1.30.0000.00817.82
8.1.20.0050.00317.79
8.1.10.0000.00817.80
8.1.00.0040.00417.70
8.0.300.0000.00720.27
8.0.290.0000.00716.88
8.0.280.0040.00418.57
8.0.270.0000.00717.43
8.0.260.0030.00317.18
8.0.250.0000.00717.30
8.0.240.0040.00417.32
8.0.230.0000.00717.34
8.0.220.0000.00717.13
8.0.210.0040.00417.32
8.0.200.0060.00317.18
8.0.190.0050.00517.26
8.0.180.0050.00217.22
8.0.170.0000.00717.18
8.0.160.0060.00317.21
8.0.150.0000.00817.18
8.0.140.0040.00317.18
8.0.130.0030.00313.61
8.0.120.0000.00717.21
8.0.110.0050.00317.26
8.0.100.0000.00717.29
8.0.90.0000.00717.27
8.0.80.0090.00617.23
8.0.70.0000.00717.23
8.0.60.0080.00017.24
8.0.50.0040.00417.07
8.0.30.0090.00817.42
8.0.20.0140.00717.45
8.0.10.0000.00717.47
8.0.00.0120.01217.20
7.4.330.0000.00615.55
7.4.320.0030.00316.73
7.4.300.0000.00816.68
7.4.290.0040.00716.70
7.4.280.0040.00416.71
7.4.270.0000.00716.79
7.4.260.0000.00613.46
7.4.250.0040.00416.61
7.4.240.0040.00316.65
7.4.230.0000.00716.71
7.4.220.0130.01016.89
7.4.210.0070.00716.76
7.4.200.0070.00016.85
7.4.160.0090.00816.82
7.4.150.0110.00917.40
7.4.140.0100.01017.86
7.4.130.0090.01516.68
7.4.120.0100.01016.83
7.4.110.0090.00916.80
7.4.100.0100.01316.75
7.4.90.0110.00716.89
7.4.80.0130.00319.39
7.4.70.0120.00416.75
7.4.60.0170.00016.77
7.4.50.0030.01316.72
7.4.40.0100.00716.65
7.4.30.0090.00916.64
7.4.00.0030.01215.02
7.3.330.0030.00313.47
7.3.320.0050.00013.54
7.3.310.0030.00316.34
7.3.300.0060.00316.50
7.3.290.0150.00516.53
7.3.280.0080.00916.50
7.3.270.0090.00917.40
7.3.260.0130.00616.72
7.3.250.0130.00916.71
7.3.240.0100.00716.60
7.3.230.0070.01116.80
7.3.210.0130.00616.47
7.3.200.0140.00916.60
7.3.190.0060.01016.50
7.3.180.0120.00616.79
7.3.170.0100.00716.82
7.3.160.0060.01016.66
7.3.10.0150.00816.78
7.3.00.0170.00916.66
7.2.330.0060.01116.75
7.2.320.0140.00616.91
7.2.310.0130.00316.86
7.2.300.0120.01216.85
7.2.290.0040.01816.88
7.2.130.0170.00717.13
7.2.120.0070.01017.01
7.2.110.0130.00816.68
7.2.100.0130.00817.05
7.2.90.0120.00717.04
7.2.80.0190.00316.77
7.2.70.0140.00617.07
7.2.60.0120.00716.91
7.2.50.0060.01217.04
7.2.40.0170.00316.99
7.2.30.0100.01016.81
7.2.20.0120.01216.96
7.2.10.0130.00916.97
7.2.00.0070.01018.43
7.1.250.0130.00015.91
7.1.200.0000.01416.17
7.1.70.0000.01117.52
7.1.60.0700.01733.48
7.1.50.0600.01733.18
7.1.40.0600.01332.73
7.1.30.0570.02332.96
7.1.20.0430.02033.12
7.1.10.0470.01714.88
7.1.00.0470.01315.09
7.0.200.1000.01014.88
7.0.190.0430.01015.14
7.0.180.0430.01014.63
7.0.170.0400.01014.75
7.0.160.0470.01014.54
7.0.150.0500.00314.80
7.0.140.0830.00714.61
7.0.130.0430.01714.77
7.0.120.0370.01314.88
7.0.110.0430.01314.69
7.0.100.0530.01714.38
7.0.90.0370.00314.84
7.0.80.0370.01014.77
7.0.70.0400.01014.70
7.0.60.0430.01014.60
7.0.50.0400.00314.55
7.0.40.0430.01015.00
7.0.30.0570.01714.66
7.0.20.0570.00714.84
7.0.10.0400.01014.93
7.0.00.0430.01314.84

preferences:
49.9 ms | 400 KiB | 5 Q