]> www.fi.muni.cz Git - aoc.git/commitdiff
runner: display total runtime
authorJan "Yenya" Kasprzak <kas@fi.muni.cz>
Thu, 19 Dec 2024 07:19:52 +0000 (08:19 +0100)
committerJan "Yenya" Kasprzak <kas@fi.muni.cz>
Thu, 19 Dec 2024 07:19:52 +0000 (08:19 +0100)
run

diff --git a/run b/run
index 19f31bad44de5c0a65229ce146b2626c0931093d..dee795ebaef6af6dacc4016a9fb161fe65e57ac3 100755 (executable)
--- a/run
+++ b/run
@@ -6,12 +6,12 @@ use strict;
 
 use FindBin qw($Bin);
 use lib "$Bin/lib";
-use Time::HiRes qw(sleep);
+use Time::HiRes qw(sleep time);
 use Linux::Inotify2;
 use POSIX qw(strftime WIFSIGNALED WTERMSIG SIGINT);
 use Mojo::File;
 
-use Y::AoC qw(grey red);
+use Y::AoC qw(grey red white);
 
 my $cmd = shift;
 die "Usage: $0 ./command.pl" if !defined $cmd || !-x $cmd;
@@ -25,6 +25,7 @@ while (1) {
        my $b = "$backup-".strftime("%H-%M-%S", localtime(time));
        $file->copy_to($b);
        $mtime = $file->stat->mtime;
+       my $starttime = time;
        say grey("\nrunning $cmd @ARGV... ============================");
        system $cmd, @ARGV;
        if ($? && WIFSIGNALED($?) && WTERMSIG($?) == SIGINT) {
@@ -37,7 +38,8 @@ while (1) {
        } else {
                my $line;
                $line .= (qw(. ' ~ - = _))[rand(5)] for 1 .. 30;
-               say grey("finished OK $line");
+               say grey("finished OK $line after "),
+                       white(sprintf('%.1f', time-$starttime), 's');
        }
 
        my $inotify = Linux::Inotify2->new;