Created
May 13, 2018 16:03
-
-
Save hainesr/bccf584b828493ce5b36b8708d0bb073 to your computer and use it in GitHub Desktop.
Test the various default options for ruby Zlib::Deflate.
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
# 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