table.pl 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. #! /usr/bin/perl
  2. ## vim:set ts=4 sw=4 et: -*- coding: utf-8 -*-
  3. ##
  4. ##---------------------------------------------------------------------------##
  5. ##
  6. ## Author:
  7. ## Markus F.X.J. Oberhumer <markus@oberhumer.com>
  8. ##
  9. ## Description:
  10. ## Convert the output of the LZO lzotest program into a nice table.
  11. ##
  12. ## Copyright (C) 1996-2015 Markus Franz Xaver Johannes Oberhumer
  13. ##
  14. ##---------------------------------------------------------------------------##
  15. $PROG = $0;
  16. require 'ctime.pl';
  17. #
  18. # get options
  19. #
  20. while ($_ = $ARGV[ $[ ], /^-/) {
  21. shift(@ARGV);
  22. /^--$/ && ($opt_last = 1, last);
  23. /^--sort=name/ && ($opt_sort_summary_by_name++, next);
  24. /^--sort=ratio/ && ($opt_sort_summary_by_ratio++, next);
  25. /^-s/ && ($opt_summary_only++, next);
  26. /^-t/ && ($opt_clear_time++, next);
  27. }
  28. $alg = '';
  29. $sep = "+" . ("-" x 76) . "+\n";
  30. $block_size = -1;
  31. $n = 0;
  32. @algs = ();
  33. %average = ();
  34. %total = ();
  35. $lzo_version_string = '';
  36. $lzo_version_date = '';
  37. # /***********************************************************************
  38. # //
  39. # ************************************************************************/
  40. while (<>) {
  41. if (/(^|\s)(\d+)\s+block\-size/i) {
  42. if ($block_size < 0) {
  43. $block_size = $2;
  44. &intro($block_size);
  45. } elsif ($block_size != $2) {
  46. die "$PROG: block-size: $block_size != $2\n";
  47. }
  48. next;
  49. }
  50. if (/^\s*LZO\s.*library\s+\(v\s*([\w\.\s]+)\s*\,\s*([^\)]+)\)/) {
  51. $lzo_version_string = $1;
  52. $lzo_version_date = $2;
  53. next;
  54. }
  55. if (/^\s*(\S+(\s+\[\S+\])?)\s*(\|.*\|)\s*$/i) {
  56. if ($1 ne $alg) {
  57. &footer($1);
  58. &header($1);
  59. }
  60. $line = $3;
  61. &stats(*line);
  62. print "$line\n" if (!$opt_summary_only);
  63. }
  64. }
  65. &footer($1);
  66. &summary();
  67. exit(0);
  68. # /***********************************************************************
  69. # //
  70. # ************************************************************************/
  71. sub stats {
  72. local (*l) = @_;
  73. local ($x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8);
  74. if ($l !~ /^\|\s*(.+?)\s+(\d+)\s+(\d+)\s+(\d+)\s+([\d\.]+\s+)?([\d\.]+\s+)?([\d\.]+)\s+([\d\.]+)\s*\|/) {
  75. die $_;
  76. }
  77. $n++;
  78. $x1 = $1; $x2 = $2; $x3 = $3; $x4 = $4;
  79. $x5 = ($x2 > 0) ? $x4 * 100.0 / $x2 : 0.0;
  80. $x6 = ($x2 > 0) ? $x4 * 8.0 / $x2 : 0.0;
  81. $x7 = $7; $x8 = $8;
  82. # convert from kB/s to MB/s (for old versions of lzotest)
  83. if ($x7 =~ /\.\d\d$/) { $x7 = $x7 / 1000.0; }
  84. if ($x8 =~ /\.\d\d$/) { $x8 = $x8 / 1000.0; }
  85. if ($opt_clear_time) {
  86. $x7 = $x8 = 0.0;
  87. }
  88. $s[0] += $x2;
  89. $s[1] += $x3;
  90. $s[2] += $x4;
  91. $s[3] += $x5;
  92. $s[4] += $x6;
  93. if ($x7 > 0) {
  94. $s[5] += 1.0 / $x7; $sn[5] += 1;
  95. }
  96. if ($x8 > 0) {
  97. $s[6] += 1.0/ $x8; $sn[6] += 1;
  98. }
  99. $x1 =~ s/\s+$//;
  100. $l = sprintf("| %-14s %10d %5d %9d %6.1f %5.2f %9.3f %9.3f |",
  101. $x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8);
  102. }
  103. # /***********************************************************************
  104. # //
  105. # ************************************************************************/
  106. sub header {
  107. local ($t) = @_;
  108. $alg = $t;
  109. # reset stats
  110. $n = 0;
  111. @s = (0, 0, 0, 0.0, 0.0, 0.0, 0.0);
  112. @sn = (0, 0, 0, 0, 0, 0, 0);
  113. return if $opt_summary_only;
  114. print "\n$alg\n\n";
  115. print $sep;
  116. print <<EndOfString;
  117. | File Name Length CxB ComLen Ratio% Bits Com MB/s Dec MB/s |
  118. | --------- ------ --- ------ ----- ---- -------- -------- |
  119. EndOfString
  120. }
  121. # /***********************************************************************
  122. # //
  123. # ************************************************************************/
  124. sub footer {
  125. local ($t) = @_;
  126. local ($shm5, $shm6);
  127. return unless $alg;
  128. die if $n <= 0;
  129. die if $s[0] <= 0;
  130. # harmonic mean
  131. $shm5 = $s[5] > 0 ? $sn[5] / $s[5] : 0.0;
  132. $shm6 = $s[6] > 0 ? $sn[6] / $s[6] : 0.0;
  133. push(@algs,$alg);
  134. $average{$alg} =
  135. sprintf("| %-14s %10d %5d %9d %6.1f %5.2f %9.3f %9.3f |\n",
  136. "Average", $s[0]/$n, $s[1]/$n, $s[2]/$n,
  137. $s[3]/$n, $s[4]/$n,
  138. $shm5, $shm6);
  139. $total{$alg} =
  140. sprintf("| %-14s %10d %5d %9d %6.1f %5.2f %9.3f %9.3f |\n",
  141. "Total", $s[0], $s[1], $s[2],
  142. $s[2]/$s[0]*100, $s[2]/$s[0]*8,
  143. $shm5, $shm6);
  144. return if $opt_summary_only;
  145. print $sep;
  146. print $average{$alg};
  147. print $total{$alg};
  148. print $sep, "\n";
  149. }
  150. # /***********************************************************************
  151. # //
  152. # ************************************************************************/
  153. $sort_mode = 0;
  154. sub cmp_by_ratio {
  155. local ($aa, $bb);
  156. if ($sort_mode == 0) {
  157. $aa = $average{$a};
  158. $bb = $average{$b};
  159. } elsif ($sort_mode == 1) {
  160. $aa = $total{$a};
  161. $bb = $total{$b};
  162. } else {
  163. die;
  164. }
  165. ($aa =~ m%^\s*\|\s+\S+\s+\d+\s+\d+\s+\d+\s+(\S+)%) || die;
  166. $aa = $1;
  167. ($bb =~ m%^\s*\|\s+\S+\s+\d+\s+\d+\s+\d+\s+(\S+)%) || die;
  168. $bb = $1;
  169. # $aa < $bb;
  170. $aa cmp $bb;
  171. }
  172. # /***********************************************************************
  173. # //
  174. # ************************************************************************/
  175. sub summary {
  176. local ($l);
  177. local (@k);
  178. $sort_mode = 0;
  179. if ($opt_sort_summary_by_name) {
  180. @k = sort(@algs);
  181. } elsif ($opt_sort_summary_by_ratio) {
  182. @k = sort(cmp_by_ratio @algs);
  183. } else {
  184. @k = @algs;
  185. }
  186. print "\n\n";
  187. print "Summary of average values\n\n";
  188. print $sep;
  189. print <<EndOfString;
  190. | Algorithm Length CxB ComLen Ratio% Bits Com MB/s Dec MB/s |
  191. | --------- ------ --- ------ ----- ---- -------- -------- |
  192. EndOfString
  193. for (@k) {
  194. $l = $average{$_};
  195. $l =~ s/Average[\s]{7}/sprintf("%-14s",$_)/e;
  196. print $l;
  197. }
  198. print $sep;
  199. $sort_mode = 1;
  200. if ($opt_sort_summary_by_name) {
  201. @k = sort(@algs);
  202. } elsif ($opt_sort_summary_by_ratio) {
  203. @k = sort(cmp_by_ratio @algs);
  204. } else {
  205. @k = @algs;
  206. }
  207. print "\n\n";
  208. print "Summary of total values\n\n";
  209. print $sep;
  210. print <<EndOfString;
  211. | Algorithm Length CxB ComLen Ratio% Bits Com MB/s Dec MB/s |
  212. | --------- ------ --- ------ ----- ---- -------- -------- |
  213. EndOfString
  214. for (@k) {
  215. $l = $total{$_};
  216. $l =~ s/Total[\s]{9}/sprintf("%-14s",$_)/e;
  217. print $l;
  218. }
  219. print $sep;
  220. }
  221. # /***********************************************************************
  222. # //
  223. # ************************************************************************/
  224. sub intro {
  225. local ($bs) = @_;
  226. local ($v, $t, $x);
  227. local ($u, $uname_m, $uname_s, $uname_r);
  228. $t = &ctime(time); chop($t);
  229. $t = sprintf("%-55s |", $t);
  230. $v='';
  231. if ($lzo_version_string) {
  232. $v = $lzo_version_string;
  233. $v .= ', ' . $lzo_version_date if $lzo_version_date;
  234. $v = sprintf("%-55s |", $v);
  235. $v = sprintf("| LZO version : %s\n", $v);
  236. }
  237. if ($bs % 1024 == 0) {
  238. $x = sprintf("%d (= %d kB)", $bs, $bs / 1024);
  239. } else {
  240. $x = sprintf("%d (= %.3f kB)", $bs, $bs / 1024.0);
  241. }
  242. $x = sprintf("%-55s |", $x);
  243. $u='';
  244. if (1 == 1) {
  245. $uname_s = `uname -s`; $uname_s =~ s/^\s+//; $uname_s =~ s/\s+$//;
  246. $uname_r = `uname -r`; $uname_r =~ s/^\s+//; $uname_r =~ s/\s+$//;
  247. $uname_m = `uname -m`; $uname_m =~ s/^\s+//; $uname_m =~ s/\s+$//;
  248. if ($uname_s && $uname_m) {
  249. $u = $uname_s;
  250. $u .= ' ' . $uname_r if $uname_r;
  251. $u .= ' ' . $uname_m;
  252. $u = sprintf("%-55s |", $u);
  253. $u = sprintf("| Operating system : %s\n", $u);
  254. }
  255. }
  256. print <<EndOfString;
  257. +----------------------------------------------------------------------------+
  258. | DATA COMPRESSION TEST |
  259. | ===================== |
  260. | Time of run : $t
  261. $v$u| Context length : $x
  262. +----------------------------------------------------------------------------+
  263. Notes:
  264. - CxB is the number of independent blocks a file was splitted
  265. - MB/s is the speed measured in 1,000,000 uncompressed bytes per second
  266. - all averages are calculated from the un-rounded values
  267. - the average ratio & bits are calculated by the arithmetic mean
  268. - the average speed is calculated by the harmonic mean
  269. EndOfString
  270. }
  271. __END__
  272. ### insert something like this after 'Time of run':
  273. | Hardware : Intel Pentium 133, 64 MB RAM, 256 kB Cache |
  274. | Operating system : MS-DOS 7.10, HIMEM.SYS 3.95, DOS/4GW 1.97 |
  275. | Compiler : Watcom C32 10.5 |
  276. | Compiler flags : -mf -5r -oneatx |
  277. | Test suite : Calgary Corpus Suite |
  278. | Files in suite : 14 |
  279. | Timing accuracy : One part in 100 |