Created
December 16, 2019 08:53
-
-
Save julianrubisch/637bc6fa3fec4f7b9dba0624935cda31 to your computer and use it in GitHub Desktop.
benchmarking partials
This file contains 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 "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