From ce76dbf8d92227ecadcdead441f7be376628e1a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Lu=CC=88tke?= Date: Sat, 20 Oct 2012 10:53:53 -0400 Subject: [PATCH] fixed the performance suite --- Rakefile | 6 +++--- performance/profile.rb | 6 +++--- performance/theme_runner.rb | 29 +++++++++++++++-------------- 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/Rakefile b/Rakefile index c6e1932b..862e80f5 100755 --- a/Rakefile +++ b/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 diff --git a/performance/profile.rb b/performance/profile.rb index 61688c58..c07be5c5 100644 --- a/performance/profile.rb +++ b/performance/profile.rb @@ -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 diff --git a/performance/theme_runner.rb b/performance/theme_runner.rb index ffac20ed..2c155f4c 100644 --- a/performance/theme_runner.rb +++ b/performance/theme_runner.rb @@ -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 <