-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathcompression_algorithms.pl
119 lines (94 loc) · 2.71 KB
/
compression_algorithms.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/usr/bin/perl
# Rough performance comparison of some compression modules on a given file given as an argument.
use 5.010;
use strict;
use warnings;
use Time::HiRes qw(gettimeofday tv_interval);
my $data_str = do {
open(my $fh, '<:raw', $ARGV[0] // $0)
or die "Can't open file <<$ARGV[0]>> for reading: $!";
local $/;
<$fh>;
};
say "Raw : ", length($data_str);
say '';
eval {
my $t0 = [gettimeofday];
require IO::Compress::Gzip;
IO::Compress::Gzip::gzip(\$data_str, \my $data_gzip);
say "Gzip: ", length($data_gzip);
say "Time: ", tv_interval($t0, [gettimeofday]);
say '';
};
eval {
my $t0 = [gettimeofday];
require IO::Compress::Bzip2;
IO::Compress::Bzip2::bzip2(\$data_str, \my $data_bzip2);
say "Bzip: ", length($data_bzip2);
say "Time: ", tv_interval($t0, [gettimeofday]);
say '';
};
eval {
my $t0 = [gettimeofday];
require IO::Compress::RawDeflate;
IO::Compress::RawDeflate::rawdeflate(\$data_str, \my $data_raw_deflate);
say "RDef: ", length($data_raw_deflate);
say "Time: ", tv_interval($t0, [gettimeofday]);
say '';
};
eval {
my $t0 = [gettimeofday];
require IO::Compress::Deflate;
IO::Compress::Deflate::deflate(\$data_str, \my $data_deflate);
say "Defl: ", length($data_deflate);
say "Time: ", tv_interval($t0, [gettimeofday]);
say '';
};
eval {
my $t0 = [gettimeofday];
require IO::Compress::Zip;
IO::Compress::Zip::zip(\$data_str, \my $data_zip);
say "Zip : ", length($data_zip);
say "Time: ", tv_interval($t0, [gettimeofday]);
say '';
};
eval {
my $t0 = [gettimeofday];
require IO::Compress::Lzf;
IO::Compress::Lzf::lzf(\$data_str, \my $data_lzf);
say "Lzf : ", length($data_lzf);
say "Time: ", tv_interval($t0, [gettimeofday]);
say '';
};
eval {
my $t0 = [gettimeofday];
require IO::Compress::Lzip;
IO::Compress::Lzip::lzip(\$data_str, \my $data_lzip);
say "Lzip: ", length($data_lzip);
say "Time: ", tv_interval($t0, [gettimeofday]);
say '';
};
eval {
my $t0 = [gettimeofday];
require IO::Compress::Lzop;
IO::Compress::Lzop::lzop(\$data_str, \my $data_lzop);
say "Lzop: ", length($data_lzop);
say "Time: ", tv_interval($t0, [gettimeofday]);
say '';
};
eval {
my $t0 = [gettimeofday];
require IO::Compress::Zstd;
IO::Compress::Zstd::zstd(\$data_str, \my $data_zstd);
say "Zstd: ", length($data_zstd);
say "Time: ", tv_interval($t0, [gettimeofday]);
say '';
};
0 && eval {
my $t0 = [gettimeofday];
require IO::Compress::Brotli;
my $data_bro = IO::Compress::Brotli::bro($data_str);
say "Brot: ", length($data_bro);
say "Time: ", tv_interval($t0, [gettimeofday]);
say '';
};