Pistos (owner)

Revisions

gist: 122070 Download_button fork
public
Description:
Etanni vs. ERb
Public Clone URL: git://gist.github.com/122070.git
Embed All Files: show embed
bench.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
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