adventofcode/2023/preset/day/templates/perl/benchmark.pl

44 lines
954 B
Perl
Raw Normal View History

2023-12-01 18:38:44 +00:00
use 5.38.0;
use Benchmark ':hireswallclock';
use Path::Tiny;
use JSON qw/ to_json /;
use DateTime;
2023-12-07 15:01:29 +00:00
use File::Serialize;
2023-12-01 18:38:44 +00:00
use Part1;
use Part2;
my $day = path('.')->absolute->basename =~ s/^0//r;
2023-12-03 20:12:17 +00:00
my $year = path('.')->absolute->parent->basename;
2023-12-07 15:01:29 +00:00
my $solutions = deserialize_file('solutions.yml');
2023-12-01 18:38:44 +00:00
my @parts = (
2023-12-07 15:01:29 +00:00
{ part => 1, sub => \&Part1::solution_1, expected => $solutions->{1} },
{ part => 2, sub => \&Part2::solution_2, expected => $solutions->{2} },
2023-12-01 18:38: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,
timestamp => DateTime->now->iso8601,
};
say to_json $result;
}