Created
November 27, 2013 18:39
-
-
Save igrigorik/7680914 to your computer and use it in GitHub Desktop.
Testing various Deflate compression parameters...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Quick comparison of Deflate performance with respec to varios | |
# LZ77 window and memLevel settings. E.g... | |
# | |
# $> curl https://github.com/timeline.json -o timeline.json | |
# $> ruby compare.rb timeline.json | |
# | |
require "zlib" | |
unless file = ARGV[0] | |
puts "Usage: compare.rb <file>" | |
exit(1) | |
end | |
data = IO.read(file) | |
puts "Original file (#{file}) size: #{data.size} bytes" | |
(8..15).each do |window_bits| | |
puts "Window size: #{window_bits} bits (#{2**window_bits} bytes)" | |
(1..9).each do |memLevel| | |
z = Zlib::Deflate.new(nil, window_bits, memLevel) | |
dst = z.deflate(data, Zlib::FINISH) | |
z.close | |
puts "\t memLevel: #{memLevel}, compressed size: #{dst.size} bytes " \ | |
+ "(#{(100-((dst.size.to_f/data.size)*100)).round(2)}% reduction)" | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
igrigorik { ~/Desktop } > ruby compare.rb timeline.json | |
Original file (timeline.json) size: 30437 bytes | |
Window size: 8 bits (256 bytes) | |
memLevel: 1, compressed size: 19472 bytes (36.03% reduction) | |
memLevel: 2, compressed size: 17701 bytes (41.84% reduction) | |
memLevel: 3, compressed size: 16574 bytes (45.55% reduction) | |
memLevel: 4, compressed size: 15872 bytes (47.85% reduction) | |
memLevel: 5, compressed size: 15485 bytes (49.12% reduction) | |
memLevel: 6, compressed size: 15306 bytes (49.71% reduction) | |
memLevel: 7, compressed size: 15216 bytes (50.01% reduction) | |
memLevel: 8, compressed size: 15166 bytes (50.17% reduction) | |
memLevel: 9, compressed size: 15116 bytes (50.34% reduction) | |
Window size: 9 bits (512 bytes) | |
memLevel: 1, compressed size: 19472 bytes (36.03% reduction) | |
memLevel: 2, compressed size: 17701 bytes (41.84% reduction) | |
memLevel: 3, compressed size: 16574 bytes (45.55% reduction) | |
memLevel: 4, compressed size: 15872 bytes (47.85% reduction) | |
memLevel: 5, compressed size: 15485 bytes (49.12% reduction) | |
memLevel: 6, compressed size: 15306 bytes (49.71% reduction) | |
memLevel: 7, compressed size: 15216 bytes (50.01% reduction) | |
memLevel: 8, compressed size: 15166 bytes (50.17% reduction) | |
memLevel: 9, compressed size: 15116 bytes (50.34% reduction) | |
Window size: 10 bits (1024 bytes) | |
memLevel: 1, compressed size: 16218 bytes (46.72% reduction) | |
memLevel: 2, compressed size: 14881 bytes (51.11% reduction) | |
memLevel: 3, compressed size: 14032 bytes (53.9% reduction) | |
memLevel: 4, compressed size: 13488 bytes (55.69% reduction) | |
memLevel: 5, compressed size: 13220 bytes (56.57% reduction) | |
memLevel: 6, compressed size: 13061 bytes (57.09% reduction) | |
memLevel: 7, compressed size: 12971 bytes (57.38% reduction) | |
memLevel: 8, compressed size: 12921 bytes (57.55% reduction) | |
memLevel: 9, compressed size: 12921 bytes (57.55% reduction) | |
Window size: 11 bits (2048 bytes) | |
memLevel: 1, compressed size: 9797 bytes (67.81% reduction) | |
memLevel: 2, compressed size: 9077 bytes (70.18% reduction) | |
memLevel: 3, compressed size: 8626 bytes (71.66% reduction) | |
memLevel: 4, compressed size: 8359 bytes (72.54% reduction) | |
memLevel: 5, compressed size: 8180 bytes (73.12% reduction) | |
memLevel: 6, compressed size: 8110 bytes (73.35% reduction) | |
memLevel: 7, compressed size: 8062 bytes (73.51% reduction) | |
memLevel: 8, compressed size: 8062 bytes (73.51% reduction) | |
memLevel: 9, compressed size: 8062 bytes (73.51% reduction) | |
Window size: 12 bits (4096 bytes) | |
memLevel: 1, compressed size: 8853 bytes (70.91% reduction) | |
memLevel: 2, compressed size: 8228 bytes (72.97% reduction) | |
memLevel: 3, compressed size: 7833 bytes (74.26% reduction) | |
memLevel: 4, compressed size: 7613 bytes (74.99% reduction) | |
memLevel: 5, compressed size: 7489 bytes (75.4% reduction) | |
memLevel: 6, compressed size: 7410 bytes (75.65% reduction) | |
memLevel: 7, compressed size: 7363 bytes (75.81% reduction) | |
memLevel: 8, compressed size: 7363 bytes (75.81% reduction) | |
memLevel: 9, compressed size: 7363 bytes (75.81% reduction) | |
Window size: 13 bits (8192 bytes) | |
memLevel: 1, compressed size: 8518 bytes (72.01% reduction) | |
memLevel: 2, compressed size: 7928 bytes (73.95% reduction) | |
memLevel: 3, compressed size: 7537 bytes (75.24% reduction) | |
memLevel: 4, compressed size: 7316 bytes (75.96% reduction) | |
memLevel: 5, compressed size: 7199 bytes (76.35% reduction) | |
memLevel: 6, compressed size: 7162 bytes (76.47% reduction) | |
memLevel: 7, compressed size: 7114 bytes (76.63% reduction) | |
memLevel: 8, compressed size: 7112 bytes (76.63% reduction) | |
memLevel: 9, compressed size: 7114 bytes (76.63% reduction) | |
Window size: 14 bits (16384 bytes) | |
memLevel: 1, compressed size: 8368 bytes (72.51% reduction) | |
memLevel: 2, compressed size: 7814 bytes (74.33% reduction) | |
memLevel: 3, compressed size: 7440 bytes (75.56% reduction) | |
memLevel: 4, compressed size: 7225 bytes (76.26% reduction) | |
memLevel: 5, compressed size: 7108 bytes (76.65% reduction) | |
memLevel: 6, compressed size: 7083 bytes (76.73% reduction) | |
memLevel: 7, compressed size: 7036 bytes (76.88% reduction) | |
memLevel: 8, compressed size: 7034 bytes (76.89% reduction) | |
memLevel: 9, compressed size: 7036 bytes (76.88% reduction) | |
Window size: 15 bits (32768 bytes) | |
memLevel: 1, compressed size: 8327 bytes (72.64% reduction) | |
memLevel: 2, compressed size: 7787 bytes (74.42% reduction) | |
memLevel: 3, compressed size: 7410 bytes (75.65% reduction) | |
memLevel: 4, compressed size: 7201 bytes (76.34% reduction) | |
memLevel: 5, compressed size: 7089 bytes (76.71% reduction) | |
memLevel: 6, compressed size: 7065 bytes (76.79% reduction) | |
memLevel: 7, compressed size: 7027 bytes (76.91% reduction) | |
memLevel: 8, compressed size: 7024 bytes (76.92% reduction) | |
memLevel: 9, compressed size: 7027 bytes (76.91% reduction) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment