Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added minimagick for comparison to ruby-vps #7

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .ruby-gemset
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node-ruby-img
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ruby-2.4.2
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
source "https://rubygems.org"

gem 'ruby-vips'
gem 'mini_magick'
7 changes: 6 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
namespace :run do
desc "Run Ruby Minimagick benchmark"
task "ruby:mini" do
sh "ruby ruby_io_speed_mm.rb"
end

desc "Run Ruby benchmark"
task :ruby do
sh "ruby ruby_io_speed.rb"
Expand All @@ -15,7 +20,7 @@ namespace :run do
end

desc "Run all benchmarks"
task :all => [:ruby, :node, "node:streams"]
task :all => ["ruby:mini", :ruby, :node, "node:streams"]
end

namespace :install do
Expand Down
29 changes: 29 additions & 0 deletions mem.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require 'thread'

# Credits: http://zogovic.com/post/59091704817/memory-usage-monitor-in-ruby

class MemoryUsageMonitor
attr_reader :peak_memory, :log

def initialize(frequency: 0.25)
@frequency = frequency
@peak_memory = 0
@log = []
end

def start
@thread = Thread.new do
while true do
puts "#{Process::pid}"
memory = `ps -o rss -p #{Process::pid}`.chomp.split("\n").last.strip.to_i
@log.push memory
@peak_memory = [memory, @peak_memory].max
sleep @frequency
end
end
end

def stop
Thread.kill(@thread)
end
end
2 changes: 1 addition & 1 deletion node_io_speed.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var SIZES = {
var performUpload = function(size, next){
var name = size + ".jpg"
sharp('cakes.jpg')
.resize(SIZES[size][0], SIZES[size][1])
.resize(SIZES[size][0])
.toFile(name, next);
}

Expand Down
2 changes: 1 addition & 1 deletion node_io_speed_streams.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var performUpload = function(size, next){
var resizer = function(){
var client = sharp()
return client.resize.
apply(client, SIZES[size])
apply(client, [SIZES[size][0]])
}

var stream = image.pipe(resizer(size)).pipe(fs.createWriteStream(name))
Expand Down
263 changes: 237 additions & 26 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion ruby_io_speed.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require "vips"

ORIGINAL = "cakes.jpg"
Expand All @@ -17,4 +18,6 @@
end
end.each(&:join)

puts "Took: #{((Time.now - start) * 1000).to_i}ms"
stop = Time.now

puts "Took: #{((stop - start) * 1000).to_i}ms"
Loading