mktable 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. #!/usr/bin/perl
  2. # XXX
  3. sub table() {
  4. my ($name) = @_;
  5. print <<'EOF';
  6. <table border=0>
  7. <tr><th>System</th><th>PCRE</th><th>RE2</th></tr>
  8. EOF
  9. foreach my $sys (@sys) {
  10. my $ns_pcre = $data{$sys}->{sprintf($name, "PCRE")}->{'ns/op'};
  11. my $ns_re2 = $data{$sys}->{sprintf($name, "RE2")}->{'ns/op'};
  12. printf "<tr><td>%s</td><td>%.1f µs</td><td>%.1f µs</td></tr>\n", $sysname{$sys}, $ns_pcre/1000., $ns_re2/1000.;
  13. }
  14. print <<'EOF';
  15. <tr height=5><td colspan=3></td></tr>
  16. </table>
  17. EOF
  18. }
  19. @sizes = (
  20. "8", "16", "32", "64", "128", "256", "512",
  21. "1K", "2K", "4K", "8K", "16K", "32K", "64K", "128K", "256K", "512K",
  22. "1M", "2M", "4M", "8M", "16M"
  23. );
  24. %color = (
  25. "PCRE" => "0.7 0 0",
  26. "RE2" => "0 0 1",
  27. );
  28. $ngraph = 0;
  29. sub graph() {
  30. my ($name) = @_;
  31. my $sys = "wreck";
  32. my $base = sprintf("regexp3g%d", ++$ngraph);
  33. open(JGR, ">$base.jgr") || die "open >$base.jgr: $!";
  34. printf JGR "bbox -20 -12 392 95\n";
  35. printf JGR "newgraph clip x_translate 0.25 y_translate 0.25\n";
  36. $ymax = 0;
  37. %lastx = ();
  38. %lasty = ();
  39. foreach my $who ("PCRE", "RE2") {
  40. printf JGR "newcurve pts\n";
  41. for(my $i=0; $i<@sizes; $i++) {
  42. my $key = sprintf("%s%s/%s", $name, $who, $sizes[$i]);
  43. my $val = $data{$sys}->{$key}->{'MB/s'};
  44. next if !defined($val);
  45. if($val > $ymax) {
  46. $ymax = $val;
  47. }
  48. $lastx{$who} = $i;
  49. $lasty{$who} = $val;
  50. printf JGR "$i %f (* %s *)\n", $val, $key;
  51. }
  52. my $color = $color{$who};
  53. printf JGR "marktype none color $color linethickness 2 linetype solid label : $who\n";
  54. }
  55. my $n = @sizes;
  56. printf JGR "xaxis min -1 max $n size 5 label : text size (bytes)\n";
  57. printf JGR " no_auto_hash_marks hash_labels fontsize 9\n";
  58. for($i=0; $i<@sizes; $i+=3) {
  59. printf JGR " hash_at $i hash_label at $i : $sizes[$i]\n";
  60. }
  61. my $y = 1;
  62. while(10*$y <= $ymax) {
  63. $y = 10*$y;
  64. }
  65. for($i=2; $i<=10; $i++) {
  66. if($i*$y > $ymax) {
  67. $y = $i*$y;
  68. last;
  69. }
  70. }
  71. foreach my $who ("PCRE", "RE2") {
  72. $x1 = $lastx{$who};
  73. $y1 = $lasty{$who};
  74. $x1 *= 1.01;
  75. my $v = "vjc";
  76. if($y1 < 0.05 * $y) {
  77. $v = "vjb";
  78. $y1 = 0.05 * $y;
  79. }
  80. printf JGR "newstring x $x1 y $y1 hjl $v : $who\n";
  81. }
  82. printf JGR "yaxis min 0 max $y size 1 label : speed (MB/s)\n";
  83. printf JGR " hash_labels fontsize 9\n";
  84. # printf JGR "legend defaults font Times-Roman fontsize 10 x 0 y $y hjl vjt\n";
  85. system("jgraph $base.jgr >$base.eps"); # die "system: $!";
  86. system("gs -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -dEPSCrop -sDEVICE=png16m -r100 -sOutputFile=$base.png -dBATCH -dQUIT -dQUIET -dNOPAUSE $base.eps");
  87. printf "<img src=$base.png>\n"
  88. }
  89. sub skip() {
  90. while(<>) {
  91. if(/^<!-- -->/) {
  92. print;
  93. last;
  94. }
  95. }
  96. }
  97. @sys = ("r70", "c2", "wreck", "mini");
  98. %sysname = (
  99. "r70" => "AMD Opteron 8214 HE, 2.2 GHz",
  100. "c2" => "Intel Core2 Duo E7200, 2.53 GHz",
  101. "wreck" => "Intel Xeon 5150, 2.66 GHz (Mac Pro)",
  102. "mini" => "Intel Core2 T5600, 1.83 GHz (Mac Mini)",
  103. );
  104. %func = (
  105. "table" => \&table,
  106. "graph" => \&graph,
  107. );
  108. foreach my $sys (@sys) {
  109. open(F, "benchlog.$sys") || die "open benchlog.$sys: $!";
  110. my %sysdat;
  111. while(<F>) {
  112. if(/^([A-Za-z0-9_\/]+)\s+(\d+)\s+(\d+) ns\/op/) {
  113. my %row;
  114. $row{"name"} = $1;
  115. $row{"iter"} = $2;
  116. $row{"ns/op"} = $3;
  117. if(/([\d.]+) MB\/s/){
  118. $row{"MB/s"} = $1;
  119. }
  120. $sysdat{$row{"name"}} = \%row;
  121. }
  122. }
  123. close F;
  124. $data{$sys} = \%sysdat;
  125. }
  126. while(<>) {
  127. print;
  128. if(/^<!-- benchlog (\w+) -->/) {
  129. $func{$1}();
  130. skip();
  131. next;
  132. }
  133. if(/^<!-- benchlog (\w+) ([%\w]+) -->/) {
  134. $func{$1}($2);
  135. skip();
  136. next;
  137. }
  138. }