@ 2020-09-06T15:26:35Z <?php
error_reporting(E_ALL);
ini_set('display_startup_errors', 1);
ini_set('display_errors', 1);
function getFillNotion(\DateTimeImmutable $fillStart, \DateTimeImmutable $fillEnd, \DateTimeInterface $gapStart, \DateTimeInterface $gapEnd)
{
//$gapInterval = $gapStart->diff($gapEnd); // Doesn't work
$gapInterval = new \DateInterval('PT'.($gapEnd->getTimestamp() - $gapStart->getTimestamp()).'S');
if($gapStart > $fillStart) {
//The fill is older than the gap so make the fill's endTime match the gap's endTime
$fillEndModified = $fillEnd
->modify('previous '.$gapEnd->format('D'))
->setTime(...explode('.', $gapEnd->format('H.i.s.u')));
if($fillEndModified->diff($fillEnd)->format('%a') >= 7) {
$fillEndModified = $fillEndModified->add(new \DateInterval('P7D'));
}
$fillStartModified = $fillEndModified->sub($gapInterval);
if($fillStartModified < $fillStart) {
return [];
}
}
else {
//The fill is newer than the gap so make the fill's startTime match the gap's startTime
$fillStartModified = $fillStart
->modify('next '.$gapStart->format('D'))
->setTime(...explode('.', $gapStart->format('H.i.s.u')));
if($fillStart->diff($fillStartModified)->format('%a') >= 7) {
$fillStartModified = $fillStartModified->sub(new \DateInterval('P7D'));
}
$fillEndModified = $fillStartModified->add($gapInterval);
if($fillEndModified > $fillEnd) {
return [];
}
}
return [$fillStartModified, $fillEndModified];
}
function getFillRequinix(\DateTime $fillStart, \DateTime $fillEnd, \DateTime $gapStart, \DateTime $gapEnd)
{
//
// being with the original start
$fillStartModified = clone $fillStart;
// move to the next weekday and time
$wdtStart = $gapStart->format("l H:i:s");
if ($fillStartModified->format("l H:i:s") != $wdtStart) {
$fillStartModified->modify("next {$wdtStart}");
}
// get the duration, minus a bit so we can do a "next <day>" after
$days = $gapStart->diff($gapEnd)->days - 1;
// get the weekday and time
$wdtEnd = $gapEnd->format("l H:i:s");
// update
$fillEndModified = clone $fillStartModified;
$fillEndModified->modify("+${days} days");
$fillEndModified->modify("next {$wdtEnd}");
return $fillStartModified < $fillStart || $fillEndModified > $fillEnd?[]:[$fillStartModified, $fillEndModified];
}
function isDifferent(?DateTimeInterface $requinix, $notion) {
if($requinix xor $notion) {
return true;
}
elseif(!$requinix && !$notion) {
return false;
}
else {
return $requinix->getTimestamp() !== $notion->getTimestamp();
}
}
/*
Fill Sunday 2019-02-17 08:09:53 -> Saturday 2019-04-06 19:09:48
Gap Sunday 2019-04-14 20:33:00 -> Tuesday 2019-05-28 10:05:28
*/
$max = 800*24*60*60;
$int = 80*24*60*60;
$score = ['requinix'=>0, 'notion'=>0, 'tie'=>0, 'nofill'=>0];
for ($i = 0; $i < 10000; $i++) {
$fillEnd = time()-rand(0, $max);
$fillStart = $fillEnd-rand(0, $int);
$gapEnd = time()-rand(0, $max);
$gapStart = $gapEnd-rand(0, $int);
$fillEnd = new DateTime("@$fillEnd");
$fillStart = new DateTime("@$fillStart");
$gapEnd = new DateTime("@$gapEnd");
$gapStart = new DateTime("@$gapStart");
$fillRequinix = getFillRequinix($fillStart, $fillEnd, $gapStart, $gapEnd);
$fillNotion = getFillNotion(DateTimeImmutable::createFromMutable( $fillStart ), DateTimeImmutable::createFromMutable( $fillEnd ), $gapStart, $gapEnd);
if($fillRequinix && $fillNotion) {
$gapStartTimestamp = $gapStart->getTimestamp();
$fillRequinixOffset = abs($gapStartTimestamp - $fillRequinix[0]->getTimestamp());
$fillNotionOffset = abs($gapStartTimestamp - $fillNotion[0]->getTimestamp());
if($fillRequinixOffset === $fillNotionOffset) {
$score['tie']++;
}
elseif($fillRequinixOffset<$fillNotionOffset) {
$score['requinix']++;
}
else {
$score['notion']++;
}
}
elseif($fillRequinix) {
$score['requinix']++;
}
elseif($fillNotion) {
$score['notion']++;
}
else {
$score['nofill']++;
}
}
$score['total'] = array_sum($score);
print_r($score);
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
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).
Version System time (s) User time (s) Memory (MiB) 7.4.10 0.016 0.300 16.89 7.4.9 0.009 0.404 16.64 7.4.8 0.012 0.303 16.79 7.4.7 0.020 0.302 16.71 7.4.6 0.006 0.296 16.88 7.4.5 0.016 0.310 16.86 7.4.4 0.013 0.324 16.90 7.4.3 0.007 0.314 16.79 7.4.2 0.009 0.322 16.81 7.4.1 0.006 0.315 16.71 7.4.0 0.006 0.317 16.64 7.3.22 0.016 0.325 16.87 7.3.21 0.013 0.314 16.74 7.3.20 0.009 0.295 17.01 7.3.19 0.010 0.303 16.57 7.3.18 0.009 0.330 16.68 7.3.17 0.013 0.300 16.69 7.3.16 0.016 0.308 16.62 7.3.15 0.016 0.305 16.89 7.3.14 0.007 0.301 16.64 7.3.13 0.007 0.307 16.85 7.3.12 0.019 0.309 16.64 7.3.11 0.017 0.289 16.73 7.3.10 0.013 0.298 16.53 7.3.9 0.016 0.340 16.53 7.3.8 0.007 0.504 16.63 7.3.7 0.019 0.302 16.71 7.3.6 0.013 0.314 16.58 7.3.5 0.007 0.359 16.57 7.3.4 0.013 0.316 16.67 7.3.3 0.019 0.299 16.73 7.3.2 0.016 0.298 16.61 7.3.1 0.010 0.323 16.72 7.3.0 0.075 0.313 16.63 7.2.33 0.016 0.310 17.09 7.2.32 0.018 0.355 17.01 7.2.31 0.007 0.317 16.95 7.2.30 0.013 0.304 17.11 7.2.29 0.010 0.351 17.16 7.2.28 0.013 0.387 17.11 7.2.27 0.010 0.319 16.95 7.2.26 0.003 0.302 17.05 7.2.25 0.007 0.323 17.00 7.2.24 0.007 0.297 16.73 7.2.23 0.013 0.307 16.89 7.2.22 0.000 0.323 16.77 7.2.21 0.015 0.342 16.84 7.2.20 0.016 0.322 17.05 7.2.19 0.003 0.316 16.96 7.2.18 0.016 0.318 16.86 7.2.17 0.013 0.336 16.94 7.2.16 0.017 0.337 16.95 7.2.15 0.010 0.322 16.90 7.2.14 0.016 0.301 16.95 7.2.13 0.010 0.312 16.95 7.2.12 0.013 0.368 17.02 7.2.11 0.016 0.311 17.00 7.2.10 0.016 0.304 16.85 7.2.9 0.010 0.318 16.94 7.2.8 0.007 0.526 16.96 7.2.7 0.017 0.457 17.16 7.2.6 0.016 0.376 16.97 7.2.5 0.019 0.351 16.93 7.2.4 0.006 0.348 17.00 7.2.3 0.016 0.520 17.12 7.2.2 0.007 0.340 16.98 7.2.1 0.003 0.324 17.04 7.2.0 0.003 0.362 16.84
preferences:dark mode live preview
33.73 ms | 401 KiB | 5 Q