MiniMagick vs libvips benchmark (generating a 500x500 thumbnail)
require "bundler/inline" | |
gemfile do | |
gem "image_processing" | |
gem "down" | |
gem "benchmark-ips" | |
end | |
require "image_processing/mini_magick" # imagemagick 7.0.8-59 | |
require "image_processing/vips" # vips 8.8.1 | |
require "down" | |
require "benchmark/ips" | |
require "csv" | |
# disable cache | |
Vips.vips_cache_set_max 0 | |
csv = CSV.new(STDOUT) | |
csv << ["width", "imagemagick", "libvips"] | |
1000.step(by: 500, to: 3000) do |source_width| | |
source = Down.download("https://images.unsplash.com/photo-1549221838-126dc3ebf29f?ixlib=rb-1.2.1&q=85&fm=jpg&crop=entropy&cs=srgb&w=#{source_width}") | |
result = Benchmark.ips(quiet: true) do |x| | |
x.report("imagemagick (#{source_width}px)") do | |
ImageProcessing::MiniMagick | |
.source(source) | |
.resize_to_limit!(500, 500) | |
end | |
x.report("libvips (#{source_width}px)") do | |
ImageProcessing::Vips | |
.source(source) | |
.resize_to_limit!(500, 500) | |
end | |
end | |
imagemagick_duration = 1 / result.data.first.fetch(:ips) | |
libvips_duration = 1 / result.data.last.fetch(:ips) | |
csv << [source_width, "%.3f" % imagemagick_duration, "%.3f" % libvips_duration] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment