erubis-bmp 2.7.0.bmp
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGES.txt +828 -0
- data/MIT-LICENSE +20 -0
- data/README.txt +10 -0
- data/benchmark/bench.rb +313 -0
- data/benchmark/bench_context.yaml +141 -0
- data/benchmark/mybench2.rb +266 -0
- data/benchmark/pibench.rb +163 -0
- data/benchmark/templates/_footer.html +4 -0
- data/benchmark/templates/_header.html +52 -0
- data/benchmark/templates/bench_erb.rhtml +29 -0
- data/benchmark/templates/bench_erubis.rhtml +29 -0
- data/benchmark/templates/bench_eruby.rhtml +29 -0
- data/bin/erubis +10 -0
- data/contrib/erubis-run.rb +132 -0
- data/doc/Rookbook.yaml +106 -0
- data/doc/docstyle.css +209 -0
- data/doc/users-guide.html +3551 -0
- data/doc/users-guide.txt +3631 -0
- data/examples/basic/Makefile +58 -0
- data/examples/basic/example.ec +42 -0
- data/examples/basic/example.ecpp +33 -0
- data/examples/basic/example.ejava +45 -0
- data/examples/basic/example.ejs +16 -0
- data/examples/basic/example.eperl +16 -0
- data/examples/basic/example.ephp +17 -0
- data/examples/basic/example.eruby +15 -0
- data/examples/basic/example.escheme +26 -0
- data/examples/pi-xhtml/ExamplePage.xhtml +80 -0
- data/examples/pi-xhtml/Makefile +17 -0
- data/examples/pi-xhtml/my/User.java +19 -0
- data/examples/pi-xhtml/my/Util.java +54 -0
- data/examples/pi/Makefile +54 -0
- data/examples/pi/example.ec +42 -0
- data/examples/pi/example.ejava +45 -0
- data/examples/pi/example.ejs +16 -0
- data/examples/pi/example.eperl +16 -0
- data/examples/pi/example.ephp +17 -0
- data/examples/pi/example.eruby +15 -0
- data/examples/pi/example.escheme +26 -0
- data/lib/erubis.rb +73 -0
- data/lib/erubis/context.rb +83 -0
- data/lib/erubis/converter.rb +357 -0
- data/lib/erubis/engine.rb +120 -0
- data/lib/erubis/engine/ec.rb +117 -0
- data/lib/erubis/engine/ecpp.rb +113 -0
- data/lib/erubis/engine/ejava.rb +110 -0
- data/lib/erubis/engine/ejavascript.rb +119 -0
- data/lib/erubis/engine/enhanced.rb +126 -0
- data/lib/erubis/engine/eperl.rb +95 -0
- data/lib/erubis/engine/ephp.rb +99 -0
- data/lib/erubis/engine/eruby.rb +125 -0
- data/lib/erubis/engine/escheme.rb +114 -0
- data/lib/erubis/engine/optimized.rb +127 -0
- data/lib/erubis/enhancer.rb +723 -0
- data/lib/erubis/error.rb +23 -0
- data/lib/erubis/evaluator.rb +88 -0
- data/lib/erubis/generator.rb +85 -0
- data/lib/erubis/helper.rb +47 -0
- data/lib/erubis/helpers/rails_form_helper.rb +197 -0
- data/lib/erubis/helpers/rails_helper.rb +353 -0
- data/lib/erubis/local-setting.rb +9 -0
- data/lib/erubis/main.rb +516 -0
- data/lib/erubis/preprocessing.rb +58 -0
- data/lib/erubis/tiny.rb +144 -0
- data/lib/erubis/util.rb +22 -0
- data/setup.rb +1331 -0
- data/test/Rookbook.yaml +42 -0
- data/test/assert-text-equal.rb +44 -0
- data/test/test-engines.rb +425 -0
- data/test/test-enhancers.rb +646 -0
- data/test/test-erubis.rb +887 -0
- data/test/test-index-cgi.rb +191 -0
- data/test/test-main.rb +752 -0
- data/test/test-users-guide.rb +73 -0
- data/test/test.rb +45 -0
- data/test/testutil.rb +111 -0
- metadata +121 -0
@@ -0,0 +1,266 @@
|
|
1
|
+
|
2
|
+
$: << '../lib'
|
3
|
+
%w[erb erubis yaml benchmark].each {|x| require x }
|
4
|
+
|
5
|
+
ydoc = YAML.load_file('bench_context.yaml')
|
6
|
+
list = ydoc['list']
|
7
|
+
@list = list
|
8
|
+
|
9
|
+
filename = 'bench_erb.rhtml'
|
10
|
+
input = File.read(filename)
|
11
|
+
input2 = input.gsub(/\blist\b/, '@list')
|
12
|
+
|
13
|
+
erb = ERB.new(input)
|
14
|
+
erb.result(binding())
|
15
|
+
|
16
|
+
N = ($N || 10000).to_i
|
17
|
+
output = nil
|
18
|
+
Benchmark.bm(33) do |x|
|
19
|
+
|
20
|
+
## warm up (why need?)
|
21
|
+
ERB.new(input).result(binding())
|
22
|
+
Erubis::Eruby.new(input).result(binding())
|
23
|
+
|
24
|
+
output = nil; GC.start
|
25
|
+
x.report('ERB') do
|
26
|
+
i = 0
|
27
|
+
(N/10).times do
|
28
|
+
output = ERB.new(input).result(binding())
|
29
|
+
output = ERB.new(input).result(binding())
|
30
|
+
output = ERB.new(input).result(binding())
|
31
|
+
output = ERB.new(input).result(binding())
|
32
|
+
output = ERB.new(input).result(binding())
|
33
|
+
output = ERB.new(input).result(binding())
|
34
|
+
output = ERB.new(input).result(binding())
|
35
|
+
output = ERB.new(input).result(binding())
|
36
|
+
output = ERB.new(input).result(binding())
|
37
|
+
output = ERB.new(input).result(binding())
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
output = nil; GC.start
|
42
|
+
x.report('ERB (reused)') do
|
43
|
+
erb = ERB.new(input)
|
44
|
+
(N/10).times do
|
45
|
+
output = erb.result(binding())
|
46
|
+
output = erb.result(binding())
|
47
|
+
output = erb.result(binding())
|
48
|
+
output = erb.result(binding())
|
49
|
+
output = erb.result(binding())
|
50
|
+
output = erb.result(binding())
|
51
|
+
output = erb.result(binding())
|
52
|
+
output = erb.result(binding())
|
53
|
+
output = erb.result(binding())
|
54
|
+
output = erb.result(binding())
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
output = nil; GC.start
|
59
|
+
x.report('ERB (defmethod)') do
|
60
|
+
ERB_FILENAME = filename
|
61
|
+
class Renderer
|
62
|
+
extend ERB::DefMethod
|
63
|
+
def_erb_method('render_erb', ERB_FILENAME)
|
64
|
+
attr_accessor :list
|
65
|
+
end
|
66
|
+
#self.extend ERB::DefMethod
|
67
|
+
#def_erb_method('render_erb', filename)
|
68
|
+
r = Renderer.new
|
69
|
+
r.list = list
|
70
|
+
(N/10).times do
|
71
|
+
output = r.render_erb()
|
72
|
+
output = r.render_erb()
|
73
|
+
output = r.render_erb()
|
74
|
+
output = r.render_erb()
|
75
|
+
output = r.render_erb()
|
76
|
+
output = r.render_erb()
|
77
|
+
output = r.render_erb()
|
78
|
+
output = r.render_erb()
|
79
|
+
output = r.render_erb()
|
80
|
+
output = r.render_erb()
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
output = nil; GC.start
|
85
|
+
x.report('Erubis::Eruby#result') do
|
86
|
+
(N/10).times do
|
87
|
+
output = Erubis::Eruby.new(input).result(binding())
|
88
|
+
output = Erubis::Eruby.new(input).result(binding())
|
89
|
+
output = Erubis::Eruby.new(input).result(binding())
|
90
|
+
output = Erubis::Eruby.new(input).result(binding())
|
91
|
+
output = Erubis::Eruby.new(input).result(binding())
|
92
|
+
output = Erubis::Eruby.new(input).result(binding())
|
93
|
+
output = Erubis::Eruby.new(input).result(binding())
|
94
|
+
output = Erubis::Eruby.new(input).result(binding())
|
95
|
+
output = Erubis::Eruby.new(input).result(binding())
|
96
|
+
output = Erubis::Eruby.new(input).result(binding())
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
output = nil; GC.start
|
101
|
+
input2 = input.gsub(/\blist\b/, '@list')
|
102
|
+
x.report('Erubis::Eruby#evaluate') do
|
103
|
+
(N/10).times do
|
104
|
+
output = Erubis::Eruby.new(input2).evaluate(self)
|
105
|
+
output = Erubis::Eruby.new(input2).evaluate(self)
|
106
|
+
output = Erubis::Eruby.new(input2).evaluate(self)
|
107
|
+
output = Erubis::Eruby.new(input2).evaluate(self)
|
108
|
+
output = Erubis::Eruby.new(input2).evaluate(self)
|
109
|
+
output = Erubis::Eruby.new(input2).evaluate(self)
|
110
|
+
output = Erubis::Eruby.new(input2).evaluate(self)
|
111
|
+
output = Erubis::Eruby.new(input2).evaluate(self)
|
112
|
+
output = Erubis::Eruby.new(input2).evaluate(self)
|
113
|
+
output = Erubis::Eruby.new(input2).evaluate(self)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
output = nil; GC.start
|
118
|
+
x.report('Erubis::Eruby#result (reused)') do
|
119
|
+
erubis = Erubis::Eruby.new(input)
|
120
|
+
(N/10).times do
|
121
|
+
output = erubis.result(binding())
|
122
|
+
output = erubis.result(binding())
|
123
|
+
output = erubis.result(binding())
|
124
|
+
output = erubis.result(binding())
|
125
|
+
output = erubis.result(binding())
|
126
|
+
output = erubis.result(binding())
|
127
|
+
output = erubis.result(binding())
|
128
|
+
output = erubis.result(binding())
|
129
|
+
output = erubis.result(binding())
|
130
|
+
output = erubis.result(binding())
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
output = nil; GC.start
|
135
|
+
x.report('Erubis::Eruby#evaluate (reused)') do
|
136
|
+
erubis = Erubis::Eruby.new(input2)
|
137
|
+
(N/10).times do
|
138
|
+
output = erubis.evaluate(self)
|
139
|
+
output = erubis.evaluate(self)
|
140
|
+
output = erubis.evaluate(self)
|
141
|
+
output = erubis.evaluate(self)
|
142
|
+
output = erubis.evaluate(self)
|
143
|
+
output = erubis.evaluate(self)
|
144
|
+
output = erubis.evaluate(self)
|
145
|
+
output = erubis.evaluate(self)
|
146
|
+
output = erubis.evaluate(self)
|
147
|
+
output = erubis.evaluate(self)
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
output = nil; GC.start
|
152
|
+
x.report('Erubis::Eruby (defmethod)') do
|
153
|
+
erubis = Erubis::Eruby.new(input)
|
154
|
+
eval "def render_erubis(list); #{erubis.src}; end"
|
155
|
+
(N/10).times do
|
156
|
+
output = render_erubis(list)
|
157
|
+
output = render_erubis(list)
|
158
|
+
output = render_erubis(list)
|
159
|
+
output = render_erubis(list)
|
160
|
+
output = render_erubis(list)
|
161
|
+
output = render_erubis(list)
|
162
|
+
output = render_erubis(list)
|
163
|
+
output = render_erubis(list)
|
164
|
+
output = render_erubis(list)
|
165
|
+
output = render_erubis(list)
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
output = nil; GC.start
|
170
|
+
x.report('Erubis::Eruby (defmethod#2)') do
|
171
|
+
erubis = Erubis::Eruby.new(input2)
|
172
|
+
eval "def render_erubis; #{erubis.src}; end"
|
173
|
+
(N/10).times do
|
174
|
+
output = render_erubis()
|
175
|
+
output = render_erubis()
|
176
|
+
output = render_erubis()
|
177
|
+
output = render_erubis()
|
178
|
+
output = render_erubis()
|
179
|
+
output = render_erubis()
|
180
|
+
output = render_erubis()
|
181
|
+
output = render_erubis()
|
182
|
+
output = render_erubis()
|
183
|
+
output = render_erubis()
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
|
188
|
+
File.open('hoge.output', 'w') {|f| f.write(output) }
|
189
|
+
|
190
|
+
end
|
191
|
+
|
192
|
+
__END__
|
193
|
+
|
194
|
+
$ ruby186 -s mybench2.rb -N=10000
|
195
|
+
user system total real
|
196
|
+
ERB 29.940000 0.810000 30.750000 ( 31.175876)
|
197
|
+
ERB (reused) 8.890000 0.030000 8.920000 ( 8.989230)
|
198
|
+
ERB (defmethod) 4.870000 0.010000 4.880000 ( 4.913900)
|
199
|
+
Erubis::Eruby#result 9.070000 0.030000 9.100000 ( 9.148731)
|
200
|
+
Erubis::Eruby#evaluate 9.130000 0.020000 9.150000 ( 9.209373)
|
201
|
+
Erubis::Eruby#result (reused) 5.580000 0.020000 5.600000 ( 5.666395)
|
202
|
+
Erubis::Eruby#evaluate (reused) 3.870000 0.000000 3.870000 ( 3.916371)
|
203
|
+
Erubis::Eruby (defmethod) 3.780000 0.000000 3.780000 ( 3.810064)
|
204
|
+
Erubis::Eruby (defmethod#2) 3.790000 0.010000 3.800000 ( 3.824344)
|
205
|
+
|
206
|
+
$ ruby187 -s mybench2.rb -N=10000
|
207
|
+
user system total real
|
208
|
+
ERB 16.410000 0.050000 16.460000 ( 16.549911)
|
209
|
+
ERB (reused) 5.880000 0.010000 5.890000 ( 5.930305)
|
210
|
+
ERB (defmethod) 3.850000 0.010000 3.860000 ( 3.883939)
|
211
|
+
Erubis::Eruby#result 9.320000 0.030000 9.350000 ( 9.394255)
|
212
|
+
Erubis::Eruby#evaluate 9.400000 0.020000 9.420000 ( 9.471952)
|
213
|
+
Erubis::Eruby#result (reused) 5.680000 0.010000 5.690000 ( 5.737928)
|
214
|
+
Erubis::Eruby#evaluate (reused) 3.960000 0.010000 3.970000 ( 3.992922)
|
215
|
+
Erubis::Eruby (defmethod) 3.850000 0.010000 3.860000 ( 3.896049)
|
216
|
+
Erubis::Eruby (defmethod#2) 3.850000 0.010000 3.860000 ( 3.872664)
|
217
|
+
|
218
|
+
$ ruby191 -s mybench2.rb -N=10000
|
219
|
+
user system total real
|
220
|
+
ERB 14.370000 0.050000 14.420000 ( 14.469204)
|
221
|
+
ERB (reused) 7.150000 0.030000 7.180000 ( 7.207674)
|
222
|
+
ERB (defmethod) 3.940000 0.010000 3.950000 ( 3.983292)
|
223
|
+
Erubis::Eruby#result 9.320000 0.040000 9.360000 ( 9.423159)
|
224
|
+
Erubis::Eruby#evaluate 9.550000 0.040000 9.590000 ( 9.659015)
|
225
|
+
Erubis::Eruby#result (reused) 6.420000 0.020000 6.440000 ( 6.479266)
|
226
|
+
Erubis::Eruby#evaluate (reused) 3.830000 0.020000 3.850000 ( 3.876132)
|
227
|
+
Erubis::Eruby (defmethod) 3.690000 0.010000 3.700000 ( 3.726208)
|
228
|
+
Erubis::Eruby (defmethod#2) 3.690000 0.020000 3.710000 ( 3.715565)
|
229
|
+
|
230
|
+
--------------------------------------------------------------------------------
|
231
|
+
|
232
|
+
$ ruby186 -s mybench2.rb -N=10000
|
233
|
+
user system total real
|
234
|
+
ERB 30.880000 0.240000 31.120000 ( 33.366328)
|
235
|
+
ERB (reused) 9.280000 0.070000 9.350000 ( 10.036719)
|
236
|
+
ERB (defmethod) 5.030000 0.040000 5.070000 ( 5.387336)
|
237
|
+
Erubis::Eruby#result 9.460000 0.070000 9.530000 ( 10.171072)
|
238
|
+
Erubis::Eruby#evaluate 9.540000 0.070000 9.610000 ( 10.289576)
|
239
|
+
Erubis::Eruby#result (reused) 5.830000 0.050000 5.880000 ( 6.286742)
|
240
|
+
Erubis::Eruby#evaluate (reused) 3.990000 0.030000 4.020000 ( 4.330680)
|
241
|
+
Erubis::Eruby (defmethod) 3.890000 0.030000 3.920000 ( 4.189439)
|
242
|
+
Erubis::Eruby (defmethod#2) 3.910000 0.030000 3.940000 ( 4.223124)
|
243
|
+
|
244
|
+
$ ruby187 -s mybench2.rb -N=10000
|
245
|
+
user system total real
|
246
|
+
ERB 16.950000 0.140000 17.090000 ( 18.276843)
|
247
|
+
ERB (reused) 6.100000 0.050000 6.150000 ( 6.578923)
|
248
|
+
ERB (defmethod) 3.990000 0.030000 4.020000 ( 4.314654)
|
249
|
+
Erubis::Eruby#result 9.690000 0.080000 9.770000 ( 10.467531)
|
250
|
+
Erubis::Eruby#evaluate 9.770000 0.080000 9.850000 ( 10.539132)
|
251
|
+
Erubis::Eruby#result (reused) 5.940000 0.040000 5.980000 ( 6.434127)
|
252
|
+
Erubis::Eruby#evaluate (reused) 4.110000 0.030000 4.140000 ( 4.424622)
|
253
|
+
Erubis::Eruby (defmethod) 3.990000 0.030000 4.020000 ( 4.292276)
|
254
|
+
Erubis::Eruby (defmethod#2) 3.990000 0.040000 4.030000 ( 4.332821)
|
255
|
+
|
256
|
+
$ ruby191 -s mybench2.rb -N=10000
|
257
|
+
user system total real
|
258
|
+
ERB 14.850000 0.150000 15.000000 ( 16.020819)
|
259
|
+
ERB (reused) 7.400000 0.070000 7.470000 ( 7.971797)
|
260
|
+
ERB (defmethod) 4.090000 0.030000 4.120000 ( 4.477900)
|
261
|
+
Erubis::Eruby#result 9.720000 0.100000 9.820000 ( 10.486989)
|
262
|
+
Erubis::Eruby#evaluate 9.930000 0.100000 10.030000 ( 10.720467)
|
263
|
+
Erubis::Eruby#result (reused) 6.660000 0.060000 6.720000 ( 7.201429)
|
264
|
+
Erubis::Eruby#evaluate (reused) 3.960000 0.040000 4.000000 ( 4.265177)
|
265
|
+
Erubis::Eruby (defmethod) 3.810000 0.040000 3.850000 ( 4.130089)
|
266
|
+
Erubis::Eruby (defmethod#2) 3.810000 0.030000 3.840000 ( 4.096473)
|
@@ -0,0 +1,163 @@
|
|
1
|
+
|
2
|
+
require 'yaml'
|
3
|
+
require 'benchmark'
|
4
|
+
require 'eruby'
|
5
|
+
require 'erb'
|
6
|
+
require 'erubis'
|
7
|
+
require 'erubis/tiny'
|
8
|
+
require 'erubis/engine/enhanced'
|
9
|
+
|
10
|
+
|
11
|
+
## default values
|
12
|
+
ntime = 10000
|
13
|
+
filename = 'erubybench.rhtml'
|
14
|
+
show_code = false
|
15
|
+
show_output = false
|
16
|
+
show_help = false
|
17
|
+
|
18
|
+
## parse command-line options
|
19
|
+
while ARGV[0] && ARGV[0][0] == ?-
|
20
|
+
option = ARGV.shift
|
21
|
+
case option
|
22
|
+
when '-n'
|
23
|
+
raise "-n: argument required." if ARGV.empty?
|
24
|
+
ntime = ARGV.shift.to_i
|
25
|
+
when '-f'
|
26
|
+
raise "-f: argument required." if ARGV.empty?
|
27
|
+
filename = ARGV.shift
|
28
|
+
when '-c'
|
29
|
+
show_code = true
|
30
|
+
when '-o'
|
31
|
+
show_output = true
|
32
|
+
when '-h'
|
33
|
+
show_help = true
|
34
|
+
else
|
35
|
+
raise "#{option}: unknown option."
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
## show help
|
41
|
+
if show_help
|
42
|
+
script = File.basename($0)
|
43
|
+
puts "usage: ruby #{script} [-h] [-c] [-o] [-n N] [-f filename] > /dev/null"
|
44
|
+
puts " -h: show help"
|
45
|
+
puts " -c: show ruby code"
|
46
|
+
puts " -o: show output"
|
47
|
+
puts " -n N: repeat N times in benchmark"
|
48
|
+
puts " -f file: eRuby file (*.rhtml) for benchmark"
|
49
|
+
exit
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
## load data for benchmark
|
54
|
+
ydoc = YAML.load_file('erubybench.yaml')
|
55
|
+
data = []
|
56
|
+
ydoc['data'].each do |hash|
|
57
|
+
#data << hash.inject({}) { |h, t| h[t[0].intern] = t[1]; h }
|
58
|
+
h = {}; hash.each { |k, v| h[k.intern] = v } ; data << h
|
59
|
+
end
|
60
|
+
data = data.sort_by { |h| h[:code] }
|
61
|
+
#require 'pp'; pp data
|
62
|
+
|
63
|
+
|
64
|
+
## eRuby string
|
65
|
+
input1 = File.read(filename)
|
66
|
+
input2 = input1.gsub(/<%==\s*(.*?)\s*%>/m, '@{\1}@').gsub(/<%=\s*(.*?)\s*%>/m, '@!{\1}@')
|
67
|
+
input2 = input2.gsub(/<%(.*?)%>/m, '<?rb\1?>')
|
68
|
+
|
69
|
+
|
70
|
+
## procedure objects for benchmark
|
71
|
+
code = nil
|
72
|
+
convert_procs = [
|
73
|
+
['eruby',
|
74
|
+
proc { code = ERuby::Compiler.new.compile_string(input1) } ],
|
75
|
+
# ['ERB',
|
76
|
+
# proc { code = ERB.new(input1).src } ],
|
77
|
+
['Erubis::Eruby',
|
78
|
+
proc { code = Erubis::Eruby.new.convert(input1) } ],
|
79
|
+
['Erubis::StringBufferEruby',
|
80
|
+
proc { code = Erubis::StringBufferEruby.new.convert(input1) } ],
|
81
|
+
['Erubis::StdoutEruby',
|
82
|
+
proc { code = Erubis::StdoutEruby.new.convert(input1) } ],
|
83
|
+
['Erubis::PI::Eruby',
|
84
|
+
proc { code = Erubis::PI::Eruby.new.convert(input2) } ],
|
85
|
+
['Erubis::TinyEruby',
|
86
|
+
proc { code = Erubis::TinyEruby.new.convert(input1) } ],
|
87
|
+
['Erubis::PI::TinyEruby',
|
88
|
+
proc { code = Erubis::PI::TinyEruby.new.convert(input2) } ],
|
89
|
+
]
|
90
|
+
|
91
|
+
evaluate_procs = [
|
92
|
+
['eruby',
|
93
|
+
proc { ERuby::load(filename) } ],
|
94
|
+
# ['ERB',
|
95
|
+
# proc { print ERB.new(input1).result() } ],
|
96
|
+
['Erubis::Eruby',
|
97
|
+
proc { print Erubis::Eruby.new.process(input1, binding()) } ],
|
98
|
+
['Erubis::StringBufferEruby',
|
99
|
+
proc { print Erubis::StringBufferEruby.new.process(input1, binding()) } ],
|
100
|
+
['Erubis::StdoutEruby',
|
101
|
+
proc { Erubis::StdoutEruby.new.process(input1, binding()) } ],
|
102
|
+
['Erubis::PI::Eruby',
|
103
|
+
proc { print Erubis::PI::Eruby.new.process(input2, binding()) } ],
|
104
|
+
['Erubis::TinyEruby',
|
105
|
+
proc { print eval(Erubis::TinyEruby.new.convert(input1)) } ],
|
106
|
+
['Erubis::PI::TinyEruby',
|
107
|
+
proc { print eval(Erubis::PI::TinyEruby.new.convert(input2)) } ],
|
108
|
+
]
|
109
|
+
|
110
|
+
|
111
|
+
## change benchmark library to use $stderr instead of $stdout
|
112
|
+
require 'benchmark'
|
113
|
+
module Benchmark
|
114
|
+
class Report
|
115
|
+
def print(*args)
|
116
|
+
$stderr.print(*args)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
module_function
|
120
|
+
def print(*args)
|
121
|
+
$stderr.print(*args)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
## show code or output
|
126
|
+
if show_code
|
127
|
+
convert_procs.each do |classname, proc_obj|
|
128
|
+
puts "---- #{classname} ----"
|
129
|
+
puts proc_obj.call
|
130
|
+
end
|
131
|
+
exit
|
132
|
+
end
|
133
|
+
|
134
|
+
if show_output
|
135
|
+
evaluate_procs.each do |classname, proc_obj|
|
136
|
+
puts "---- #{classname} ---"
|
137
|
+
proc_obj.call
|
138
|
+
end
|
139
|
+
exit
|
140
|
+
end
|
141
|
+
|
142
|
+
|
143
|
+
## do benchmark
|
144
|
+
width = 30
|
145
|
+
$stderr.puts "*** benchmark result of convertion *.rhtml into ruby code"
|
146
|
+
Benchmark.bm(width) do |x|
|
147
|
+
GC.start()
|
148
|
+
convert_procs.each do |classname, proc_obj|
|
149
|
+
x.report(classname) do
|
150
|
+
ntime.times(&proc_obj)
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
$stderr.puts
|
155
|
+
$stderr.puts "*** benchmark result of evaluation of *.rhtml"
|
156
|
+
Benchmark.bm(width) do |x|
|
157
|
+
GC.start()
|
158
|
+
evaluate_procs.each do |classname, proc_obj|
|
159
|
+
x.report(classname) do
|
160
|
+
ntime.times(&proc_obj)
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
3
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
4
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
5
|
+
<head>
|
6
|
+
<title>Stock Prices</title>
|
7
|
+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
8
|
+
<meta http-equiv="Content-Style-Type" content="text/css" />
|
9
|
+
<meta http-equiv="Content-Script-Type" content="text/javascript" />
|
10
|
+
<link rel="shortcut icon" href="/images/favicon.ico" />
|
11
|
+
<link rel="stylesheet" type="text/css" href="/css/style.css" media="all" />
|
12
|
+
<script type="text/javascript" src="/js/util.js"></script>
|
13
|
+
<style type="text/css">
|
14
|
+
/*<![CDATA[*/
|
15
|
+
|
16
|
+
body {
|
17
|
+
color: #333333;
|
18
|
+
line-height: 150%;
|
19
|
+
}
|
20
|
+
|
21
|
+
thead {
|
22
|
+
font-weight: bold;
|
23
|
+
background-color: #CCCCCC;
|
24
|
+
}
|
25
|
+
|
26
|
+
.odd {
|
27
|
+
background-color: #FFCCCC;
|
28
|
+
}
|
29
|
+
|
30
|
+
.even {
|
31
|
+
background-color: #CCCCFF;
|
32
|
+
}
|
33
|
+
|
34
|
+
.minus {
|
35
|
+
color: #FF0000;
|
36
|
+
}
|
37
|
+
|
38
|
+
/*]]>*/
|
39
|
+
</style>
|
40
|
+
|
41
|
+
</head>
|
42
|
+
|
43
|
+
<body>
|
44
|
+
|
45
|
+
<h1>Stock Prices</h1>
|
46
|
+
|
47
|
+
<table>
|
48
|
+
<thead>
|
49
|
+
<tr>
|
50
|
+
<th>#</th><th>symbol</th><th>name</th><th>price</th><th>change</th><th>ratio</th>
|
51
|
+
</tr>
|
52
|
+
</thead>
|