Fix Slim, add Tenjin - new winner!
This commit is contained in:
parent
e24c040f01
commit
4a8e148fc6
1
Gemfile
1
Gemfile
|
@ -9,3 +9,4 @@ gem 'slim'
|
|||
gem 'liquid'
|
||||
gem 'mustache'
|
||||
gem 'markaby'
|
||||
gem 'tenjin'
|
||||
|
|
|
@ -16,6 +16,7 @@ GEM
|
|||
temple (~> 0.6.6)
|
||||
tilt (>= 1.3.3, < 2.1)
|
||||
temple (0.6.7)
|
||||
tenjin (0.7.1)
|
||||
tilt (2.0.0)
|
||||
|
||||
PLATFORMS
|
||||
|
@ -29,4 +30,5 @@ DEPENDENCIES
|
|||
markaby
|
||||
mustache
|
||||
slim
|
||||
tenjin
|
||||
tilt
|
||||
|
|
78
README.md
78
README.md
|
@ -37,55 +37,59 @@ bundle install
|
|||
## Compilation (small template) - 1.000 runs ##
|
||||
############################################################
|
||||
user system total real
|
||||
string 0.030000 0.020000 0.050000 ( 0.044899)
|
||||
erubis 0.060000 0.030000 0.090000 ( 0.086133)
|
||||
erb 0.260000 0.020000 0.280000 ( 0.278659)
|
||||
haml 0.840000 0.030000 0.870000 ( 0.869582)
|
||||
slim 1.950000 0.030000 1.980000 ( 1.993040)
|
||||
mustache 0.020000 0.020000 0.040000 ( 0.035736)
|
||||
liquid 0.060000 0.020000 0.080000 ( 0.076226)
|
||||
markaby 0.030000 0.010000 0.040000 ( 0.041241)
|
||||
builder 0.020000 0.020000 0.040000 ( 0.041957)
|
||||
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)
|
||||
|
||||
############################################################
|
||||
## Render (small template) - 10.000 runs ##
|
||||
############################################################
|
||||
user system total real
|
||||
string 0.080000 0.010000 0.090000 ( 0.086388)
|
||||
erubis 0.130000 0.010000 0.140000 ( 0.148000)
|
||||
erb 0.120000 0.010000 0.130000 ( 0.117680)
|
||||
haml 0.220000 0.000000 0.220000 ( 0.223524)
|
||||
slim 0.270000 0.000000 0.270000 ( 0.268160)
|
||||
mustache 2.380000 0.060000 2.440000 ( 2.448563)
|
||||
liquid 0.380000 0.000000 0.380000 ( 0.392713)
|
||||
markaby 2.410000 0.040000 2.450000 ( 2.441700)
|
||||
builder 1.840000 0.010000 1.850000 ( 1.848402)
|
||||
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)
|
||||
|
||||
############################################################
|
||||
## Compilation (big template) - 1.000 runs ##
|
||||
############################################################
|
||||
user system total real
|
||||
string 0.030000 0.010000 0.040000 ( 0.044474)
|
||||
erubis 0.160000 0.030000 0.190000 ( 0.183202)
|
||||
erb 0.300000 0.020000 0.320000 ( 0.321878)
|
||||
haml 1.160000 0.030000 1.190000 ( 1.193374)
|
||||
slim 2.380000 0.040000 2.420000 ( 2.423795)
|
||||
mustache 0.020000 0.020000 0.040000 ( 0.029639)
|
||||
liquid 0.110000 0.020000 0.130000 ( 0.132466)
|
||||
markaby 0.020000 0.010000 0.030000 ( 0.039952)
|
||||
builder 0.030000 0.020000 0.050000 ( 0.043474)
|
||||
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)
|
||||
|
||||
############################################################
|
||||
## Render (big template, 150KB data) - 50 runs ##
|
||||
## Render (big template, 150KB data) - 50 runs ##
|
||||
############################################################
|
||||
user system total real
|
||||
string 0.200000 0.030000 0.230000 ( 0.220962)
|
||||
erubis 0.210000 0.010000 0.220000 ( 0.225647)
|
||||
erb 0.310000 0.010000 0.320000 ( 0.321146)
|
||||
haml 0.460000 0.010000 0.470000 ( 0.474801)
|
||||
slim 0.710000 0.010000 0.720000 ( 0.717359)
|
||||
mustache 1.900000 0.010000 1.910000 ( 1.909129)
|
||||
liquid 5.230000 0.030000 5.260000 ( 5.265334)
|
||||
markaby 5.760000 0.010000 5.770000 ( 5.766475)
|
||||
builder 9.150000 0.020000 9.170000 ( 9.168262)
|
||||
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)
|
||||
```
|
||||
|
|
27
benchmark.rb
27
benchmark.rb
|
@ -9,6 +9,10 @@ $ ./fakedata.rb 10000 > data/big.yml
|
|||
AGRR
|
||||
|
||||
Workbench::Benchmark.describe_engines(
|
||||
tenjin: {
|
||||
class: Workbench::Wrappers::Tenjin,
|
||||
extension: 'rbhtml'
|
||||
},
|
||||
string: {
|
||||
class: Tilt::StringTemplate,
|
||||
extension: 'str'
|
||||
|
@ -26,11 +30,11 @@ Workbench::Benchmark.describe_engines(
|
|||
extension: 'haml'
|
||||
},
|
||||
slim: {
|
||||
class: Slim::Template,
|
||||
class: Workbench::Wrappers::Slim,
|
||||
extension: 'slim'
|
||||
},
|
||||
mustache: {
|
||||
class: Wrappers::Mustache,
|
||||
class: Workbench::Wrappers::Mustache,
|
||||
extension: 'mustache'
|
||||
},
|
||||
liquid: {
|
||||
|
@ -57,12 +61,7 @@ Workbench::Benchmark.new(loops: 1000, title: 'Compilation (small template) - 1.0
|
|||
end
|
||||
|
||||
Workbench::Benchmark.new(loops: 10000, title: 'Render (small template) - 10.000 runs') do |name, attrs|
|
||||
case name
|
||||
when :slim
|
||||
templates[name].render(OpenStruct.new(small_data))
|
||||
else
|
||||
templates[name].render(Object, small_data)
|
||||
end
|
||||
templates[name].render(Object, small_data)
|
||||
end
|
||||
|
||||
Workbench::Benchmark.new(loops: 1000, title: 'Compilation (big template) - 1.000 runs') do |name, attrs|
|
||||
|
@ -71,10 +70,10 @@ Workbench::Benchmark.new(loops: 1000, title: 'Compilation (big template) - 1.000
|
|||
end
|
||||
|
||||
Workbench::Benchmark.new(loops: 50, title: 'Render (big template, 150KB data) - 50 runs') do |name, attrs|
|
||||
case name
|
||||
when :slim
|
||||
templates[name].render(OpenStruct.new(customers: big_data))
|
||||
else
|
||||
templates[name].render(Object, {customers: big_data})
|
||||
end
|
||||
templates[name].render(Object, {customers: big_data})
|
||||
end
|
||||
|
||||
# Cleanup Tenjin cache files
|
||||
path = File.expand_path('../templates/tenjin/%s.rbhtml.cache', __FILE__)
|
||||
File.delete(path % 'small') if File.exist?(path % 'small')
|
||||
File.delete(path % 'big') if File.exist?(path % 'big')
|
||||
|
|
|
@ -11,6 +11,7 @@ require 'haml'
|
|||
require 'slim'
|
||||
require 'liquid'
|
||||
require 'mustache'
|
||||
require 'tenjin'
|
||||
require 'tilt/erb'
|
||||
require 'tilt/erubis'
|
||||
require 'tilt/haml'
|
||||
|
@ -19,3 +20,5 @@ require 'tilt/liquid'
|
|||
require 'workbench/benchmark'
|
||||
require 'workbench/wrappers/base'
|
||||
require 'workbench/wrappers/mustache'
|
||||
require 'workbench/wrappers/slim'
|
||||
require 'workbench/wrappers/tenjin'
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
module Wrappers
|
||||
class Base
|
||||
attr_reader :tpl
|
||||
module Workbench
|
||||
module Wrappers
|
||||
class Base
|
||||
attr_reader :tpl
|
||||
|
||||
def initialize path
|
||||
@tpl = File.read(path)
|
||||
def initialize path
|
||||
@tpl = File.read(path)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
module Wrappers
|
||||
class Mustache < Base
|
||||
def render context, args = {}
|
||||
::Mustache.render(tpl, args)
|
||||
module Workbench
|
||||
module Wrappers
|
||||
class Mustache < Base
|
||||
def render context, args = {}
|
||||
::Mustache.render(tpl, args)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
module Workbench
|
||||
module Wrappers
|
||||
class Slim < Base
|
||||
def initialize path
|
||||
@engine = ::Slim::Template.new{ File.read(path) }
|
||||
end
|
||||
|
||||
def render context, args = {}
|
||||
@engine.render(OpenStruct.new(args))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,14 @@
|
|||
module Workbench
|
||||
module Wrappers
|
||||
class Tenjin < Base
|
||||
def initialize path
|
||||
@path = path
|
||||
@engine = ::Tenjin::Engine.new
|
||||
end
|
||||
|
||||
def render context, args = {}
|
||||
@engine.render(@path, args)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,25 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Customers List</title>
|
||||
</head>
|
||||
<body>
|
||||
<?rb @customers.each do |customer| ?>
|
||||
<dl>
|
||||
<dt>Name:</dt>
|
||||
<dd>#{customer['name']}</dd>
|
||||
<dt>Age:</dt>
|
||||
<dd>#{customer['age']}</dd>
|
||||
<dt>Address:</dt>
|
||||
<dd>
|
||||
#{customer['zip']}
|
||||
#{customer['country']}
|
||||
#{customer['city']}
|
||||
#{customer['address']}
|
||||
</dd>
|
||||
<dt>Employer:</dt>
|
||||
<dd>#{customer['employer']}</dd>
|
||||
</dl>
|
||||
<?rb end ?>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,18 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>#{@window_title}</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Hello, #{@username}!</h1>
|
||||
<p>
|
||||
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.
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue