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
+3 -3
View File
@@ -27,7 +27,7 @@ namespace :benchmark do
desc "Run the liquid benchmark" desc "Run the liquid benchmark"
task :run do task :run do
ruby "performance/benchmark.rb" ruby "./performance/benchmark.rb"
end end
end end
@@ -37,12 +37,12 @@ namespace :profile do
desc "Run the liquid profile/performance coverage" desc "Run the liquid profile/performance coverage"
task :run do task :run do
ruby "performance/profile.rb" ruby "./performance/profile.rb"
end end
desc "Run KCacheGrind" desc "Run KCacheGrind"
task :grind => :run do task :grind => :run do
system "kcachegrind /tmp/liquid.rubyprof_calltreeprinter.txt" system "qcachegrind /tmp/liquid.rubyprof_calltreeprinter.txt"
end end
end end
+3 -3
View File
@@ -6,14 +6,14 @@ profiler = ThemeRunner.new
puts 'Running profiler...' puts 'Running profiler...'
results = profiler.run(true) results = profiler.run
puts 'Success' puts 'Success'
puts puts
[RubyProf::FlatPrinter, RubyProf::GraphPrinter, RubyProf::GraphHtmlPrinter, RubyProf::CallTreePrinter].each do |klass| [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!(/:+/, '_') 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}" $stderr.puts "wrote #{klass.name} output to #{filename}"
end end
+15 -14
View File
@@ -28,8 +28,8 @@ class ThemeRunner
end end
def run(profile = false) def run()
RubyProf.measure_mode = RubyProf::WALL_TIME if profile RubyProf.measure_mode = RubyProf::WALL_TIME
# Dup assigns because will make some changes to them # Dup assigns because will make some changes to them
assigns = Database.tables.dup assigns = Database.tables.dup
@@ -40,26 +40,27 @@ class ThemeRunner
html = nil html = nil
page_template = File.basename(template_name, File.extname(template_name)) page_template = File.basename(template_name, File.extname(template_name))
# Profile compiling and rendering both unless @started
RubyProf.start
if profile RubyProf.pause
@started = true
RubyProf.resume do
html = compile_and_render(liquid, layout, assigns, page_template)
end
else
html = compile_and_render(liquid, layout, assigns, page_template)
end 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 # 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 # 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} # File.open("/tmp/#{File.basename(template_name)}.html", "w+") { |fp| fp <<html}
end end
RubyProf.stop if profile RubyProf.stop
end end
def compile_and_render(template, layout, assigns, page_template) def compile_and_render(template, layout, assigns, page_template)