Add Mustache
This commit is contained in:
parent
babdc13c79
commit
0425c8bac9
|
@ -8,6 +8,7 @@ GEM
|
|||
tilt
|
||||
i18n (0.6.9)
|
||||
liquid (2.6.0)
|
||||
mustache (0.99.5)
|
||||
slim (2.0.2)
|
||||
temple (~> 0.6.6)
|
||||
tilt (>= 1.3.3, < 2.1)
|
||||
|
@ -22,5 +23,6 @@ DEPENDENCIES
|
|||
faker
|
||||
haml
|
||||
liquid
|
||||
mustache
|
||||
slim
|
||||
tilt
|
||||
|
|
67
README.md
67
README.md
|
@ -1,4 +1,15 @@
|
|||
# Template Engine Comparison
|
||||
# Template Engine Performance Comparison
|
||||
#### Ruby implementations.
|
||||
|
||||
## Competitors
|
||||
- ERB
|
||||
- Erubis
|
||||
- Haml
|
||||
- Liquid
|
||||
- Mustache
|
||||
- Slim
|
||||
... and our special guest ...
|
||||
- String interpolation
|
||||
|
||||
## Running
|
||||
```bash
|
||||
|
@ -15,50 +26,54 @@ bundle install
|
|||
```
|
||||
|
||||
## Current Results
|
||||
** Intel Core i7 2.6 GHz **
|
||||
**Intel Core i7 2.6 GHz**
|
||||
|
||||
```
|
||||
############################################################
|
||||
## Compilation (small) (1000 runs) ##
|
||||
############################################################
|
||||
user system total real
|
||||
string 0.040000 0.010000 0.050000 ( 0.054310)
|
||||
erb 0.240000 0.030000 0.270000 ( 0.260111)
|
||||
erubis 0.060000 0.010000 0.070000 ( 0.078122)
|
||||
haml 0.850000 0.030000 0.880000 ( 0.873031)
|
||||
slim 1.930000 0.030000 1.960000 ( 1.960224)
|
||||
liquid 0.050000 0.020000 0.070000 ( 0.073867)
|
||||
string 0.040000 0.020000 0.060000 ( 0.053855)
|
||||
erubis 0.060000 0.010000 0.070000 ( 0.075751)
|
||||
erb 0.240000 0.030000 0.270000 ( 0.262077)
|
||||
haml 0.840000 0.020000 0.860000 ( 0.865688)
|
||||
slim 1.930000 0.040000 1.970000 ( 1.968993)
|
||||
mustache 0.020000 0.010000 0.030000 ( 0.030289)
|
||||
liquid 0.080000 0.020000 0.100000 ( 0.104174)
|
||||
|
||||
############################################################
|
||||
## Render (small) (1000 runs) ##
|
||||
############################################################
|
||||
user system total real
|
||||
string 0.010000 0.000000 0.010000 ( 0.013322)
|
||||
erb 0.010000 0.000000 0.010000 ( 0.012137)
|
||||
erubis 0.010000 0.000000 0.010000 ( 0.008176)
|
||||
haml 0.020000 0.000000 0.020000 ( 0.021298)
|
||||
slim 0.020000 0.000000 0.020000 ( 0.022210)
|
||||
liquid 0.030000 0.000000 0.030000 ( 0.036494)
|
||||
string 0.010000 0.000000 0.010000 ( 0.007824)
|
||||
erubis 0.010000 0.000000 0.010000 ( 0.008019)
|
||||
erb 0.010000 0.000000 0.010000 ( 0.010448)
|
||||
haml 0.020000 0.000000 0.020000 ( 0.019507)
|
||||
slim 0.020000 0.000000 0.020000 ( 0.019644)
|
||||
mustache 0.230000 0.000000 0.230000 ( 0.232938)
|
||||
liquid 0.040000 0.000000 0.040000 ( 0.044189)
|
||||
|
||||
############################################################
|
||||
## Compilation (big) (1000 runs) ##
|
||||
############################################################
|
||||
user system total real
|
||||
string 0.060000 0.020000 0.080000 ( 0.071830)
|
||||
erb 0.300000 0.020000 0.320000 ( 0.324309)
|
||||
erubis 0.120000 0.020000 0.140000 ( 0.140036)
|
||||
haml 1.180000 0.030000 1.210000 ( 1.203810)
|
||||
slim 2.410000 0.030000 2.440000 ( 2.441857)
|
||||
liquid 0.120000 0.010000 0.130000 ( 0.134647)
|
||||
string 0.030000 0.020000 0.050000 ( 0.044706)
|
||||
erubis 0.140000 0.020000 0.160000 ( 0.161244)
|
||||
erb 0.320000 0.030000 0.350000 ( 0.341144)
|
||||
haml 1.180000 0.020000 1.200000 ( 1.205595)
|
||||
slim 2.410000 0.040000 2.450000 ( 2.449355)
|
||||
mustache 0.020000 0.010000 0.030000 ( 0.028152)
|
||||
liquid 0.110000 0.020000 0.130000 ( 0.133382)
|
||||
|
||||
############################################################
|
||||
## Render (big) (100 runs) ##
|
||||
############################################################
|
||||
user system total real
|
||||
string 0.390000 0.030000 0.420000 ( 0.414645)
|
||||
erb 0.650000 0.020000 0.670000 ( 0.666250)
|
||||
erubis 0.430000 0.010000 0.440000 ( 0.448594)
|
||||
haml 0.970000 0.020000 0.990000 ( 0.981991)
|
||||
slim 1.400000 0.010000 1.410000 ( 1.408893)
|
||||
liquid 10.480000 0.050000 10.530000 ( 10.535895)
|
||||
string 0.390000 0.020000 0.410000 ( 0.408272)
|
||||
erubis 0.440000 0.020000 0.460000 ( 0.457214)
|
||||
erb 0.640000 0.020000 0.660000 ( 0.656181)
|
||||
haml 0.940000 0.020000 0.960000 ( 0.965373)
|
||||
slim 1.390000 0.000000 1.390000 ( 1.395409)
|
||||
mustache 3.770000 0.010000 3.780000 ( 3.778392)
|
||||
liquid 10.460000 0.050000 10.510000 ( 10.507224)
|
||||
```
|
||||
|
|
32
benchmark.rb
32
benchmark.rb
|
@ -10,6 +10,7 @@ require 'erubis'
|
|||
require 'haml'
|
||||
require 'slim'
|
||||
require 'liquid'
|
||||
require 'mustache'
|
||||
require 'tilt/erb'
|
||||
require 'tilt/erubis'
|
||||
require 'tilt/haml'
|
||||
|
@ -51,19 +52,35 @@ def benchmark params
|
|||
end
|
||||
end
|
||||
|
||||
module Wrappers
|
||||
class Base
|
||||
attr_reader :tpl
|
||||
|
||||
def initialize path
|
||||
@tpl = File.read(path)
|
||||
end
|
||||
end
|
||||
|
||||
class Mustache < Base
|
||||
def render context, args = {}
|
||||
::Mustache.render(tpl, args)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
ENGINES = {
|
||||
string: {
|
||||
class: Tilt::StringTemplate,
|
||||
extension: 'str'
|
||||
},
|
||||
erb: {
|
||||
class: Tilt::ERBTemplate,
|
||||
extension: 'erb'
|
||||
},
|
||||
erubis: {
|
||||
class: Tilt::ErubisTemplate,
|
||||
extension: 'erubis'
|
||||
},
|
||||
erb: {
|
||||
class: Tilt::ERBTemplate,
|
||||
extension: 'erb'
|
||||
},
|
||||
haml: {
|
||||
class: Tilt::HamlTemplate,
|
||||
extension: 'haml'
|
||||
|
@ -72,13 +89,16 @@ ENGINES = {
|
|||
class: Slim::Template,
|
||||
extension: 'slim'
|
||||
},
|
||||
mustache: {
|
||||
class: Wrappers::Mustache,
|
||||
extension: 'mustache'
|
||||
},
|
||||
liquid: {
|
||||
class: Tilt::LiquidTemplate,
|
||||
extension: 'liquid'
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
banner 'Compilation (small) (%d runs)' % COMPILE_LOOPS
|
||||
benchmark(loops: COMPILE_LOOPS) do |name, attrs|
|
||||
template_path = File.expand_path('../templates/%s/small.%s', __FILE__) % [name, attrs[:extension]]
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Customers List</title>
|
||||
</head>
|
||||
<body>
|
||||
{{# customers }}
|
||||
<dl>
|
||||
<dt>Name:</dt>
|
||||
<dd>{{ name }}</dd>
|
||||
<dt>Age:</dt>
|
||||
<dd>{{ age }}</dd>
|
||||
<dt>Address:</dt>
|
||||
<dd>
|
||||
{{ zip }}
|
||||
{{ country }}
|
||||
{{ city }}
|
||||
{{ address }}
|
||||
</dd>
|
||||
<dt>Employer:</dt>
|
||||
<dd>{{ employer }}</dd>
|
||||
</dl>
|
||||
{{/ customers }}
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,18 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>{{ 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