1
0

Fix Slim, add Tenjin - new winner!

This commit is contained in:
Gregory Eremin 2013-12-15 01:32:31 +07:00
parent e24c040f01
commit 4a8e148fc6
No known key found for this signature in database
GPG Key ID: 5EFA427EEC26E86C
11 changed files with 143 additions and 60 deletions

View File

@ -9,3 +9,4 @@ gem 'slim'
gem 'liquid' gem 'liquid'
gem 'mustache' gem 'mustache'
gem 'markaby' gem 'markaby'
gem 'tenjin'

View File

@ -16,6 +16,7 @@ GEM
temple (~> 0.6.6) temple (~> 0.6.6)
tilt (>= 1.3.3, < 2.1) tilt (>= 1.3.3, < 2.1)
temple (0.6.7) temple (0.6.7)
tenjin (0.7.1)
tilt (2.0.0) tilt (2.0.0)
PLATFORMS PLATFORMS
@ -29,4 +30,5 @@ DEPENDENCIES
markaby markaby
mustache mustache
slim slim
tenjin
tilt tilt

View File

@ -37,55 +37,59 @@ bundle install
## Compilation (small template) - 1.000 runs ## ## Compilation (small template) - 1.000 runs ##
############################################################ ############################################################
user system total real user system total real
string 0.030000 0.020000 0.050000 ( 0.044899) tenjin 0.010000 0.010000 0.020000 ( 0.015441)
erubis 0.060000 0.030000 0.090000 ( 0.086133) string 0.040000 0.020000 0.060000 ( 0.051998)
erb 0.260000 0.020000 0.280000 ( 0.278659) erubis 0.050000 0.010000 0.060000 ( 0.076408)
haml 0.840000 0.030000 0.870000 ( 0.869582) erb 0.220000 0.020000 0.240000 ( 0.247821)
slim 1.950000 0.030000 1.980000 ( 1.993040) haml 0.850000 0.040000 0.890000 ( 0.888733)
mustache 0.020000 0.020000 0.040000 ( 0.035736) slim 1.910000 0.030000 1.940000 ( 1.945333)
liquid 0.060000 0.020000 0.080000 ( 0.076226) mustache 0.020000 0.010000 0.030000 ( 0.028953)
markaby 0.030000 0.010000 0.040000 ( 0.041241) liquid 0.060000 0.020000 0.080000 ( 0.072093)
builder 0.020000 0.020000 0.040000 ( 0.041957) markaby 0.020000 0.020000 0.040000 ( 0.039350)
builder 0.020000 0.010000 0.030000 ( 0.039334)
############################################################ ############################################################
## Render (small template) - 10.000 runs ## ## Render (small template) - 10.000 runs ##
############################################################ ############################################################
user system total real user system total real
string 0.080000 0.010000 0.090000 ( 0.086388) tenjin 0.100000 0.010000 0.110000 ( 0.100912)
erubis 0.130000 0.010000 0.140000 ( 0.148000) string 0.070000 0.010000 0.080000 ( 0.073216)
erb 0.120000 0.010000 0.130000 ( 0.117680) erubis 0.080000 0.000000 0.080000 ( 0.076072)
haml 0.220000 0.000000 0.220000 ( 0.223524) erb 0.120000 0.000000 0.120000 ( 0.113194)
slim 0.270000 0.000000 0.270000 ( 0.268160) haml 0.200000 0.000000 0.200000 ( 0.197601)
mustache 2.380000 0.060000 2.440000 ( 2.448563) slim 0.210000 0.010000 0.220000 ( 0.208949)
liquid 0.380000 0.000000 0.380000 ( 0.392713) mustache 2.370000 0.060000 2.430000 ( 2.434160)
markaby 2.410000 0.040000 2.450000 ( 2.441700) liquid 0.360000 0.000000 0.360000 ( 0.362223)
builder 1.840000 0.010000 1.850000 ( 1.848402) markaby 2.350000 0.030000 2.380000 ( 2.366150)
builder 1.880000 0.000000 1.880000 ( 1.879207)
############################################################ ############################################################
## Compilation (big template) - 1.000 runs ## ## Compilation (big template) - 1.000 runs ##
############################################################ ############################################################
user system total real user system total real
string 0.030000 0.010000 0.040000 ( 0.044474) tenjin 0.010000 0.010000 0.020000 ( 0.015806)
erubis 0.160000 0.030000 0.190000 ( 0.183202) string 0.020000 0.020000 0.040000 ( 0.043971)
erb 0.300000 0.020000 0.320000 ( 0.321878) erubis 0.110000 0.020000 0.130000 ( 0.136185)
haml 1.160000 0.030000 1.190000 ( 1.193374) erb 0.290000 0.020000 0.310000 ( 0.306882)
slim 2.380000 0.040000 2.420000 ( 2.423795) haml 1.170000 0.020000 1.190000 ( 1.189052)
mustache 0.020000 0.020000 0.040000 ( 0.029639) slim 2.350000 0.030000 2.380000 ( 2.394175)
liquid 0.110000 0.020000 0.130000 ( 0.132466) mustache 0.020000 0.010000 0.030000 ( 0.029711)
markaby 0.020000 0.010000 0.030000 ( 0.039952) liquid 0.110000 0.020000 0.130000 ( 0.129459)
builder 0.030000 0.020000 0.050000 ( 0.043474) 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 user system total real
string 0.200000 0.030000 0.230000 ( 0.220962) tenjin 0.160000 0.010000 0.170000 ( 0.170591)
erubis 0.210000 0.010000 0.220000 ( 0.225647) string 0.180000 0.020000 0.200000 ( 0.195720)
erb 0.310000 0.010000 0.320000 ( 0.321146) erubis 0.210000 0.010000 0.220000 ( 0.217161)
haml 0.460000 0.010000 0.470000 ( 0.474801) erb 0.300000 0.010000 0.310000 ( 0.316516)
slim 0.710000 0.010000 0.720000 ( 0.717359) haml 0.460000 0.010000 0.470000 ( 0.469774)
mustache 1.900000 0.010000 1.910000 ( 1.909129) slim 0.680000 0.000000 0.680000 ( 0.685463)
liquid 5.230000 0.030000 5.260000 ( 5.265334) mustache 1.860000 0.000000 1.860000 ( 1.871303)
markaby 5.760000 0.010000 5.770000 ( 5.766475) liquid 5.240000 0.020000 5.260000 ( 5.269241)
builder 9.150000 0.020000 9.170000 ( 9.168262) markaby 5.770000 0.010000 5.780000 ( 5.780620)
builder 9.320000 0.020000 9.340000 ( 9.343587)
``` ```

View File

@ -9,6 +9,10 @@ $ ./fakedata.rb 10000 > data/big.yml
AGRR AGRR
Workbench::Benchmark.describe_engines( Workbench::Benchmark.describe_engines(
tenjin: {
class: Workbench::Wrappers::Tenjin,
extension: 'rbhtml'
},
string: { string: {
class: Tilt::StringTemplate, class: Tilt::StringTemplate,
extension: 'str' extension: 'str'
@ -26,11 +30,11 @@ Workbench::Benchmark.describe_engines(
extension: 'haml' extension: 'haml'
}, },
slim: { slim: {
class: Slim::Template, class: Workbench::Wrappers::Slim,
extension: 'slim' extension: 'slim'
}, },
mustache: { mustache: {
class: Wrappers::Mustache, class: Workbench::Wrappers::Mustache,
extension: 'mustache' extension: 'mustache'
}, },
liquid: { liquid: {
@ -57,12 +61,7 @@ Workbench::Benchmark.new(loops: 1000, title: 'Compilation (small template) - 1.0
end end
Workbench::Benchmark.new(loops: 10000, title: 'Render (small template) - 10.000 runs') do |name, attrs| 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) templates[name].render(Object, small_data)
end
end end
Workbench::Benchmark.new(loops: 1000, title: 'Compilation (big template) - 1.000 runs') do |name, attrs| 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 end
Workbench::Benchmark.new(loops: 50, title: 'Render (big template, 150KB data) - 50 runs') do |name, attrs| 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}) templates[name].render(Object, {customers: big_data})
end
end 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')

View File

@ -11,6 +11,7 @@ require 'haml'
require 'slim' require 'slim'
require 'liquid' require 'liquid'
require 'mustache' require 'mustache'
require 'tenjin'
require 'tilt/erb' require 'tilt/erb'
require 'tilt/erubis' require 'tilt/erubis'
require 'tilt/haml' require 'tilt/haml'
@ -19,3 +20,5 @@ require 'tilt/liquid'
require 'workbench/benchmark' require 'workbench/benchmark'
require 'workbench/wrappers/base' require 'workbench/wrappers/base'
require 'workbench/wrappers/mustache' require 'workbench/wrappers/mustache'
require 'workbench/wrappers/slim'
require 'workbench/wrappers/tenjin'

View File

@ -1,4 +1,5 @@
module Wrappers module Workbench
module Wrappers
class Base class Base
attr_reader :tpl attr_reader :tpl
@ -6,4 +7,5 @@ module Wrappers
@tpl = File.read(path) @tpl = File.read(path)
end end
end end
end
end end

View File

@ -1,7 +1,9 @@
module Wrappers module Workbench
module Wrappers
class Mustache < Base class Mustache < Base
def render context, args = {} def render context, args = {}
::Mustache.render(tpl, args) ::Mustache.render(tpl, args)
end end
end end
end
end end

View File

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

View File

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

View File

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

View File

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