my @parsers = qw(C-Expat C-Rxp Java-xp Java-xml4j Perl Python);

my @tests   = qw(REC chrmed med chrbig big);

my $xp_classpath = "/home/ccc/Java/xp/xp.jar";
my $xml4j_classpath = "/home/ccc/Java/xml4j_2_0_2/xml4j.jar";

my $reps = 3;
my %cmds = ('C-Expat'    => './stats',
	    'C-Rxp'      => './stats',
	    'Java-xp'    => "java -cp $xp_classpath:. Statsxp",
	    'Java-xml4j' => "java -cp $xml4j_classpath:. Statsax",
	    'Perl'       => 'perl xmlstats',
	    'Python'     => 'python statsexpat.py');

print "<TABLE border='1'>\n";
print "<CAPTION>XML Parser Performance Statistics</CAPTION>\n";
print "<TR><TH rowspan='2'>";

foreach (@tests) {
  print "<TH colspan='3'>$_";
}

print "\n<TR>";

foreach (@tests) {
  print "<TH>user<TH>sys<TH>real";
}

print "\n";

my $parser;
foreach $parser (@parsers) {

  chdir($parser);

  my $cmd = $cmds{$parser};
  print "<TR><TH>$parser\n";

  #prime memory working set and cache
  system("$cmd ../Data/$tests[0].xml >/dev/null");

  my $test;
  foreach $test (@tests) {
    my $tc = "time -f 'u=%U s=%S r=%e' $cmd ../Data/$test.xml 2>&1 >/dev/null";

    my ($user, $sys, $real) = (0, 0, 0);

    for (1 .. $reps) {
      $result = `$tc`;
      unless ($result =~ /^u=(\d+\.\d+)\s+s=(\d+\.\d+)\s+r=(\d+\.\d+)/m) {
	die "Bad result for parser $parser on test $test:\n$result\n";
      }
      my ($u, $s, $r) = ($1, $2, $3);
      $user += $u;
      $sys  += $s;
      $real += $r;
    }

    $user /= $reps;
    $sys  /= $reps;
    $real /= $reps;

    printf "  <TD>%.3f<TD>%.3f<TD>%.3f\n", $user, $sys, $real;
  }

  chdir('..');
}

print "</TABLE>\n";



