Sha256: 151ab9c0ced39e38f4d6032036ae8337b5ef8d83eeec9f4d8ed9a81bb98ef581

Contents?: true

Size: 1.08 KB

Versions: 5

Compression:

Stored size: 1.08 KB

Contents

require "rubygems"
require "bundler/setup"

require "benchmark"
require "chunky_png"

files = ["pixelstream_reference.png", "operations.png", "clock.png"]

def encode_png(image, constraints = {})
  filesize = nil
  time = Benchmark.realtime { filesize = image.to_blob(constraints).bytesize }
  [filesize, time]
end

files.each do |file|
  filename = File.join(File.dirname(__FILE__), "..", "spec", "resources", file)
  image = ChunkyPNG::Canvas.from_file(filename)

  puts "#{file}: #{image.width}x#{image.height} - #{image.palette.size} colors"
  puts "------------------------------------------------"
  puts "<default>         : %8d bytes in %0.4fs" % encode_png(image)
  puts ":no_compression   : %8d bytes in %0.4fs" % encode_png(image, :no_compression)
  puts ":fast_rgba        : %8d bytes in %0.4fs" % encode_png(image, :fast_rgba)
  puts ":fast_rgb         : %8d bytes in %0.4fs" % encode_png(image, :fast_rgb)
  puts ":good_compression : %8d bytes in %0.4fs" % encode_png(image, :good_compression)
  puts ":best_compression : %8d bytes in %0.4fs" % encode_png(image, :best_compression)
  puts
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
chunky_png-1.4.0 benchmarks/filesize_benchmark.rb
chunky_png-1.3.15 benchmarks/filesize_benchmark.rb
chunky_png-1.3.14 benchmarks/filesize_benchmark.rb
chunky_png-1.3.13 benchmarks/filesize_benchmark.rb
chunky_png-1.3.12 benchmarks/filesize_benchmark.rb