File tree Expand file tree Collapse file tree 3 files changed +67
-1
lines changed Expand file tree Collapse file tree 3 files changed +67
-1
lines changed Original file line number Diff line number Diff line change 6
6
7
7
gemspec
8
8
9
- gem 'liquid' , github : 'Shopify/liquid' , ref : 'master '
9
+ gem 'liquid' , github : 'Shopify/liquid' , ref : 'pz-serialize-benchmark-refactor '
10
10
11
11
group :test do
12
12
gem 'rubocop' , '~> 0.93.1' , require : false
Original file line number Diff line number Diff line change @@ -73,11 +73,13 @@ namespace :benchmark do
73
73
desc "Run the liquid benchmark with lax parsing"
74
74
task :run do
75
75
ruby "./performance.rb c benchmark lax"
76
+ ruby "./performance/serialization.rb lax"
76
77
end
77
78
78
79
desc "Run the liquid benchmark with strict parsing"
79
80
task :strict do
80
81
ruby "./performance.rb c benchmark strict"
82
+ ruby "./performance/serialization.rb strict"
81
83
end
82
84
end
83
85
Original file line number Diff line number Diff line change
1
+ # frozen_string_literal: true
2
+
3
+ require 'liquid'
4
+ require 'liquid/c'
5
+ require 'benchmark/ips'
6
+
7
+ liquid_lib_dir = $LOAD_PATH. detect { |p | File . exist? ( File . join ( p , 'liquid.rb' ) ) }
8
+ require File . join ( File . dirname ( liquid_lib_dir ) , "performance/theme_runner.rb" )
9
+
10
+ module SerializationThemeRunner
11
+ def initialize
12
+ super
13
+ serialize_all_tests
14
+ end
15
+
16
+ def deserialize
17
+ @serialized_tests . each do |test |
18
+ Liquid ::Template . load ( test [ :tmpl ] )
19
+ Liquid ::Template . load ( test [ :layout ] )
20
+ end
21
+ end
22
+
23
+ def deserialize_and_render
24
+ @serialized_tests . each do |test |
25
+ tmpl = test [ :tmpl ]
26
+ assigns = test [ :assigns ]
27
+ layout = test [ :layout ]
28
+
29
+ render_layout ( Liquid ::Template . load ( tmpl ) , Liquid ::Template . load ( layout ) , assigns )
30
+ end
31
+ end
32
+
33
+ private
34
+
35
+ def serialize_all_tests
36
+ @serialized_tests = [ ]
37
+ @compiled_tests . each do |test_hash |
38
+ @serialized_tests <<
39
+ if test_hash [ :layout ]
40
+ { tmpl : test_hash [ :tmpl ] . dump , assigns : test_hash [ :assigns ] , layout : test_hash [ :layout ] . dump }
41
+ else
42
+ { tmpl : test_hash [ :tmpl ] . dump , assigns : test_hash [ :assigns ] }
43
+ end
44
+ end
45
+ @serialized_tests
46
+ end
47
+ end
48
+
49
+ ThemeRunner . prepend ( SerializationThemeRunner )
50
+
51
+ Liquid ::Template . error_mode = ARGV . first . to_sym
52
+ profiler = ThemeRunner . new
53
+
54
+ Benchmark . ips do |x |
55
+ x . time = 10
56
+ x . warmup = 5
57
+
58
+ puts
59
+ puts "Running benchmark for #{ x . time } seconds (with #{ x . warmup } seconds warmup)."
60
+ puts
61
+
62
+ x . report ( "deserialize:" ) { profiler . deserialize }
63
+ x . report ( "deserialize & render:" ) { profiler . deserialize_and_render }
64
+ end
You can’t perform that action at this time.
0 commit comments