Actual test harness
use Time::HiRes 'gettimeofday';
sub time2 {
my ($function) = @_;
my ($stop_s, $stop_ms);
my ($start_s, $start_ms) = gettimeofday;
$function->();
($stop_s, $stop_ms) = gettimeofday;
my ($duration_s, $duration_ms) = (
$stop_s - $start_s,
$stop_ms - $start_ms,
);
if ($duration_ms < 0) {
$duration_s--;
$duration_ms += 1_000_000;
}
printf "%d.%06d\n", $duration_s, $duration_ms;
}