Created
March 30, 2011 23:26
-
-
Save pbosetti/895517 to your computer and use it in GitHub Desktop.
Testing zlib compression on strings
This file contains hidden or 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
#!/usr/bin/env ruby | |
# untitled.rb | |
# Created by Paolo Bosetti on 2011-03-30. | |
# Copyright (c) 2011 University of Trento. All rights reserved. | |
require "zlib" | |
str = "" | |
100.times do |i| | |
str << ("%d\t%9.3f\t%9.3f\n" % [i, i.to_f, i.to_f ** 2]) | |
end | |
level = [Zlib::NO_COMPRESSION, Zlib::BEST_SPEED, Zlib::BEST_COMPRESSION, Zlib::DEFAULT_COMPRESSION] + (0..9).to_a | |
strz = "" | |
level.each do |l| | |
strz = Zlib::Deflate.deflate(str, l) | |
puts "level #{l}: #{str.size} -> #{strz.size}" | |
end | |
puts Zlib::Inflate.inflate(strz) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment