Skip to content

Commit d8d383e

Browse files
authored
Merge pull request #1 from SpringMT/add-benchmarks
Add benchmarks
2 parents 27be391 + 962197f commit d8d383e

File tree

14 files changed

+4713
-1
lines changed

14 files changed

+4713
-1
lines changed

benchmarks/Gemfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
source 'https://rubygems.org'
2+
3+
gem 'benchmark-ips'
4+
gem 'snappy'
5+
gem 'ruby-xz'
6+
gem 'lz4-ruby'
7+

benchmarks/Gemfile.lock

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
GEM
2+
remote: https://rubygems.org/
3+
specs:
4+
benchmark-ips (2.7.2)
5+
ffi (1.9.17)
6+
io-like (0.3.0)
7+
lz4-ruby (0.3.3)
8+
ruby-xz (0.2.3)
9+
ffi (~> 1.9)
10+
io-like (~> 0.3)
11+
snappy (0.0.15)
12+
13+
PLATFORMS
14+
ruby
15+
16+
DEPENDENCIES
17+
benchmark-ips
18+
lz4-ruby
19+
ruby-xz
20+
snappy
21+
22+
BUNDLED WITH
23+
1.14.3

benchmarks/README.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# sample data
2+
FROM http://www.cl.ecei.tohoku.ac.jp/~matsuda/LRE_corpus/
3+
4+
# usage
5+
6+
7+
```
8+
bundle exec ruby compress.rb city
9+
```
10+
11+
12+
# Result
13+
## Compression
14+
15+
### Performance
16+
17+
```
18+
% bundle exec ruby compress.rb city.json
19+
Warming up --------------------------------------
20+
snappy 18.000 i/100ms
21+
gzip 2.000 i/100ms
22+
xz 1.000 i/100ms
23+
lz4 24.000 i/100ms
24+
zstd 17.000 i/100ms
25+
Calculating -------------------------------------
26+
snappy 189.588 (±16.9%) i/s - 918.000 in 5.072385s
27+
gzip 27.703 (± 7.2%) i/s - 138.000 in 5.032686s
28+
xz 1.621 (± 0.0%) i/s - 9.000 in 5.560271s
29+
lz4 282.316 (±14.5%) i/s - 1.368k in 5.008697s
30+
zstd 195.722 (±14.3%) i/s - 952.000 in 5.027488s
31+
```
32+
33+
34+
35+
### Data Size
36+
37+
#### before
38+
39+
```
40+
% ls -alh samples/city.json
41+
-rw-r--r--@ 1 makoto staff 1.7M 2 5 16:07 samples/city.json
42+
```
43+
44+
#### after
45+
46+
```
47+
% ls -alh results
48+
total 2712
49+
-rw-r--r-- 1 makoto staff 219K 2 5 16:08 city.json.gzip
50+
-rw-r--r-- 1 makoto staff 365K 2 5 16:08 city.json.lz4
51+
-rw-r--r-- 1 makoto staff 358K 2 5 16:08 city.json.snappy
52+
-rw-r--r-- 1 makoto staff 166K 2 5 16:08 city.json.xz
53+
-rw-r--r-- 1 makoto staff 238K 2 5 16:08 city.json.zstd
54+
```
55+

benchmarks/compress.rb

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
require 'benchmark/ips'
2+
3+
$LOAD_PATH.unshift "../lib"
4+
5+
require 'json'
6+
require 'snappy'
7+
require 'zlib'
8+
require 'xz'
9+
require 'lz4-ruby'
10+
require 'zstd-ruby'
11+
12+
sample_file_name = ARGV[0]
13+
14+
json_data = JSON.parse(IO.read("./samples/#{sample_file_name}"), symbolize_names: true)
15+
json_string = json_data.to_json
16+
17+
Benchmark.ips do |x|
18+
x.report("snappy") do
19+
File.write("./results/#{sample_file_name}.snappy", Snappy.deflate(json_string))
20+
end
21+
22+
x.report("gzip") do
23+
Zlib::GzipWriter.open("./results/#{sample_file_name}.gzip") do |gz|
24+
gz.write json_string
25+
end
26+
end
27+
28+
x.report("xz") do
29+
File.write("./results/#{sample_file_name}.xz", XZ.compress(json_string))
30+
end
31+
32+
x.report("lz4") do
33+
File.write("./results/#{sample_file_name}.lz4", LZ4::compress(json_string))
34+
end
35+
36+
x.report("zstd") do
37+
File.write("./results/#{sample_file_name}.zstd", Zstd.compress(json_string))
38+
end
39+
end

benchmarks/decompress.rb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
require 'benchmark/ips'
2+
3+
require 'json'
4+
require 'snappy'
5+
require 'zlib'
6+
require 'xz'
7+
require 'lz4-ruby'
8+
9+
sample_file_name = ARGV[0]
10+
11+
Benchmark.ips do |x|
12+
x.report("snappy") do
13+
Snappy.inflate IO.read("./results/#{sample_file_name}.snappy")
14+
end
15+
16+
x.report("gzip") do
17+
gz = Zlib::GzipReader.new( File.open("./results/#{sample_file_name}.gzip") )
18+
gz.read
19+
gz.close
20+
end
21+
22+
x.report("xz") do
23+
XZ.decompress IO.read("./results/#{sample_file_name}.xz")
24+
end
25+
26+
x.report("lz4") do
27+
LZ4::decompress IO.read("./results/#{sample_file_name}.lz4")
28+
end
29+
30+
x.report("zstd") do
31+
Zstd.decompress IO.read("./results/#{sample_file_name}.zstd")
32+
end
33+
34+
end

benchmarks/results/city.json.gzip

219 KB
Binary file not shown.

benchmarks/results/city.json.lz4

365 KB
Binary file not shown.

benchmarks/results/city.json.snappy

358 KB
Binary file not shown.

benchmarks/results/city.json.xz

166 KB
Binary file not shown.

benchmarks/results/city.json.zstd

238 KB
Binary file not shown.

0 commit comments

Comments
 (0)