Created
March 27, 2021 08:05
-
-
Save nvh0412/9d08bedc70f96152a90827cd6f5cff97 to your computer and use it in GitHub Desktop.
Benchmark mini_mime vs marcel
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 'marcel' | |
require 'memory_profiler' | |
require 'benchmark/ips' | |
puts "Memory stats for requiring mini_mime" | |
result = MemoryProfiler.report do | |
require 'mini_mime' | |
end | |
puts "Total allocated: #{result.total_allocated_memsize} bytes (#{result.total_allocated} objects)" | |
puts "Memory stats for requiring marcel" | |
result = MemoryProfiler.report do | |
require 'marcel' | |
end | |
puts "Total allocated: #{result.total_allocated_memsize} bytes (#{result.total_allocated} objects)" | |
Benchmark.ips do |bm| | |
bm.report 'cached content_type lookup MiniMime' do | |
MiniMime.lookup_by_filename("a.txt").content_type | |
end | |
bm.report 'content_type lookup Marcel::MimeType' do | |
Marcel::MimeType.for "a.txt" | |
end | |
bm.compare! | |
end | |
module MiniMime | |
class Db | |
class RandomAccessDb | |
alias_method :lookup, :lookup_uncached | |
end | |
end | |
end | |
Benchmark.ips do |bm| | |
bm.report 'uncached content_type lookup MiniMime' do | |
MiniMime.lookup_by_filename("a.txt").content_type | |
end | |
bm.report 'content_type lookup Marcel::MimeType' do | |
Marcel::MimeType.for "a.txt" | |
end | |
bm.compare! | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment