day00: Add template
parent
4d9e5cca8a
commit
74b642837c
|
@ -0,0 +1 @@
|
|||
|
|
@ -0,0 +1 @@
|
|||
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
require_once(__DIR__.'/../lib/functions.php');
|
||||
|
||||
$entries = getLines(__DIR__.'/'.$argv[1].'.txt');
|
||||
|
||||
timedPrintf(
|
||||
'[2021-12-00.1] DESCRIPTION: %d [Time: %ss]',
|
||||
(function (array $entries) : int {
|
||||
return 1;
|
||||
}),
|
||||
$entries
|
||||
);
|
||||
|
||||
timedPrintf(
|
||||
'[2021-12-00.2] DESCRIPTION: %d [Time: %ss]',
|
||||
(function (array $entries) : int {
|
||||
return 1;
|
||||
}),
|
||||
$entries
|
||||
);
|
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
function getLines(string $filename, bool $filter = true) : array
|
||||
{
|
||||
$fileContents = file_get_contents($filename);
|
||||
$lines = explode(PHP_EOL, $fileContents);
|
||||
|
||||
return $filter ? array_filter($lines) : $lines;
|
||||
}
|
||||
|
||||
function timedPrintf(string $format, callable $fn, array $args) : void
|
||||
{
|
||||
$timeBefore = microtime(true);
|
||||
$result = $fn($args);
|
||||
$timeAfter = microtime(true);
|
||||
|
||||
printf(
|
||||
$format.PHP_EOL,
|
||||
$result,
|
||||
$timeAfter - $timeBefore,
|
||||
);
|
||||
}
|
Loading…
Reference in New Issue