1
0
Fork 0

Faster Tagz

This commit is contained in:
Gregory Eremin 2013-12-15 04:06:34 +07:00
parent 47d5ab67a0
commit e031b29205
No known key found for this signature in database
GPG Key ID: 5EFA427EEC26E86C
9 changed files with 167 additions and 150 deletions

17
Gemfile
View File

@ -5,14 +5,13 @@ gem 'tilt'
gem 'erubis' gem 'erubis'
gem 'haml' gem 'haml'
gem 'slim'
gem 'liquid'
gem 'mustache'
gem 'markaby'
gem 'tenjin'
gem 'handlebars' gem 'handlebars'
gem 'tagz'
# gem 'liquor' # No docs - no wrapper
# gem 'parkaby', github: 'judofyr/parkaby' # No gemspec
# gem 'laminate' # No gemspec, dead # 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'

View File

@ -11,6 +11,7 @@
- [Markaby](http://markaby.github.io/) - [Markaby](http://markaby.github.io/)
- [Mustache](https://github.com/defunkt/mustache) - [Mustache](https://github.com/defunkt/mustache)
- [Slim](http://slim-lang.com/) - [Slim](http://slim-lang.com/)
- [Tagz](https://github.com/ahoward/tagz)
- [Tenjin](http://www.kuwata-lab.com/tenjin/) - [Tenjin](http://www.kuwata-lab.com/tenjin/)
... and our special guest ... ... and our special guest ...
@ -39,59 +40,67 @@ bundle install
## Compilation (small template) - 1.000 runs ## ## Compilation (small template) - 1.000 runs ##
############################################################ ############################################################
user system total real user system total real
tenjin 0.010000 0.010000 0.020000 ( 0.015441) builder 0.040000 0.010000 0.050000 ( 0.051603)
string 0.040000 0.020000 0.060000 ( 0.051998) erb 0.240000 0.020000 0.260000 ( 0.252003)
erubis 0.050000 0.010000 0.060000 ( 0.076408) erubis 0.060000 0.020000 0.080000 ( 0.082601)
erb 0.220000 0.020000 0.240000 ( 0.247821) haml 0.850000 0.030000 0.880000 ( 0.880267)
haml 0.850000 0.040000 0.890000 ( 0.888733) handlebars 0.100000 0.030000 0.130000 ( 0.124923)
slim 1.910000 0.030000 1.940000 ( 1.945333) liquid 0.050000 0.020000 0.070000 ( 0.074742)
mustache 0.020000 0.010000 0.030000 ( 0.028953) markaby 0.020000 0.010000 0.030000 ( 0.040555)
liquid 0.060000 0.020000 0.080000 ( 0.072093) mustache 0.020000 0.020000 0.040000 ( 0.028828)
markaby 0.020000 0.020000 0.040000 ( 0.039350) slim 1.980000 0.050000 2.030000 ( 2.038820)
builder 0.020000 0.010000 0.030000 ( 0.039334) 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 ## ## Render (small template) - 10.000 runs ##
############################################################ ############################################################
user system total real user system total real
tenjin 0.100000 0.010000 0.110000 ( 0.100912) builder 1.890000 0.000000 1.890000 ( 1.893341)
string 0.070000 0.010000 0.080000 ( 0.073216) erb 0.110000 0.000000 0.110000 ( 0.109126)
erubis 0.080000 0.000000 0.080000 ( 0.076072) erubis 0.080000 0.000000 0.080000 ( 0.078112)
erb 0.120000 0.000000 0.120000 ( 0.113194) haml 0.210000 0.010000 0.220000 ( 0.212483)
haml 0.200000 0.000000 0.200000 ( 0.197601) handlebars 0.690000 0.040000 0.730000 ( 0.701104)
slim 0.210000 0.010000 0.220000 ( 0.208949) liquid 0.350000 0.000000 0.350000 ( 0.353939)
mustache 2.370000 0.060000 2.430000 ( 2.434160) markaby 2.450000 0.070000 2.520000 ( 2.518086)
liquid 0.360000 0.000000 0.360000 ( 0.362223) mustache 2.510000 0.060000 2.570000 ( 2.569790)
markaby 2.350000 0.030000 2.380000 ( 2.366150) slim 0.210000 0.010000 0.220000 ( 0.213641)
builder 1.880000 0.000000 1.880000 ( 1.879207) 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 ## ## Compilation (big template) - 1.000 runs ##
############################################################ ############################################################
user system total real user system total real
tenjin 0.010000 0.010000 0.020000 ( 0.015806) builder 0.020000 0.020000 0.040000 ( 0.043931)
string 0.020000 0.020000 0.040000 ( 0.043971) erb 0.280000 0.020000 0.300000 ( 0.302882)
erubis 0.110000 0.020000 0.130000 ( 0.136185) erubis 0.110000 0.020000 0.130000 ( 0.135634)
erb 0.290000 0.020000 0.310000 ( 0.306882) haml 1.140000 0.030000 1.170000 ( 1.171942)
haml 1.170000 0.020000 1.190000 ( 1.189052) handlebars 0.100000 0.030000 0.130000 ( 0.118258)
slim 2.350000 0.030000 2.380000 ( 2.394175) liquid 0.110000 0.020000 0.130000 ( 0.130391)
mustache 0.020000 0.010000 0.030000 ( 0.029711) markaby 0.020000 0.010000 0.030000 ( 0.042543)
liquid 0.110000 0.020000 0.130000 ( 0.129459) mustache 0.020000 0.020000 0.040000 ( 0.035402)
markaby 0.020000 0.020000 0.040000 ( 0.039971) slim 2.400000 0.040000 2.440000 ( 2.440354)
builder 0.030000 0.010000 0.040000 ( 0.040546) 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 ## ## Render (big template, 150KB data) - 50 runs ##
############################################################ ############################################################
user system total real user system total real
tenjin 0.160000 0.010000 0.170000 ( 0.170591) builder 9.270000 0.030000 9.300000 ( 9.289956)
string 0.180000 0.020000 0.200000 ( 0.195720) erb 0.310000 0.000000 0.310000 ( 0.313369)
erubis 0.210000 0.010000 0.220000 ( 0.217161) erubis 0.200000 0.010000 0.210000 ( 0.214869)
erb 0.300000 0.010000 0.310000 ( 0.316516) haml 0.490000 0.010000 0.500000 ( 0.495157)
haml 0.460000 0.010000 0.470000 ( 0.469774) handlebars 5.170000 0.060000 5.230000 ( 5.221436)
slim 0.680000 0.000000 0.680000 ( 0.685463) liquid 5.770000 0.050000 5.820000 ( 5.836171)
mustache 1.860000 0.000000 1.860000 ( 1.871303) markaby 6.280000 0.020000 6.300000 ( 6.303951)
liquid 5.240000 0.020000 5.260000 ( 5.269241) mustache 2.160000 0.000000 2.160000 ( 2.164364)
markaby 5.770000 0.010000 5.780000 ( 5.780620) slim 0.700000 0.010000 0.710000 ( 0.702391)
builder 9.320000 0.020000 9.340000 ( 9.343587) 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)
``` ```

View File

@ -9,33 +9,25 @@ $ ./fakedata.rb 10000 > data/big.yml
AGRR AGRR
Workbench::Benchmark.describe_engines( Workbench::Benchmark.describe_engines(
string: { builder: {
class: Tilt::StringTemplate, class: Tilt::BuilderTemplate,
extension: 'str' extension: 'builder'
},
erubis: {
class: Tilt::ErubisTemplate,
extension: 'erubis'
},
tenjin: {
class: Workbench::Wrappers::Tenjin,
extension: 'rbhtml'
}, },
erb: { erb: {
class: Tilt::ERBTemplate, class: Tilt::ERBTemplate,
extension: 'erb' extension: 'erb'
}, },
erubis: {
class: Tilt::ErubisTemplate,
extension: 'erubis'
},
haml: { haml: {
class: Tilt::HamlTemplate, class: Tilt::HamlTemplate,
extension: 'haml' extension: 'haml'
}, },
slim: { handlebars: {
class: Workbench::Wrappers::Slim, class: Workbench::Wrappers::Handlebars,
extension: 'slim' extension: 'handlebars'
},
mustache: {
class: Workbench::Wrappers::Mustache,
extension: 'mustache'
}, },
liquid: { liquid: {
class: Tilt::LiquidTemplate, class: Tilt::LiquidTemplate,
@ -45,21 +37,25 @@ Workbench::Benchmark.describe_engines(
class: Tilt::MarkabyTemplate, class: Tilt::MarkabyTemplate,
extension: 'mab' extension: 'mab'
}, },
builder: { mustache: {
class: Tilt::BuilderTemplate, class: Workbench::Wrappers::Mustache,
extension: 'builder' extension: 'mustache'
}, },
handlebars: { slim: {
class: Workbench::Wrappers::Handlebars, class: Workbench::Wrappers::Slim,
extension: 'handlebars' extension: 'slim'
},
string: {
class: Tilt::StringTemplate,
extension: 'str'
}, },
# parkaby: {
# class: Workbench::Wrappers::Parkaby,
# extension: 'mab'
# },
tagz: { tagz: {
class: Workbench::Wrappers::Tagz, class: Workbench::Wrappers::Tagz,
extension: 'tagz' extension: 'rb'
},
tenjin: {
class: Workbench::Wrappers::Tenjin,
extension: 'rbhtml'
}, },
) )

View File

@ -8,13 +8,13 @@ require 'ostruct'
require 'erubis' require 'erubis'
require 'haml' require 'haml'
require 'slim' require 'handlebars'
require 'liquid' require 'liquid'
require 'mustache' require 'mustache'
require 'tenjin' require 'slim'
require 'handlebars'
# require 'parkaby'
require 'tagz' require 'tagz'
require 'tenjin'
require 'tilt/erb' require 'tilt/erb'
require 'tilt/erubis' require 'tilt/erubis'
require 'tilt/haml' require 'tilt/haml'
@ -22,9 +22,8 @@ require 'tilt/liquid'
require 'workbench/benchmark' require 'workbench/benchmark'
require 'workbench/wrappers/base' require 'workbench/wrappers/base'
require 'workbench/wrappers/handlebars'
require 'workbench/wrappers/mustache' require 'workbench/wrappers/mustache'
require 'workbench/wrappers/slim' require 'workbench/wrappers/slim'
require 'workbench/wrappers/tenjin'
require 'workbench/wrappers/handlebars'
require 'workbench/wrappers/parkaby'
require 'workbench/wrappers/tagz' require 'workbench/wrappers/tagz'
require 'workbench/wrappers/tenjin'

View File

@ -2,30 +2,32 @@ module Workbench
module Wrappers module Wrappers
class Tagz < Base class Tagz < Base
def initialize path def initialize path
@tpl = File.read(path) require path
@context = Context.new
if path.end_with?('small.rb')
@tpl = TagzTemplates::Small.new
else
@tpl = TagzTemplates::Big.new
end
end end
def render context, args = {} def render context, args = {}
@context.with_args(args).instance_eval(tpl) @tpl.with_args(args).render
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
end end
end end
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

32
templates/tagz/big.rb Normal file
View File

@ -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

View File

@ -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']
}
}
}
}

25
templates/tagz/small.rb Normal file
View File

@ -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

View File

@ -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
}
}
}