Created
March 1, 2016 15:18
-
-
Save mechanicles/da40a518e9c6593686cb to your computer and use it in GitHub Desktop.
Profile with freeze
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 'memory_profiler' | |
require 'active_support/core_ext/string' | |
def translate_using_freeze(key) | |
if key.to_s.first == '.'.freeze | |
"products/index".tr('/'.freeze, '.'.freeze) | |
end | |
end | |
report = MemoryProfiler.report(ignore_files: 'active_support/core_ext/string') do | |
30.times { translate_using_freeze('.name') } | |
end | |
report.pretty_print | |
# allocated memory by file | |
# ----------------------------------- | |
# 3600 benchmark_with_freeze.rb | |
# allocated objects by file | |
# ----------------------------------- | |
# 90 benchmark_with_freeze.rb | |
# Allocated String Report | |
# ----------------------------------- | |
# 30 ".name" | |
# 30 benchmark_with_freeze.rb:11 | |
# | |
# 30 "products.index" | |
# 30 benchmark_with_freeze.rb:6 | |
# | |
# 30 "products/index" | |
# 30 benchmark_with_freeze.rb:6 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment