Faster Tagz
This commit is contained in:
parent
47d5ab67a0
commit
e031b29205
17
Gemfile
17
Gemfile
|
@ -5,14 +5,13 @@ gem 'tilt'
|
|||
|
||||
gem 'erubis'
|
||||
gem 'haml'
|
||||
gem 'slim'
|
||||
gem 'liquid'
|
||||
gem 'mustache'
|
||||
gem 'markaby'
|
||||
gem 'tenjin'
|
||||
gem 'handlebars'
|
||||
gem 'tagz'
|
||||
|
||||
# gem 'liquor' # No docs - no wrapper
|
||||
# gem 'parkaby', github: 'judofyr/parkaby' # No gemspec
|
||||
# gem 'laminate' # No gemspec, dead
|
||||
gem 'liquid'
|
||||
# gem 'liquor' # No docs - no wrapper
|
||||
gem 'markaby'
|
||||
gem 'mustache'
|
||||
# gem 'parkaby', github: 'judofyr/parkaby' # No gemspec
|
||||
gem 'slim'
|
||||
gem 'tagz'
|
||||
gem 'tenjin'
|
||||
|
|
89
README.md
89
README.md
|
@ -11,6 +11,7 @@
|
|||
- [Markaby](http://markaby.github.io/)
|
||||
- [Mustache](https://github.com/defunkt/mustache)
|
||||
- [Slim](http://slim-lang.com/)
|
||||
- [Tagz](https://github.com/ahoward/tagz)
|
||||
- [Tenjin](http://www.kuwata-lab.com/tenjin/)
|
||||
|
||||
... and our special guest ...
|
||||
|
@ -39,59 +40,67 @@ bundle install
|
|||
## Compilation (small template) - 1.000 runs ##
|
||||
############################################################
|
||||
user system total real
|
||||
tenjin 0.010000 0.010000 0.020000 ( 0.015441)
|
||||
string 0.040000 0.020000 0.060000 ( 0.051998)
|
||||
erubis 0.050000 0.010000 0.060000 ( 0.076408)
|
||||
erb 0.220000 0.020000 0.240000 ( 0.247821)
|
||||
haml 0.850000 0.040000 0.890000 ( 0.888733)
|
||||
slim 1.910000 0.030000 1.940000 ( 1.945333)
|
||||
mustache 0.020000 0.010000 0.030000 ( 0.028953)
|
||||
liquid 0.060000 0.020000 0.080000 ( 0.072093)
|
||||
markaby 0.020000 0.020000 0.040000 ( 0.039350)
|
||||
builder 0.020000 0.010000 0.030000 ( 0.039334)
|
||||
builder 0.040000 0.010000 0.050000 ( 0.051603)
|
||||
erb 0.240000 0.020000 0.260000 ( 0.252003)
|
||||
erubis 0.060000 0.020000 0.080000 ( 0.082601)
|
||||
haml 0.850000 0.030000 0.880000 ( 0.880267)
|
||||
handlebars 0.100000 0.030000 0.130000 ( 0.124923)
|
||||
liquid 0.050000 0.020000 0.070000 ( 0.074742)
|
||||
markaby 0.020000 0.010000 0.030000 ( 0.040555)
|
||||
mustache 0.020000 0.020000 0.040000 ( 0.028828)
|
||||
slim 1.980000 0.050000 2.030000 ( 2.038820)
|
||||
string 0.030000 0.020000 0.050000 ( 0.045661)
|
||||
tagz 0.010000 0.000000 0.010000 ( 0.017564)
|
||||
tenjin 0.010000 0.010000 0.020000 ( 0.015479)
|
||||
|
||||
############################################################
|
||||
## Render (small template) - 10.000 runs ##
|
||||
############################################################
|
||||
user system total real
|
||||
tenjin 0.100000 0.010000 0.110000 ( 0.100912)
|
||||
string 0.070000 0.010000 0.080000 ( 0.073216)
|
||||
erubis 0.080000 0.000000 0.080000 ( 0.076072)
|
||||
erb 0.120000 0.000000 0.120000 ( 0.113194)
|
||||
haml 0.200000 0.000000 0.200000 ( 0.197601)
|
||||
slim 0.210000 0.010000 0.220000 ( 0.208949)
|
||||
mustache 2.370000 0.060000 2.430000 ( 2.434160)
|
||||
liquid 0.360000 0.000000 0.360000 ( 0.362223)
|
||||
markaby 2.350000 0.030000 2.380000 ( 2.366150)
|
||||
builder 1.880000 0.000000 1.880000 ( 1.879207)
|
||||
builder 1.890000 0.000000 1.890000 ( 1.893341)
|
||||
erb 0.110000 0.000000 0.110000 ( 0.109126)
|
||||
erubis 0.080000 0.000000 0.080000 ( 0.078112)
|
||||
haml 0.210000 0.010000 0.220000 ( 0.212483)
|
||||
handlebars 0.690000 0.040000 0.730000 ( 0.701104)
|
||||
liquid 0.350000 0.000000 0.350000 ( 0.353939)
|
||||
markaby 2.450000 0.070000 2.520000 ( 2.518086)
|
||||
mustache 2.510000 0.060000 2.570000 ( 2.569790)
|
||||
slim 0.210000 0.010000 0.220000 ( 0.213641)
|
||||
string 0.090000 0.000000 0.090000 ( 0.091101)
|
||||
tagz 1.010000 0.020000 1.030000 ( 1.035361)
|
||||
tenjin 0.110000 0.000000 0.110000 ( 0.112881)
|
||||
|
||||
############################################################
|
||||
## Compilation (big template) - 1.000 runs ##
|
||||
############################################################
|
||||
user system total real
|
||||
tenjin 0.010000 0.010000 0.020000 ( 0.015806)
|
||||
string 0.020000 0.020000 0.040000 ( 0.043971)
|
||||
erubis 0.110000 0.020000 0.130000 ( 0.136185)
|
||||
erb 0.290000 0.020000 0.310000 ( 0.306882)
|
||||
haml 1.170000 0.020000 1.190000 ( 1.189052)
|
||||
slim 2.350000 0.030000 2.380000 ( 2.394175)
|
||||
mustache 0.020000 0.010000 0.030000 ( 0.029711)
|
||||
liquid 0.110000 0.020000 0.130000 ( 0.129459)
|
||||
markaby 0.020000 0.020000 0.040000 ( 0.039971)
|
||||
builder 0.030000 0.010000 0.040000 ( 0.040546)
|
||||
builder 0.020000 0.020000 0.040000 ( 0.043931)
|
||||
erb 0.280000 0.020000 0.300000 ( 0.302882)
|
||||
erubis 0.110000 0.020000 0.130000 ( 0.135634)
|
||||
haml 1.140000 0.030000 1.170000 ( 1.171942)
|
||||
handlebars 0.100000 0.030000 0.130000 ( 0.118258)
|
||||
liquid 0.110000 0.020000 0.130000 ( 0.130391)
|
||||
markaby 0.020000 0.010000 0.030000 ( 0.042543)
|
||||
mustache 0.020000 0.020000 0.040000 ( 0.035402)
|
||||
slim 2.400000 0.040000 2.440000 ( 2.440354)
|
||||
string 0.030000 0.020000 0.050000 ( 0.044737)
|
||||
tagz 0.010000 0.010000 0.020000 ( 0.017057)
|
||||
tenjin 0.010000 0.000000 0.010000 ( 0.015773)
|
||||
|
||||
############################################################
|
||||
## Render (big template, 150KB data) - 50 runs ##
|
||||
############################################################
|
||||
user system total real
|
||||
tenjin 0.160000 0.010000 0.170000 ( 0.170591)
|
||||
string 0.180000 0.020000 0.200000 ( 0.195720)
|
||||
erubis 0.210000 0.010000 0.220000 ( 0.217161)
|
||||
erb 0.300000 0.010000 0.310000 ( 0.316516)
|
||||
haml 0.460000 0.010000 0.470000 ( 0.469774)
|
||||
slim 0.680000 0.000000 0.680000 ( 0.685463)
|
||||
mustache 1.860000 0.000000 1.860000 ( 1.871303)
|
||||
liquid 5.240000 0.020000 5.260000 ( 5.269241)
|
||||
markaby 5.770000 0.010000 5.780000 ( 5.780620)
|
||||
builder 9.320000 0.020000 9.340000 ( 9.343587)
|
||||
builder 9.270000 0.030000 9.300000 ( 9.289956)
|
||||
erb 0.310000 0.000000 0.310000 ( 0.313369)
|
||||
erubis 0.200000 0.010000 0.210000 ( 0.214869)
|
||||
haml 0.490000 0.010000 0.500000 ( 0.495157)
|
||||
handlebars 5.170000 0.060000 5.230000 ( 5.221436)
|
||||
liquid 5.770000 0.050000 5.820000 ( 5.836171)
|
||||
markaby 6.280000 0.020000 6.300000 ( 6.303951)
|
||||
mustache 2.160000 0.000000 2.160000 ( 2.164364)
|
||||
slim 0.700000 0.010000 0.710000 ( 0.702391)
|
||||
string 0.350000 0.020000 0.370000 ( 0.370049)
|
||||
tagz 10.670000 0.190000 10.860000 ( 10.868873)
|
||||
tenjin 0.240000 0.010000 0.250000 ( 0.255957)
|
||||
```
|
||||
|
|
54
benchmark.rb
54
benchmark.rb
|
@ -9,33 +9,25 @@ $ ./fakedata.rb 10000 > data/big.yml
|
|||
AGRR
|
||||
|
||||
Workbench::Benchmark.describe_engines(
|
||||
string: {
|
||||
class: Tilt::StringTemplate,
|
||||
extension: 'str'
|
||||
},
|
||||
erubis: {
|
||||
class: Tilt::ErubisTemplate,
|
||||
extension: 'erubis'
|
||||
},
|
||||
tenjin: {
|
||||
class: Workbench::Wrappers::Tenjin,
|
||||
extension: 'rbhtml'
|
||||
builder: {
|
||||
class: Tilt::BuilderTemplate,
|
||||
extension: 'builder'
|
||||
},
|
||||
erb: {
|
||||
class: Tilt::ERBTemplate,
|
||||
extension: 'erb'
|
||||
},
|
||||
erubis: {
|
||||
class: Tilt::ErubisTemplate,
|
||||
extension: 'erubis'
|
||||
},
|
||||
haml: {
|
||||
class: Tilt::HamlTemplate,
|
||||
extension: 'haml'
|
||||
},
|
||||
slim: {
|
||||
class: Workbench::Wrappers::Slim,
|
||||
extension: 'slim'
|
||||
},
|
||||
mustache: {
|
||||
class: Workbench::Wrappers::Mustache,
|
||||
extension: 'mustache'
|
||||
handlebars: {
|
||||
class: Workbench::Wrappers::Handlebars,
|
||||
extension: 'handlebars'
|
||||
},
|
||||
liquid: {
|
||||
class: Tilt::LiquidTemplate,
|
||||
|
@ -45,21 +37,25 @@ Workbench::Benchmark.describe_engines(
|
|||
class: Tilt::MarkabyTemplate,
|
||||
extension: 'mab'
|
||||
},
|
||||
builder: {
|
||||
class: Tilt::BuilderTemplate,
|
||||
extension: 'builder'
|
||||
mustache: {
|
||||
class: Workbench::Wrappers::Mustache,
|
||||
extension: 'mustache'
|
||||
},
|
||||
handlebars: {
|
||||
class: Workbench::Wrappers::Handlebars,
|
||||
extension: 'handlebars'
|
||||
slim: {
|
||||
class: Workbench::Wrappers::Slim,
|
||||
extension: 'slim'
|
||||
},
|
||||
string: {
|
||||
class: Tilt::StringTemplate,
|
||||
extension: 'str'
|
||||
},
|
||||
# parkaby: {
|
||||
# class: Workbench::Wrappers::Parkaby,
|
||||
# extension: 'mab'
|
||||
# },
|
||||
tagz: {
|
||||
class: Workbench::Wrappers::Tagz,
|
||||
extension: 'tagz'
|
||||
extension: 'rb'
|
||||
},
|
||||
tenjin: {
|
||||
class: Workbench::Wrappers::Tenjin,
|
||||
extension: 'rbhtml'
|
||||
},
|
||||
)
|
||||
|
||||
|
|
|
@ -8,13 +8,13 @@ require 'ostruct'
|
|||
|
||||
require 'erubis'
|
||||
require 'haml'
|
||||
require 'slim'
|
||||
require 'handlebars'
|
||||
require 'liquid'
|
||||
require 'mustache'
|
||||
require 'tenjin'
|
||||
require 'handlebars'
|
||||
# require 'parkaby'
|
||||
require 'slim'
|
||||
require 'tagz'
|
||||
|
||||
require 'tenjin'
|
||||
require 'tilt/erb'
|
||||
require 'tilt/erubis'
|
||||
require 'tilt/haml'
|
||||
|
@ -22,9 +22,8 @@ require 'tilt/liquid'
|
|||
|
||||
require 'workbench/benchmark'
|
||||
require 'workbench/wrappers/base'
|
||||
require 'workbench/wrappers/handlebars'
|
||||
require 'workbench/wrappers/mustache'
|
||||
require 'workbench/wrappers/slim'
|
||||
require 'workbench/wrappers/tenjin'
|
||||
require 'workbench/wrappers/handlebars'
|
||||
require 'workbench/wrappers/parkaby'
|
||||
require 'workbench/wrappers/tagz'
|
||||
require 'workbench/wrappers/tenjin'
|
||||
|
|
|
@ -2,30 +2,32 @@ module Workbench
|
|||
module Wrappers
|
||||
class Tagz < Base
|
||||
def initialize path
|
||||
@tpl = File.read(path)
|
||||
@context = Context.new
|
||||
require path
|
||||
|
||||
if path.end_with?('small.rb')
|
||||
@tpl = TagzTemplates::Small.new
|
||||
else
|
||||
@tpl = TagzTemplates::Big.new
|
||||
end
|
||||
end
|
||||
|
||||
def render context, args = {}
|
||||
@context.with_args(args).instance_eval(tpl)
|
||||
end
|
||||
|
||||
class Context
|
||||
include ::Tagz
|
||||
|
||||
def with_args args
|
||||
@args = args
|
||||
self
|
||||
end
|
||||
|
||||
def method_missing method, *args
|
||||
if @args.key?(method)
|
||||
@args[method]
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
@tpl.with_args(args).render
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
module TagzTemplates
|
||||
class Base
|
||||
include Tagz
|
||||
|
||||
def with_args args
|
||||
args.each do |key, val|
|
||||
instance_variable_set(:"@#{key}", val)
|
||||
end
|
||||
|
||||
self
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
module TagzTemplates
|
||||
class Big < Base
|
||||
def render
|
||||
html_{
|
||||
head_{
|
||||
title_ 'Customers List'
|
||||
}
|
||||
body_{
|
||||
@customers.each{ |customer|
|
||||
dl_{
|
||||
dt_ 'Name:'
|
||||
dd_ customer['name']
|
||||
dt_ 'Age:'
|
||||
dd_ customer['age']
|
||||
dt_ 'Address:'
|
||||
dd_{
|
||||
[
|
||||
customer['zip'],
|
||||
customer['country'],
|
||||
customer['city'],
|
||||
customer['address']
|
||||
].join("\n")
|
||||
}
|
||||
dt_ 'Employer:'
|
||||
dd_ customer['employer']
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,26 +0,0 @@
|
|||
html_{
|
||||
head_{
|
||||
title_ 'Customers List'
|
||||
}
|
||||
body_{
|
||||
customers.each{ |customer|
|
||||
dl_{
|
||||
dt_ 'Name:'
|
||||
dd_ customer['name']
|
||||
dt_ 'Age:'
|
||||
dd_ customer['age']
|
||||
dt_ 'Address:'
|
||||
dd_{
|
||||
[
|
||||
customer['zip'],
|
||||
customer['country'],
|
||||
customer['city'],
|
||||
customer['address']
|
||||
].join("\n")
|
||||
}
|
||||
dt_ 'Employer:'
|
||||
dd_ customer['employer']
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
module TagzTemplates
|
||||
class Small < Base
|
||||
def render
|
||||
html_{
|
||||
head_{
|
||||
title_ @window_title
|
||||
}
|
||||
body_{
|
||||
h1_ "Hello, #{@username}!"
|
||||
p_{
|
||||
<<-END
|
||||
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
|
||||
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
|
||||
veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
|
||||
commodo consequat. Duis aute irure dolor in reprehenderit in voluptate
|
||||
velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint
|
||||
occaecat cupidatat non proident, sunt in culpa qui officia deserunt
|
||||
mollit anim id est laborum.
|
||||
END
|
||||
}
|
||||
}
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,19 +0,0 @@
|
|||
html_{
|
||||
head_{
|
||||
title_ window_title
|
||||
}
|
||||
body_{
|
||||
h1_ "Hello, #{username}!"
|
||||
p_{
|
||||
<<-END
|
||||
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
|
||||
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
|
||||
veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
|
||||
commodo consequat. Duis aute irure dolor in reprehenderit in voluptate
|
||||
velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint
|
||||
occaecat cupidatat non proident, sunt in culpa qui officia deserunt
|
||||
mollit anim id est laborum.
|
||||
END
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue