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; /** * DateTime $startDate Date to start calculations from * DateTime[] $holidays Array of holidays, holidays are no conisdered business days. * 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) { $date->modify("+1 day"); if ($this->isBusinessDay($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->nonBusinessDays as $day) { if ($date->format('Y-m-d') == $day->format('Y-m-d')) { return false; //Date is a holiday. } } return true; //Date is a business day. } } $calculator = new BusinessDaysCalculator( new DateTime(), // Today [new DateTime("2014-06-01"), new DateTime("2014-06-02")], [BusinessDaysCalculator::SATURDAY, BusinessDaysCalculator::FRIDAY] ); $calculator->addBusinessDays(3); // 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.0100.00718.66
8.3.50.0100.00722.10
8.3.40.0120.00318.92
8.3.30.0050.00919.26
8.3.20.0090.00020.29
8.3.10.0000.00823.64
8.3.00.0000.00819.41
8.2.180.0180.00417.00
8.2.170.0110.00722.96
8.2.160.0160.00320.39
8.2.150.0000.00824.18
8.2.140.0000.00824.66
8.2.130.0080.00026.16
8.2.120.0060.00322.16
8.2.110.0040.00720.97
8.2.100.0030.00918.03
8.2.90.0050.00319.35
8.2.80.0060.00317.97
8.2.70.0100.00017.75
8.2.60.0000.00917.93
8.2.50.0040.00418.07
8.2.40.0050.00320.01
8.2.30.0040.00418.02
8.2.20.0080.00017.86
8.2.10.0030.00718.13
8.2.00.0080.00317.92
8.1.280.0140.00025.92
8.1.270.0080.00023.80
8.1.260.0080.00026.35
8.1.250.0040.00428.09
8.1.240.0000.00922.10
8.1.230.0110.00019.01
8.1.220.0030.00517.74
8.1.210.0000.00918.77
8.1.200.0030.00717.61
8.1.190.0040.00417.66
8.1.180.0060.00318.10
8.1.170.0000.00818.70
8.1.160.0000.00722.04
8.1.150.0040.00418.82
8.1.140.0050.00217.65
8.1.130.0050.00217.78
8.1.120.0050.00317.71
8.1.110.0000.00817.62
8.1.100.0070.00017.59
8.1.90.0000.00817.70
8.1.80.0030.00517.64
8.1.70.0030.00317.59
8.1.60.0000.00817.72
8.1.50.0000.00817.61
8.1.40.0040.00417.66
8.1.30.0040.00417.72
8.1.20.0000.00717.86
8.1.10.0070.00017.64
8.1.00.0000.00717.74
8.0.300.0040.00418.77
8.0.290.0040.00417.18
8.0.280.0000.00718.44
8.0.270.0000.00817.40
8.0.260.0040.00417.25
8.0.250.0000.00717.11
8.0.240.0000.00717.21
8.0.230.0030.00317.20
8.0.220.0000.00717.19
8.0.210.0070.00017.17
8.0.200.0030.00317.18
8.0.190.0030.00317.09
8.0.180.0030.00317.18
8.0.170.0080.00017.09
8.0.160.0020.00517.20
8.0.150.0050.00217.21
8.0.140.0040.00417.08
8.0.130.0030.00613.46
8.0.120.0000.00817.04
8.0.110.0030.00517.07
8.0.100.0050.00317.18
8.0.90.0030.00517.09
8.0.80.0130.00317.11
8.0.70.0040.00417.17
8.0.60.0040.00417.22
8.0.50.0000.00717.02
8.0.30.0080.01517.31
8.0.20.0080.01217.40
8.0.10.0040.00417.15
8.0.00.0110.01016.88
7.4.330.0050.00015.16
7.4.320.0030.00316.66
7.4.300.0000.00616.78
7.4.290.0050.00316.73
7.4.280.0030.00716.63
7.4.270.0070.00016.73
7.4.260.0000.00716.77
7.4.250.0040.00416.60
7.4.240.0040.00416.67
7.4.230.0060.00016.72
7.4.220.0090.00916.71
7.4.210.0120.00416.73
7.4.200.0000.00916.58
7.4.190.0040.00416.64
7.4.160.0150.00016.56
7.4.150.0100.00717.40
7.4.140.0080.01017.86
7.4.130.0060.01116.59
7.4.120.0120.00616.70
7.4.110.0090.00916.78
7.4.100.0150.01117.00
7.4.90.0110.00816.62
7.4.80.0030.01819.39
7.4.70.0060.01016.80
7.4.60.0030.01316.82
7.4.50.0000.00716.40
7.4.40.0030.00922.77
7.4.30.0060.00916.54
7.4.00.0030.01014.98
7.3.330.0030.00313.32
7.3.320.0050.00013.43
7.3.310.0050.00316.36
7.3.300.0030.00316.38
7.3.290.0090.01216.56
7.3.280.0080.01016.56
7.3.270.0100.01017.40
7.3.260.0110.00716.81
7.3.250.0120.00816.61
7.3.240.0090.00916.68
7.3.230.0070.01216.46
7.3.210.0070.01416.48
7.3.200.0140.00419.39
7.3.190.0060.01616.71
7.3.180.0090.00916.71
7.3.170.0110.00616.69
7.3.160.0100.00716.71
7.3.120.0040.01115.20
7.2.330.0150.00416.77
7.2.320.0120.00916.88
7.2.310.0120.01216.80
7.2.300.0120.00616.87
7.2.290.0160.00716.72
7.2.60.0030.01216.74
7.2.00.0000.01419.73
7.1.200.0060.00615.83
7.1.100.0040.00418.07
7.1.70.0030.00917.43
7.1.60.0040.02119.46
7.1.50.0060.00617.12
7.1.00.0070.07322.48
7.0.200.0000.00716.92
7.0.140.0000.07722.15
7.0.110.0300.03719.89
7.0.100.0030.04720.04
7.0.90.0330.03720.04
7.0.80.0300.04319.87
7.0.70.0070.04019.94
7.0.60.0400.03720.06
7.0.50.0430.04319.98
7.0.40.0030.06319.79
7.0.30.0000.04719.77
7.0.20.0030.03719.79
7.0.10.0030.05319.75
7.0.00.0030.03719.71
5.6.280.0000.07721.08
5.6.260.0070.03320.75
5.6.250.0030.04320.66
5.6.240.0000.04020.64
5.6.230.0030.06320.70
5.6.220.0030.03720.55
5.6.210.0030.04020.62
5.6.200.0070.04020.66
5.6.190.0100.06020.70
5.6.180.0100.03720.63
5.6.170.0000.07020.63
5.6.160.0000.03720.60
5.6.150.0100.02720.86
5.6.140.0070.04020.86
5.6.130.0070.03020.65
5.6.120.0030.04320.71
5.6.110.0070.06020.66
5.6.100.0070.07020.46
5.6.90.0030.07720.67
5.6.80.0030.05320.00
5.6.70.0030.03719.94
5.6.60.0070.03719.93
5.6.50.0070.06020.00
5.6.40.0000.04319.99
5.6.30.0030.03320.01
5.6.20.0130.03019.93
5.6.10.0070.03719.95
5.6.00.0130.03020.01
5.5.380.0000.04317.48
5.5.370.0030.04017.70
5.5.360.0030.03317.68
5.5.350.0030.03717.68
5.5.340.0000.04318.09
5.5.330.0130.03718.25
5.5.320.0100.04018.07
5.5.310.0030.04018.09
5.5.300.0070.06017.94
5.5.290.0030.04317.91
5.5.280.0000.03718.09
5.5.270.0070.04718.22
5.5.260.0000.04318.21
5.5.250.0030.05017.72
5.5.240.0130.03017.64
5.5.230.0100.03317.30
5.5.220.0070.06717.30
5.5.210.0000.03717.48
5.5.200.0000.05317.40
5.5.190.0070.03317.42
5.5.180.0030.04017.28
5.5.160.0070.03717.45
5.5.150.0070.03017.32
5.5.140.0070.03717.46
5.5.130.0070.03317.39
5.5.120.0030.03717.44
5.5.110.0030.03317.41
5.5.100.0070.03317.39
5.5.90.0100.02717.19
5.5.80.0070.03717.32
5.5.70.0100.03317.16
5.5.60.0030.03717.36
5.5.50.0070.03317.37
5.5.40.0030.03017.34
5.5.30.0000.03317.48
5.5.20.0000.03317.15
5.5.10.0070.03317.33
5.5.00.0070.03317.33
5.4.450.0000.04319.49
5.4.440.0100.03719.64
5.4.430.0100.03719.52
5.4.420.0070.04719.33
5.4.410.0100.03319.38
5.4.400.0100.04019.20
5.4.390.0000.04019.19
5.4.380.0030.04019.02
5.4.370.0100.03718.95
5.4.360.0000.03318.99
5.4.350.0170.02718.99
5.4.340.0030.04019.02
5.4.320.0000.03319.02
5.4.310.0070.05019.09
5.4.300.0000.04319.24
5.4.290.0070.03719.16
5.4.280.0130.03018.95
5.4.270.0030.03718.98
5.4.260.0070.04719.21
5.4.250.0000.03719.33
5.4.240.0100.03019.03
5.4.230.0070.07319.00
5.4.220.0000.03719.03
5.4.210.0030.03719.13
5.4.200.0100.02719.00
5.4.190.0070.03319.07
5.4.180.0030.04019.01
5.4.170.0070.03719.07
5.4.160.0030.03719.01
5.4.150.0000.03719.14
5.4.140.0070.04716.60
5.4.130.0030.03716.42
5.4.120.0000.03316.52
5.4.110.0070.03016.61
5.4.100.0070.03016.48
5.4.90.0070.02716.31
5.4.80.0070.02716.54
5.4.70.0100.02316.40
5.4.60.0070.02716.55
5.4.50.0100.04016.29
5.4.40.0070.02716.58
5.4.30.0030.03016.41
5.4.20.0030.03016.47
5.4.10.0000.03716.38
5.4.00.0000.06716.00
5.3.290.0000.03314.70
5.3.280.0030.03714.60
5.3.270.0000.04014.72
5.3.260.0000.04014.70
5.3.250.0030.03314.63
5.3.240.0000.04014.64
5.3.230.0030.03314.59
5.3.220.0000.04714.57
5.3.210.0030.03314.70
5.3.200.0030.03014.72
5.3.190.0000.03714.57
5.3.180.0030.03714.68
5.3.170.0100.02314.57
5.3.160.0030.03014.71
5.3.150.0000.03314.65
5.3.140.0070.03314.71
5.3.130.0000.04014.53
5.3.120.0000.03314.58
5.3.110.0070.02714.64
5.3.100.0030.03314.05
5.3.90.0000.03714.03
5.3.80.0030.03714.25
5.3.70.0070.02714.05
5.3.60.0030.03314.24
5.3.50.0030.03313.96
5.3.40.0000.03314.03
5.3.30.0070.03713.98
5.3.20.0030.02713.70
5.3.10.0030.02713.66
5.3.00.0000.03713.71
5.2.170.0000.03012.04
5.2.160.0000.02712.04
5.2.150.0070.02712.04
5.2.140.0000.03012.04
5.2.130.0030.02312.04
5.2.120.0000.03312.04
5.2.110.0000.02712.04
5.2.100.0070.04712.04
5.2.90.0030.05312.04
5.2.80.0030.04312.04
5.2.70.0000.02712.04
5.2.60.0000.02712.04
5.2.50.0000.02712.04
5.2.40.0000.02712.04
5.2.30.0030.02712.04
5.2.20.0030.02312.04
5.2.10.0030.02312.04
5.2.00.0030.02712.04
5.1.60.0070.02012.04
5.1.50.0070.01712.04
5.1.40.0030.02012.04
5.1.30.0000.02312.04
5.1.20.0000.02312.04
5.1.10.0000.02312.04
5.1.00.0030.02012.04
5.0.50.0030.02012.04
5.0.40.0030.02012.04
5.0.30.0000.02712.04
5.0.20.0000.01712.04
5.0.10.0030.02012.04
5.0.00.0030.02712.04
4.4.90.0000.01312.04
4.4.80.0000.01312.04
4.4.70.0030.01012.04
4.4.60.0030.01012.04
4.4.50.0000.01312.04
4.4.40.0030.02012.04
4.4.30.0000.01312.04
4.4.20.0000.01312.04
4.4.10.0030.01312.04
4.4.00.0000.02012.04
4.3.110.0030.01012.04
4.3.100.0000.01312.04
4.3.90.0030.03012.04
4.3.80.0000.02012.04
4.3.70.0000.01712.04
4.3.60.0000.02012.04
4.3.50.0000.02712.04
4.3.40.0030.02312.04
4.3.30.0030.02012.04
4.3.20.0000.01312.04
4.3.10.0030.01012.04
4.3.00.0000.01312.04

preferences:
43.15 ms | 401 KiB | 5 Q