3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Period { protected $start; protected $end; public function __construct($start, $end) { $this->start = $start; $this->end = $end; } public function getStart() { return $this->start; } public function getEnd() { return $this->end; } public function containsTime($time) { return $this->start <= $time && $this->end > $time; } public function containsPeriod(Period $period) { return $this->containsTime($period->getStart()) && $this->containsTime($period->getEnd()); } public function overlaps(Period $period) { return $this->containsTime($period->getStart()) || $this->containsTime($period->getEnd()) || $period->containsTime($this->start); } public function intersect(Period $other) { $ts = $this->start; $os = $other->start; $te = $this->end; $oe = $other->end; if ($this->containsTime($os)) { $start = $os; } else if ($other->containsTime($ts)) { $start = $ts; } else { return null; } if ($this->containsTime($oe)) { $end = $oe; } else if ($other->containsTime($te)) { $end = $te; } else { return null; } return new Period($start, $end); } } class Availability { protected $periods; public function __construct($periods) { $this->periods = $periods; } public function getPeriods(Period $range) { return array_filter($this->periods, function ($period) use ($range) { return $range->intersect($period); }); } } function st($s) { return strtotime($s); } function pd($s1, $s2) { return new Period(st($s1), st($s2)); } function av() { $p = func_get_args(); $p = array_map(function ($p) { return pd($p[0], $p[1]); }, $p); return new Availability($p); } function strPeriod(Period $period) { return date('H:i:s . jS M y', $period->getStart()) . ' -- ' . date('H:i:s . jS M y', $period->getStart()); } function strResults($periods) { return implode(PHP_EOL, array_map('strPeriod', $periods)); } $availabilities = [ av( // Fridays between noon and 6pm ['2018-10-05 12:00:00', '2018-10-05 18:00:00'], ['2018-10-12 12:00:00', '2018-10-12 18:00:00'], ['2018-10-19 12:00:00', '2018-10-19 18:00:00'], ['2018-10-26 12:00:00', '2018-10-26 18:00:00'] ), av( // 15th till 19th full days ['2018-10-15 00:00:00', '2018-10-16 00:00:00'], ['2018-10-16 00:00:00', '2018-10-17 00:00:00'], ['2018-10-17 00:00:00', '2018-10-18 00:00:00'], ['2018-10-18 00:00:00', '2018-10-19 00:00:00'], ['2018-10-19 00:00:00', '2018-10-20 00:00:00'] ), av( // Wed 10th, Fri 19th and Wed 24th between 8am and 2pm ['2018-10-10 08:00:00', '2018-10-10 14:00:00'], ['2018-10-19 08:00:00', '2018-10-19 14:00:00'], ['2018-10-24 08:00:00', '2018-10-24 14:00:00'] ), ]; // Get periods for the whole month of October $periods = [ pd('2018-10-01 00:00:00', '2018-11-01 00:00:00') ]; foreach ($availabilities as $i => $avail) { printf('Availability #%d' . PHP_EOL, $i); echo str_repeat('-', 80) . PHP_EOL; $tPeriods = []; foreach ($periods as $period) { printf(' > Getting available periods in %s'.PHP_EOL, strPeriod($period)); $aPeriods = $avail->getPeriods($period); printf(' > Got %d periods', count($aPeriods)); $tPeriods = array_merge($tPeriods, $aPeriods); } $periods = $tPeriods; } echo str_repeat('=', 80) . PHP_EOL; echo 'RESULTS:' . PHP_EOL; echo strResults($periods);

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.00018.43
8.3.50.0040.01118.11
8.3.40.0120.00319.10
8.3.30.0070.00719.09
8.3.20.0040.00419.00
8.3.10.0040.00421.89
8.3.00.0050.00320.71
8.2.180.0180.00418.45
8.2.170.0080.00822.96
8.2.160.0070.01121.02
8.2.150.0000.00824.18
8.2.140.0030.00624.66
8.2.130.0050.00319.82
8.2.120.0050.00326.35
8.2.110.0100.00022.14
8.2.100.0090.00318.09
8.2.90.0030.00518.00
8.2.80.0050.00317.97
8.2.70.0060.00318.05
8.2.60.0050.00318.28
8.2.50.0040.00418.10
8.2.40.0000.00819.59
8.2.30.0040.00419.50
8.2.20.0040.00418.18
8.2.10.0040.00418.18
8.2.00.0050.00517.93
8.1.280.0140.00325.92
8.1.270.0030.00519.20
8.1.260.0040.00426.35
8.1.250.0000.00828.09
8.1.240.0030.00623.74
8.1.230.0070.00718.01
8.1.220.0000.00818.03
8.1.210.0000.01018.77
8.1.200.0030.00717.73
8.1.190.0090.00017.61
8.1.180.0050.00318.10
8.1.170.0000.00818.83
8.1.160.0050.00319.04
8.1.150.0000.00818.93
8.1.140.0040.00422.13
8.1.130.0030.00320.12
8.1.120.0000.00717.77
8.1.110.0000.00817.64
8.1.100.0040.00417.63
8.1.90.0050.00317.69
8.1.80.0030.00517.70
8.1.70.0000.00717.75
8.1.60.0060.00317.75
8.1.50.0060.00317.79
8.1.40.0030.00517.75
8.1.30.0040.00417.83
8.1.20.0000.00817.81
8.1.10.0000.00817.79
8.1.00.0000.00817.77
8.0.300.0040.00418.77
8.0.290.0030.00617.00
8.0.280.0070.00018.66
8.0.270.0030.00417.44
8.0.260.0030.00518.52
8.0.250.0030.00317.29
8.0.240.0030.00317.22
8.0.230.0040.00417.21
8.0.220.0040.00417.20
8.0.210.0030.00317.16
8.0.200.0000.00717.29
8.0.190.0000.00817.26
8.0.180.0000.00817.29
8.0.170.0000.00817.26
8.0.160.0070.00417.11
8.0.150.0040.00417.13
8.0.140.0000.00817.18
8.0.130.0000.00613.60
8.0.120.0000.00817.14
8.0.110.0030.00617.09
8.0.100.0000.00817.33
8.0.90.0040.00417.20
8.0.80.0080.00817.16
8.0.70.0000.00817.10
8.0.60.0030.00517.13
8.0.50.0050.00317.26
8.0.30.0120.00617.39
8.0.20.0080.01417.46
8.0.10.0040.00417.40
8.0.00.0150.00516.89
7.4.330.0050.00015.55
7.4.320.0000.00816.79
7.4.300.0070.00016.82
7.4.290.0030.00316.80
7.4.280.0080.00016.62
7.4.270.0040.00416.78
7.4.260.0040.00416.83
7.4.250.0000.00716.61
7.4.240.0040.00416.80
7.4.230.0040.00416.51
7.4.220.0050.00516.89
7.4.210.0080.00716.71
7.4.200.0000.00716.79
7.4.160.0090.00716.65
7.4.140.0080.01317.86
7.4.130.0090.00916.90
7.4.120.0110.00916.80
7.4.110.0070.01116.80
7.4.100.0120.00616.70
7.4.90.0130.01016.80
7.4.80.0090.01619.39
7.4.70.0100.01016.81
7.4.60.0110.00616.59
7.4.50.0170.00016.80
7.4.40.0060.01216.75
7.4.10.0030.01014.87
7.4.00.0070.01014.99
7.3.330.0000.00613.39
7.3.320.0050.00013.58
7.3.310.0090.00016.45
7.3.300.0070.00016.68
7.3.290.0050.00216.45
7.3.280.0050.01116.56
7.3.260.0090.01316.72
7.3.240.0100.01016.72
7.3.230.0150.00916.69
7.3.210.0040.01816.46
7.3.200.0150.00316.61
7.3.190.0030.01416.85
7.3.180.0070.01016.59
7.3.170.0090.00916.66
7.3.160.0110.00516.86
7.3.130.0070.01314.99
7.3.120.0070.01114.84
7.3.110.0070.01315.07
7.3.100.0030.01315.06
7.3.90.0040.01614.96
7.3.80.0090.00615.11
7.3.70.0030.01015.08
7.3.60.0100.00615.14
7.3.50.0110.00315.15
7.3.40.0000.01215.07
7.3.30.0070.00415.18
7.3.20.0120.00616.73
7.3.10.0070.01016.83
7.3.00.0040.01116.89
7.2.330.0090.00916.97
7.2.320.0120.01216.88
7.2.310.0030.01516.95
7.2.300.0100.00716.76
7.2.290.0150.01017.09
7.2.260.0070.01115.35
7.2.250.0060.01315.19
7.2.240.0070.00715.12
7.2.230.0060.01215.31
7.2.220.0140.00315.30
7.2.210.0090.00314.93
7.2.200.0100.00315.06
7.2.190.0060.00615.07
7.2.180.0130.00315.07
7.2.170.0030.00715.37
7.2.160.0070.01115.42
7.2.150.0140.00317.22
7.2.140.0060.01217.30
7.2.130.0000.01517.17
7.2.120.0080.00417.16
7.2.110.0070.01116.91
7.2.100.0030.01317.01
7.2.90.0030.01216.95
7.2.80.0000.01417.06
7.2.70.0030.01217.08
7.2.60.0070.00717.16
7.2.50.0080.00317.08
7.2.40.0080.00817.21
7.2.30.0100.00617.20
7.2.20.0030.01417.20
7.2.10.0090.00317.10
7.2.00.0070.01017.15
7.1.330.0140.00716.09
7.1.320.0080.00815.87
7.1.310.0000.01515.96
7.1.300.0080.00416.04
7.1.290.0000.01115.94
7.1.280.0000.01416.02
7.1.270.0030.01315.82
7.1.260.0040.00716.13
7.1.250.0030.01215.66
7.1.240.0060.00916.02
7.1.230.0000.01016.01
7.1.220.0080.00816.00
7.1.210.0030.00616.04
7.1.200.0000.00916.10
7.1.190.0000.01515.93
7.1.180.0060.00615.88
7.1.170.0070.01015.96
7.1.160.0030.01016.07
7.1.150.0070.01016.12
7.1.140.0060.00316.10
7.1.130.0040.01116.06
7.1.120.0070.00716.02
7.1.110.0000.01516.13
7.1.100.0100.00316.18
7.1.90.0000.01516.04
7.1.80.0030.01316.04
7.1.70.0090.00615.95
7.1.60.0120.00615.93
7.1.50.0090.00616.11
7.1.40.0060.01015.59
7.1.30.0060.00915.95
7.1.20.0000.00915.66
7.1.10.0030.01315.95
7.1.00.0040.01415.91
7.0.330.0060.00915.39
7.0.320.0000.01415.73
7.0.310.0040.00815.61
7.0.300.0080.00315.70
7.0.290.0000.01615.57
7.0.280.0000.01515.51
7.0.270.0040.00815.48
7.0.260.0030.00715.71
7.0.250.0060.01015.67
7.0.240.0090.00615.49
7.0.230.0000.01015.77
7.0.220.0100.00315.40
7.0.210.0080.00415.52
7.0.200.0060.01015.54
7.0.190.0070.01015.49
7.0.180.0000.01315.70
7.0.170.0090.00615.63
7.0.160.0120.00315.70
7.0.150.0000.01815.70
7.0.140.0110.00415.76
7.0.130.0040.00815.66
7.0.120.0100.00615.81
7.0.110.0030.00915.51
7.0.100.0030.01015.50
7.0.90.0100.00315.70
7.0.80.0070.00415.35
7.0.70.0040.00415.43
7.0.60.0000.01115.64
7.0.50.0090.00615.77
7.0.40.0060.01013.69
7.0.30.0000.00913.49
7.0.20.0060.00613.48
7.0.10.0000.01413.79
7.0.00.0110.00413.45
5.6.400.0080.00614.88
5.6.390.0080.00414.96
5.6.380.0120.00314.66
5.6.370.0130.00314.37
5.6.360.0000.01015.01
5.6.350.0110.00614.70
5.6.340.0110.00414.73
5.6.330.0060.00614.69
5.6.320.0040.00814.49
5.6.310.0060.00914.89
5.6.300.0000.01714.82
5.6.290.0000.01314.77
5.6.280.0030.00914.58
5.6.270.0100.00314.58
5.6.260.0060.00914.64
5.6.250.0060.00914.71
5.6.240.0090.00614.68
5.6.230.0120.00014.40
5.6.220.0030.00914.73
5.6.210.0160.00314.73
5.6.200.0000.01914.74
5.6.190.0080.00414.58
5.6.180.0000.01314.79
5.6.170.0070.00714.84
5.6.160.0070.01014.73
5.6.150.0070.00714.46
5.6.140.0040.00814.78
5.6.130.0040.01114.59
5.6.120.0000.00914.54
5.6.110.0070.01014.71
5.6.100.0030.01414.48
5.6.90.0030.01014.47
5.6.80.0060.00914.54
5.6.70.0030.01014.87
5.6.60.0030.00714.36
5.6.50.0000.01314.47
5.6.40.0030.00614.62
5.6.30.0030.01014.72
5.6.20.0130.00314.64
5.6.10.0060.01014.50
5.6.00.0000.01014.42

preferences:
59.47 ms | 400 KiB | 5 Q