fixed the performance suite

This commit is contained in:
Tobias Lütke
2012-10-20 10:53:53 -04:00
parent 661ff2ccdf
commit ce76dbf8d9
3 changed files with 21 additions and 20 deletions

View File

@@ -28,8 +28,8 @@ class ThemeRunner
end
def run(profile = false)
RubyProf.measure_mode = RubyProf::WALL_TIME if profile
def run()
RubyProf.measure_mode = RubyProf::WALL_TIME
# Dup assigns because will make some changes to them
assigns = Database.tables.dup
@@ -40,26 +40,27 @@ class ThemeRunner
html = nil
page_template = File.basename(template_name, File.extname(template_name))
# Profile compiling and rendering both
if profile
RubyProf.resume do
html = compile_and_render(liquid, layout, assigns, page_template)
end
else
html = compile_and_render(liquid, layout, assigns, page_template)
unless @started
RubyProf.start
RubyProf.pause
@started = true
end
html = nil
RubyProf.resume
html = compile_and_render(liquid, layout, assigns, page_template)
RubyProf.pause
# return the result and the MD5 of the content, this can be used to detect regressions between liquid version
$stdout.puts "* rendered template %s, content: %s" % [template_name, Digest::MD5.hexdigest(html)] if profile
$stdout.puts "* rendered template %s, content: %s" % [template_name, Digest::MD5.hexdigest(html)]
# Uncomment to dump html files to /tmp so that you can inspect for errors
# File.open("/tmp/#{File.basename(template_name)}.html", "w+") { |fp| fp <<html}
end
RubyProf.stop if profile
RubyProf.stop
end
def compile_and_render(template, layout, assigns, page_template)