Skip to content

Instantly share code, notes, and snippets.

@julianrubisch
Created December 16, 2019 08:53
Show Gist options
  • Save julianrubisch/637bc6fa3fec4f7b9dba0624935cda31 to your computer and use it in GitHub Desktop.
Save julianrubisch/637bc6fa3fec4f7b9dba0624935cda31 to your computer and use it in GitHub Desktop.
benchmarking partials
require "benchmark-malloc"
require "slim"
require "action_view"
class BenchmarkView < ActionView::Base
def benchmark
bench_malloc = Benchmark::Malloc.new
stats = bench_malloc.run {
render partial: "my_partial", locals: {}
}
puts "Memory:"
puts "Total: #{stats.allocated.total_memory}"
puts stats.allocated.count_memory
puts "\nObjects:"
puts "Total: #{stats.allocated.total_objects}"
puts stats.allocated.count_objects
end
end
BenchmarkView.new(ActionView::LookupContext.new(File.expand_path("app/views"), {})).benchmark
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment