2023-12-08 15:31:44 +00:00
|
|
|
use 5.38.0;
|
|
|
|
|
|
|
|
use Benchmark ':hireswallclock';
|
|
|
|
use Path::Tiny;
|
|
|
|
use JSON qw/ to_json /;
|
|
|
|
use DateTime;
|
|
|
|
use File::Serialize;
|
|
|
|
|
|
|
|
use Part1;
|
|
|
|
use Part2;
|
|
|
|
|
2023-12-08 15:35:08 +00:00
|
|
|
my $day = path('.')->absolute->basename =~ s/^0//r;
|
|
|
|
my $year = path('.')->absolute->parent->basename;
|
2023-12-08 15:31:44 +00:00
|
|
|
my $solutions = deserialize_file('solutions.yml');
|
|
|
|
|
|
|
|
my @parts = (
|
|
|
|
{ part => 1, sub => \&Part1::solution_1, expected => $solutions->{1} },
|
2023-12-09 20:31:25 +00:00
|
|
|
{ part => 2, sub => \&Part2::solution_2, expected => $solutions->{2} },
|
2023-12-08 15:31:44 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
my $input = path('./input')->slurp;
|
|
|
|
|
|
|
|
for my $part (@parts) {
|
|
|
|
my $res = Benchmark::countit(
|
|
|
|
10,
|
|
|
|
sub {
|
|
|
|
$part->{sub}->($input) == $part->{expected} or die;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
my $result = {
|
|
|
|
day => $day,
|
|
|
|
year => $year,
|
|
|
|
|
|
|
|
#variant => '',
|
|
|
|
language => 'perl',
|
|
|
|
part => $part->{part},
|
|
|
|
time => $res->cpu_a / $res->iters,
|
2023-12-09 20:05:07 +00:00
|
|
|
persec => $res->iters / $res->cpu_a,
|
2023-12-08 15:31:44 +00:00
|
|
|
timestamp => DateTime->now->iso8601,
|
|
|
|
};
|
|
|
|
say to_json $result;
|
|
|
|
}
|
|
|
|
|