#!/usr/bin/env perl

use warnings;
use strict;

my @TESTS = $#ARGV == -1 ? qw(1 2 3 4 5 8) : @ARGV;
my $NTRIES = 5;

!system("./crawl --builddb") or die "Rebuilding the db failed -- bailing.\n";

# Load the db into the page cache, make the disk idle.
system("tar cf - saves/db saves/des >/dev/null 2>/dev/null");
system("sync");

my (%results, %times, $test);
for $test (@TESTS)
{
    my @times;
    for (1..$NTRIES)
    {
        my $u0 = (times)[2];
        system("test/stress/run " . $test);
        my $u1 = (times)[2];
        push @times, $u1 - $u0;
    }
    $results{$test} = $times[($NTRIES+1)/2];
}

print STDERR "Version: "; system("(git describe 2>/dev/null || cat util/release_ver) >&2");
printf STDERR "%s %10.2f\n", $_, $results{$_} for sort keys %results;
