~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/myisam/ftbench/Ecompare.pl

  • Committer: Brian Aker
  • Date: 2008-07-06 15:03:34 UTC
  • Revision ID: brian@tangent.org-20080706150334-xv3xa202trvs0712
USE_RAID cleanup, along with ftbench tools.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/perl
2
 
 
3
 
# compares out-files (as created by Ereport.pl) from dir1/*.out and dir2/*.out
4
 
# for each effectiveness column computes the probability of the hypothesis
5
 
# "Both files have the same effectiveness"
6
 
 
7
 
# sign test is used to verify that test results are statistically
8
 
# significant to support the hypothesis. Function is computed on the fly.
9
 
 
10
 
# basic formula is \sum_{r=0}^R C_N^r 2^{-N}
11
 
# As N can be big, we'll work with logarithms
12
 
$log2=log(2);
13
 
sub probab {
14
 
  my $N=shift, $R=shift;
15
 
 
16
 
  my $r, $sum=0;
17
 
 
18
 
  for $r (0..$R) {
19
 
    $sum+=exp(logfac($N)-logfac($r)-logfac($N-$r)-$N*$log2);
20
 
  }
21
 
  return $sum;
22
 
}
23
 
 
24
 
# log(N!)
25
 
# for N<20 exact value from the table (below) is taken
26
 
# otherwise, Stirling approximation for N! is used
27
 
sub logfac {
28
 
  my $n=shift; die "n=$n<0" if $n<0;
29
 
  return $logfactab[$n] if $n<=$#logfactab;
30
 
  return $n*log($n)-$n+log(2*3.14159265358*$n)/2;
31
 
}
32
 
@logfactab=(
33
 
0,    0,         0.693147180559945, 1.79175946922805, 3.17805383034795,
34
 
4.78749174278205, 6.57925121201010, 8.52516136106541, 10.6046029027453,
35
 
12.8018274800815, 15.1044125730755, 17.5023078458739, 19.9872144956619,
36
 
22.5521638531234, 25.1912211827387, 27.8992713838409, 30.6718601060807,
37
 
33.5050734501369, 36.3954452080331, 39.3398841871995, 42.3356164607535,
38
 
);
39
 
 
40
 
############################# main () ###############################
41
 
#$p=shift; $m=shift; $p-=$m;
42
 
#if($p>$m) {
43
 
#  print "1 > 2 [+$p-$m]: ", probab($p+$m, $m), "\n";
44
 
#} elsif($p<$m) {
45
 
#  print "1 < 2 [+$p-$m]: ", probab($p+$m, $p), "\n";
46
 
#} else {
47
 
#  print "1 = 2 [+$p-$m]: ", probab($p+$m, $m), "\n";
48
 
#}
49
 
#exit;
50
 
 
51
 
die "Use: $0 dir1 dir2\n" unless @ARGV==2 &&
52
 
                             -d ($dir1=shift) && -d ($dir2=shift);
53
 
$_=`cd $dir1; echo *.out`;
54
 
s/\.out\b//g;
55
 
$total="";
56
 
 
57
 
for $file (split) {
58
 
  open(OUT1,$out1="$dir1/$file.out") || die "Cannot open $out1: $!";
59
 
  open(OUT2,$out2="$dir2/$file.out") || die "Cannot open $out2: $!";
60
 
 
61
 
  @p=@m=();
62
 
  while(!eof(OUT1) || !eof(OUT2)) {
63
 
    $_=<OUT1>; @l1=split; shift @l1;
64
 
    $_=<OUT2>; @l2=split; shift @l2;
65
 
 
66
 
    die "Number of columns differ in line $.\n" unless $#l1 == $#l2;
67
 
 
68
 
    for (0..$#l1) {
69
 
      $p[$_]+= $l1[$_] > $l2[$_];
70
 
      $m[$_]+= $l1[$_] < $l2[$_];
71
 
    }
72
 
  }
73
 
 
74
 
  for (0..$#l1) {
75
 
    $pp[$_]+=$p[$_]; $mm[$_]+=$m[$_];
76
 
    $total[$_].=rep($file, ($#l1 ? $_ : undef), $p[$_], $m[$_]);
77
 
  }
78
 
  close OUT1;
79
 
  close OUT2;
80
 
}
81
 
 
82
 
for (0..$#l1) {
83
 
  rep($total[$_], ($#l1 ? $_ : undef), $pp[$_], $mm[$_]);
84
 
}
85
 
 
86
 
sub rep {
87
 
  my ($test, $n, $p, $m, $c, $r)=@_;
88
 
  
89
 
  if   ($p>$m) { $c=">"; $r="+"; }
90
 
  elsif($p<$m) { $c="<"; $r="-"; }
91
 
  else         { $c="="; $r="="; }
92
 
  $n=" $n: " if defined $n;
93
 
  printf "%-8s $n $dir1 $c $dir2 [+%03d-%03d]: %16.15f\n",
94
 
          $test, $p, $m, probab($p+$m, ($p>=$m ? $m : $p));
95
 
  $r;
96
 
}