Skip to content

Instantly share code, notes, and snippets.

@hainesr
Created May 13, 2018 16:03
Show Gist options
  • Save hainesr/bccf584b828493ce5b36b8708d0bb073 to your computer and use it in GitHub Desktop.
Save hainesr/bccf584b828493ce5b36b8708d0bb073 to your computer and use it in GitHub Desktop.
Test the various default options for ruby Zlib::Deflate.
# Usage:
# ruby zlib_deflate_tests.rb < input_file
#
# Robert Haines
require 'zlib'
puts "Tests for Ruby Zlib\n-------------------\n\n"
comp = [
'Zlib::DEFAULT_COMPRESSION',
'Zlib::NO_COMPRESSION',
'Zlib::BEST_COMPRESSION',
'Zlib::BEST_SPEED'
]
input = ARGF.read
comp.each { |var| puts "#{var}: #{eval(var)}" }
puts "\nInput size (raw): #{input.size}, 100.00%"
puts input[0..50]
puts
comp.each do |var|
output = Zlib::Deflate.deflate(input, eval(var))
puts "Output size (#{var}): #{output.size}, #{(output.size/(input.size * 1.0)) * 100}%"
puts output[0..50]
puts
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment