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

@ -27,7 +27,7 @@ namespace :benchmark do
desc "Run the liquid benchmark"
task :run do
ruby "performance/benchmark.rb"
ruby "./performance/benchmark.rb"
end
end
@ -37,12 +37,12 @@ namespace :profile do
desc "Run the liquid profile/performance coverage"
task :run do
ruby "performance/profile.rb"
ruby "./performance/profile.rb"
end
desc "Run KCacheGrind"
task :grind => :run do
system "kcachegrind /tmp/liquid.rubyprof_calltreeprinter.txt"
system "qcachegrind /tmp/liquid.rubyprof_calltreeprinter.txt"
end
end

View File

@ -6,14 +6,14 @@ profiler = ThemeRunner.new
puts 'Running profiler...'
results = profiler.run(true)
results = profiler.run
puts 'Success'
puts
[RubyProf::FlatPrinter, RubyProf::GraphPrinter, RubyProf::GraphHtmlPrinter, RubyProf::CallTreePrinter].each do |klass|
filename = (ENV['TMP'] || '/tmp') + (klass.name.include?('Html') ? "/liquid.#{klass.name.downcase}.html" : "/liquid.#{klass.name.downcase}.txt")
filename = (ENV['TMP'] || '/tmp') + (klass.name.include?('Html') ? "/liquid.#{klass.name.downcase}.html" : "/callgrind.liquid.#{klass.name.downcase}.txt")
filename.gsub!(/:+/, '_')
File.open(filename, "w+") { |fp| klass.new(results).print(fp) }
File.open(filename, "w+") { |fp| klass.new(results).print(fp, :print_file => true) }
$stderr.puts "wrote #{klass.name} output to #{filename}"
end

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)