zopfli 0.0.8 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/main.yml +35 -0
- data/.github/workflows/publish.yml +34 -0
- data/Gemfile +3 -1
- data/Rakefile +14 -8
- data/ext/extconf.rb +36 -33
- data/ext/zopfli.c +13 -0
- data/lib/zopfli/version.rb +1 -1
- data/test/test_helper.rb +7 -0
- data/test/zopfli_test.rb +63 -0
- data/zopfli.gemspec +6 -7
- metadata +13 -54
- data/.travis.yml +0 -23
- data/spec/fixtures/alice29.txt +0 -3609
- data/spec/spec_helper.rb +0 -2
- data/spec/zopfli_spec.rb +0 -68
data/spec/spec_helper.rb
DELETED
data/spec/zopfli_spec.rb
DELETED
@@ -1,68 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'zlib'
|
3
|
-
require 'stringio'
|
4
|
-
require 'benchmark'
|
5
|
-
require 'thread'
|
6
|
-
|
7
|
-
RSpec.describe Zopfli do
|
8
|
-
let(:fixture) { File.read(File.expand_path('fixtures/alice29.txt', File.dirname(__FILE__))) }
|
9
|
-
|
10
|
-
it 'works' do
|
11
|
-
expect(Zopfli.deflate(fixture)).to eq Zopfli.deflate(fixture, format: :zlib)
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'works (zlib format)' do
|
15
|
-
deflated = Zopfli.deflate fixture, format: :zlib
|
16
|
-
|
17
|
-
uncompressed = Zlib::Inflate.inflate deflated
|
18
|
-
|
19
|
-
expect(uncompressed).to eq fixture
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'works (gzip format)' do
|
23
|
-
deflated = Zopfli.deflate fixture, format: :gzip
|
24
|
-
|
25
|
-
uncompressed = Zlib::GzipReader.wrap(StringIO.new(deflated), &:read)
|
26
|
-
|
27
|
-
expect(uncompressed).to eq fixture
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'works (deflate format)' do
|
31
|
-
deflated = Zopfli.deflate fixture, format: :deflate
|
32
|
-
p fixture.bytesize, deflated.bytesize
|
33
|
-
end
|
34
|
-
|
35
|
-
context 'benchmark' do
|
36
|
-
it 'seq' do
|
37
|
-
data = 10.times.map { fixture.dup }
|
38
|
-
deflates = nil
|
39
|
-
t = Benchmark.realtime { deflates = data.map { |datum| Zopfli.deflate datum } }
|
40
|
-
deflates.each { |deflate| expect(Zlib::Inflate.inflate(deflate)).to eq fixture }
|
41
|
-
puts t
|
42
|
-
# => 4.483513999963179
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'thread' do
|
46
|
-
q = Queue.new
|
47
|
-
10.times { q.push fixture.dup }
|
48
|
-
10.times { q.push nil }
|
49
|
-
w = 10.times.map do
|
50
|
-
Thread.new do
|
51
|
-
deflates = []
|
52
|
-
loop do
|
53
|
-
datum = q.pop
|
54
|
-
break if datum.nil?
|
55
|
-
deflates << Zopfli.deflate(datum)
|
56
|
-
end
|
57
|
-
deflates
|
58
|
-
end
|
59
|
-
end
|
60
|
-
deflates = nil
|
61
|
-
t = Benchmark.realtime { deflates = w.map(&:value) }
|
62
|
-
deflates.flatten.each { |deflate| expect(Zlib::Inflate.inflate(deflate)).to eq fixture }
|
63
|
-
puts t
|
64
|
-
# => 2.6099140000296757
|
65
|
-
# => 0.9405940000433475 (w/o gvl)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|