zopfli 0.0.8 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +0,0 @@
1
- $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
- require 'zopfli'
@@ -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