From 05d9976e1603eb461294daf1a43564bbd03a6ab0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Lu=CC=88tke?= Date: Mon, 29 Oct 2012 16:47:57 -0400 Subject: [PATCH] fix benchmark --- performance/benchmark.rb | 3 ++- performance/theme_runner.rb | 27 ++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/performance/benchmark.rb b/performance/benchmark.rb index 74301ee..afb6ffa 100644 --- a/performance/benchmark.rb +++ b/performance/benchmark.rb @@ -5,6 +5,7 @@ require File.dirname(__FILE__) + '/theme_runner' profiler = ThemeRunner.new Benchmark.bmbm do |x| - x.report("parse & run:") { 10.times { profiler.run(false) } } + x.report("parse:") { 100.times { profiler.compile } } + x.report("parse & run:") { 100.times { profiler.run } } end diff --git a/performance/theme_runner.rb b/performance/theme_runner.rb index 2c155f4..98406b3 100644 --- a/performance/theme_runner.rb +++ b/performance/theme_runner.rb @@ -27,8 +27,33 @@ class ThemeRunner end.compact end + def compile + # Dup assigns because will make some changes to them - def run() + @tests.each do |liquid, layout, template_name| + + tmpl = Liquid::Template.new + tmpl.parse(liquid) + tmpl = Liquid::Template.new + tmpl.parse(layout) + end + end + + def run + # Dup assigns because will make some changes to them + assigns = Database.tables.dup + + @tests.each do |liquid, layout, template_name| + + # Compute page_tempalte outside of profiler run, uninteresting to profiler + page_template = File.basename(template_name, File.extname(template_name)) + compile_and_render(liquid, layout, assigns, page_template) + + end + end + + + def run_profile RubyProf.measure_mode = RubyProf::WALL_TIME # Dup assigns because will make some changes to them