mirror of
https://github.com/Shopify/liquid.git
synced 2025-10-01 00:00:26 -04:00
fixed the performance suite
This commit is contained in:
parent
661ff2ccdf
commit
ce76dbf8d9
6
Rakefile
6
Rakefile
@ -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
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user