Last active
December 14, 2022 09:15
-
-
Save janko/c539732abac966693398e216eb90651b to your computer and use it in GitHub Desktop.
MiniMagick vs libvips benchmark (generating a 500x500 thumbnail)
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
width, imagemagick, libvips | |
1000, 0.129, 0.045 | |
1500, 0.190, 0.067 | |
2000, 0.276, 0.054 | |
2500, 0.380, 0.068 | |
3000, 0.498, 0.085 |
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
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
In bundle 2.3.16
Need to add