#!/usr/local/bin/perl5 -w
#!/usr/bin/perl

if($#ARGV < 0){
  print "You have to supply the number of the test you want to make (1-5)\n";
  exit(1);
}


@args = ("./driver", $ARGV[0]);
system(@args);
if($ARGV[0] == 1){$N= 32;}
if($ARGV[0] == 2){$N= 64;}
if($ARGV[0] == 3){$N= 128;}
if($ARGV[0] == 4){$N= 256;}
if($ARGV[0] == 5){$N= 1024;}


$cache_count = `tail -1 cacheprof.out.summary`;

my (@line) = split(/[,\)]\s+/, $cache_count);

# 1 == reads, 2 == writes, 3 == read misses, 4 == write misses
# We need to eat the trailing ',' in the number.

my ($refs) = $line[1] + $line[2];
my ($hits) = $refs - ($line[3] + $line[4]);

print "Hit score test $ARGV[0] is = " ,  ($line[3] + $line[4])/($N*$N), "\n";
