3 #=======================================================================
5 # File ID: 8cb08b6c-fa50-11dd-aa63-000475e441b9
6 # Display a graph which compares the compress ratio from several
7 # programs. Quick & Dirty™.
10 # ©opyleft 2006– Øyvind A. Holm <sunny@sunbase.org>
11 # License: GNU General Public License version 2 or later, see end of
12 # file for legal stuff.
13 #=======================================================================
18 use Time
::HiRes
qw{ gettimeofday
};
36 $progname =~ s/^.*\/(.*?)$/$1/;
37 our $VERSION = "0.00";
39 Getopt
::Long
::Configure
("bundling");
42 "debug" => \
$Opt{'debug'},
43 "full-scale|f" => \
$Opt{'full-scale'},
44 "help|h" => \
$Opt{'help'},
45 "time|t" => \
$Opt{'time'},
46 "verbose|v+" => \
$Opt{'verbose'},
47 "version" => \
$Opt{'version'},
49 ) || die("$progname: Option error. Use -h for help.\n");
51 $Opt{'debug'} && ($Debug = 1);
52 $Opt{'help'} && usage
(0);
53 if ($Opt{'version'}) {
59 for my $File (@ARGV) {
60 my $orig_size = file_size
($File);
61 my $yrange = $Opt{'full-scale'} ?
"[0:100]" : "[:]";
63 unless (length($orig_size)) {
64 warn("$progname: $File: Unable to stat() file\n");
67 if ($orig_size == 0) {
68 warn("$progname: $File: File cannot be empty\n");
71 unless (open(DatFP
, ">", "$File.compr")) {
72 warn("$progname: $File.compr: Cannot open file for write: $!\n");
77 system("cat $File >/dev/null");
80 my $tmp_prefix = "$File.$Comp.tmp";
82 $Opt{'verbose'} && print("gzip -$Comp\n");
83 my $gzip_start = gettimeofday
;
84 system("gzip -$Comp <$File >$tmp_prefix.gz");
85 my $gzip_end = gettimeofday
;
86 my $gzip_time = $gzip_end-$gzip_start;
87 my $compr_gzip = file_size
("$tmp_prefix.gz");
88 unlink("$tmp_prefix.gz");
90 $Opt{'verbose'} && print("bzip2 -$Comp\n");
91 my $bzip_start = gettimeofday
;
92 system("bzip2 -$Comp <$File >$tmp_prefix.bz2");
93 my $bzip_end = gettimeofday
;
94 my $bzip_time = $bzip_end-$bzip_start;
95 my $compr_bzip = file_size
("$tmp_prefix.bz2");
96 unlink("$tmp_prefix.bz2");
98 $Opt{'verbose'} && print("zip -$Comp\n");
99 my $zip_start = gettimeofday
;
100 system("zip -$Comp - - 2>/dev/null <$File >$tmp_prefix.zip");
101 my $zip_end = gettimeofday
;
102 my $zip_time = $zip_end-$zip_start;
103 my $compr_zip = file_size
("$tmp_prefix.zip");
104 unlink("$tmp_prefix.zip");
106 $Opt{'verbose'} && print("lzip -$Comp\n");
107 my $lzip_start = gettimeofday
;
108 system("lzip -$Comp <$File >$tmp_prefix.lz");
109 my $lzip_end = gettimeofday
;
110 my $lzip_time = $lzip_end-$lzip_start;
111 my $compr_lzip = file_size
("$tmp_prefix.lz");
112 unlink("$tmp_prefix.lz");
114 $Opt{'verbose'} && print("lrzip -L $Comp\n");
115 my $lrzip_start = gettimeofday
;
116 system("lrzip -L $Comp <$File >$tmp_prefix.lrz");
117 my $lrzip_end = gettimeofday
;
118 my $lrzip_time = $lrzip_end-$lrzip_start;
119 my $compr_lrzip = file_size
("$tmp_prefix.lrz");
120 unlink("$tmp_prefix.lrz");
122 $Opt{'verbose'} && print("lrzip -z -L $Comp\n");
123 my $lrzip_z_start = gettimeofday
;
124 system("lrzip -z -L $Comp <$File >$tmp_prefix.lrz");
125 my $lrzip_z_end = gettimeofday
;
126 my $lrzip_z_time = $lrzip_z_end-$lrzip_z_start;
127 my $compr_lrzip_z = file_size
("$tmp_prefix.lrz");
128 unlink("$tmp_prefix.lrz");
130 $Opt{'verbose'} && print("xz -$Comp\n");
131 my $xz_start = gettimeofday
;
132 system("xz -$Comp <$File >$tmp_prefix.xz");
133 my $xz_end = gettimeofday
;
134 my $xz_time = $xz_end-$xz_start;
135 my $compr_xz = file_size
("$tmp_prefix.xz");
136 unlink("$tmp_prefix.xz");
138 $Opt{'verbose'} && print("xz -e -$Comp\n");
139 my $xz_e_start = gettimeofday
;
140 system("xz -e -$Comp <$File >$tmp_prefix.xz");
141 my $xz_e_end = gettimeofday
;
142 my $xz_e_time = $xz_e_end-$xz_e_start;
143 my $compr_xz_e = file_size
("$tmp_prefix.xz");
144 unlink("$tmp_prefix.xz");
146 my ($ratio_gzip, $ratio_bzip, $ratio_zip, $ratio_lzip, $ratio_lrzip, $ratio_lrzip_z, $ratio_xz, $ratio_xz_e);
149 # $ratio_gzip = $gzip_time / ($compr_gzip/$orig_size);
150 # $ratio_bzip = $bzip_time / ($compr_bzip/$orig_size);
151 # $ratio_zip = $zip_time / ($compr_zip/$orig_size);
152 $ratio_gzip = $gzip_time;
153 $ratio_bzip = $bzip_time;
154 $ratio_zip = $zip_time;
155 $ratio_lzip = $lzip_time;
156 $ratio_lrzip = $lrzip_time;
157 $ratio_lrzip_z = $lrzip_z_time;
158 $ratio_xz = $xz_time;
159 $ratio_xz_e = $xz_e_time;
161 $ratio_gzip = ($compr_gzip/$orig_size) * 100;
162 $ratio_bzip = ($compr_bzip/$orig_size) * 100;
163 $ratio_zip = ($compr_zip/$orig_size) * 100;
164 $ratio_lzip = ($compr_lzip/$orig_size) * 100;
165 $ratio_lrzip = ($compr_lrzip/$orig_size) * 100;
166 $ratio_lrzip_z = ($compr_lrzip_z/$orig_size) * 100;
167 $ratio_xz = ($compr_xz/$orig_size) * 100;
168 $ratio_xz_e = ($compr_xz_e/$orig_size) * 100;
171 print(DatFP
"$Comp\t$ratio_gzip\t$ratio_bzip\t$ratio_zip\t$ratio_lzip\t$ratio_lrzip\t$ratio_lrzip_z\t$ratio_xz\t$ratio_xz_e\n");
174 my $gnuplot_file = "$File.gnuplot";
175 if (open(GnuplFP
, ">", "$gnuplot_file")) {
176 print(GnuplFP
<<END);
177 #!/usr/bin/gnuplot -persist
180 plot "$File.compr" using 1:2 title "gzip" w lp pt 3, \\
181 "$File.compr" using 1:3 title "bzip2" w lp pt 3, \\
182 "$File.compr" using 1:4 title "zip" w lp pt 3, \\
183 "$File.compr" using 1:5 title "lzip" w lp pt 3, \\
184 "$File.compr" using 1:6 title "lrzip" w lp pt 3, \\
185 "$File.compr" using 1:7 title "lrzip -z" w lp pt 3, \\
186 "$File.compr" using 1:8 title "xz" w lp pt 3, \\
187 "$File.compr" using 1:9 title "xz -e" w lp pt 3
191 system("gnuplot -persist $gnuplot_file");
196 my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime,
197 $mtime, $ctime, $blksize, $blocks) = stat($File);
198 return(defined($size) ?
$size : "");
202 # Print program version {{{
203 print("$progname v$VERSION\n");
208 # Send the help message to stdout {{{
211 if ($Opt{'verbose'}) {
217 Usage: $progname [options] [file [files [...]]]
219 Display a graph which compares the compress ratio from several programs.
220 Quick & Dirty™. Needs gnuplot(1).
229 Show number of microseconds used instead of size.
231 Increase level of verbosity. Can be repeated.
233 Print version information.
235 Print debugging messages.
243 # Print a status message to stderr based on verbosity level {{{
244 my ($verbose_level, $Txt) = @_;
246 if ($Opt{'verbose'} >= $verbose_level) {
247 print(STDERR
"$progname: $Txt\n");
253 # Print a debugging message {{{
255 my @call_info = caller;
256 chomp(my $Txt = shift);
257 my $File = $call_info[1];
259 $File =~ s
#^.*/(.*?)$#$1#;
260 print(STDERR
"$File:$call_info[2] $$ $Txt\n");
267 # Plain Old Documentation (POD) {{{
277 [options] [file [files [...]]]
287 =item B<-h>, B<--help>
289 Print a brief help summary.
291 =item B<-v>, B<--verbose>
293 Increase level of verbosity. Can be repeated.
297 Print version information.
301 Print debugging messages.
311 Made by Øyvind A. Holm S<E<lt>sunny@sunbase.orgE<gt>>.
315 Copyleft © Øyvind A. Holm E<lt>sunny@sunbase.orgE<gt>
316 This is free software; see the file F<COPYING> for legalese stuff.
320 This program is free software: you can redistribute it and/or modify it
321 under the terms of the GNU General Public License as published by the
322 Free Software Foundation, either version 2 of the License, or (at your
323 option) any later version.
325 This program is distributed in the hope that it will be useful, but
326 WITHOUT ANY WARRANTY; without even the implied warranty of
327 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
328 See the GNU General Public License for more details.
330 You should have received a copy of the GNU General Public License along
332 If not, see L<http://www.gnu.org/licenses/>.
340 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :