ETANNI_TEMPLATES = {}
ETANNI_TEMPLATES[:simple] = <<'T'
<h1>Nothing here</h1>
T
ETANNI_TEMPLATES[:small] = <<'T'
<?r 100.times do |n| ?>
#{n}
<?r end ?>
T
ETANNI_TEMPLATES[:medium] = <<'T'
<?r nil ?>
<?r nil ?>
<?r nil ?>
<?r nil ?>
<?r nil ?>
<?r nil ?>
<?r nil ?>
<?r nil ?>
<?r nil ?>
<?r nil ?>
T
ERB_TEMPLATES = {}
ERB_TEMPLATES[:simple] = <<'T'
<h1>Nothing here</h1>
T
ERB_TEMPLATES[:small] = <<'T'
<% 100.times do |n| %>
<%= n %>
<% end %>
T
ERB_TEMPLATES[:medium] = <<'T'
<% nil %>
<% nil %>
<% nil %>
<% nil %>
<% nil %>
<% nil %>
<% nil %>
<% nil %>
<% nil %>
<% nil %>
T
# ----------------------------------------------------------
require 'better-benchmark'
require 'innate'
class Bench
Innate.node '/'
def erb_template(name)
ERB_TEMPLATES[name.to_sym]
end
def etanni_template(name)
ETANNI_TEMPLATES[name.to_sym]
end
end
Innate::View.options.cache = false
# ------------------------------------------
ERB_TEMPLATES.keys.each do |key|
puts "\n\nERB vs. Etanni: #{key}:"
result = Benchmark.compare_realtime(
:iterations => 10,
:inner_iterations => 2000,
:verbose => true
) { |iteration|
action = Innate::Action.create(
:node => Bench,
:wish => 'html',
:engine => Innate::View::ERB,
:method => 'erb_template',
:params => [key.to_s],
:path => '/bench'
)
action.render
}.with { |iteration|
action = Innate::Action.create(
:node => Bench,
:wish => 'html',
:engine => Innate::View::Etanni,
:method => 'etanni_template',
:params => [key.to_s],
:path => '/bench'
)
action.render
}
Benchmark.report_on result
end
=begin
Example output:
ERB vs. Etanni: simple:
..........
Set 1 mean: 0.719 s
Set 1 std dev: 0.085
Set 2 mean: 0.443 s
Set 2 std dev: 0.008
p.value: 1.0825088224469e-05
W: 100.0
The difference (-38.3%) IS statistically significant.
ERB vs. Etanni: small:
..........
Set 1 mean: 1.486 s
Set 1 std dev: 0.017
Set 2 mean: 1.179 s
Set 2 std dev: 0.056
p.value: 1.0825088224469e-05
W: 100.0
The difference (-20.7%) IS statistically significant.
ERB vs. Etanni: medium:
..........
Set 1 mean: 1.613 s
Set 1 std dev: 0.071
Set 2 mean: 0.905 s
Set 2 std dev: 0.098
p.value: 1.0825088224469e-05
W: 100.0
The difference (-43.9%) IS statistically significant.
=end