erbse 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGES.txt +828 -0
- data/MIT-LICENSE +20 -0
- data/README.md +51 -0
- data/benchmark/Makefile +6 -0
- data/benchmark/bench.rb +313 -0
- data/benchmark/bench_context.yaml +141 -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/erbse.gemspec +24 -0
- data/lib/erbse.rb +52 -0
- data/lib/erbse/context.rb +83 -0
- data/lib/erbse/converter.rb +357 -0
- data/lib/erbse/engine.rb +114 -0
- data/lib/erbse/engine/ec.rb +117 -0
- data/lib/erbse/engine/ecpp.rb +113 -0
- data/lib/erbse/engine/ejava.rb +110 -0
- data/lib/erbse/engine/ejavascript.rb +119 -0
- data/lib/erbse/engine/enhanced.rb +126 -0
- data/lib/erbse/engine/eperl.rb +95 -0
- data/lib/erbse/engine/ephp.rb +99 -0
- data/lib/erbse/engine/eruby.rb +119 -0
- data/lib/erbse/engine/escheme.rb +114 -0
- data/lib/erbse/engine/optimized.rb +127 -0
- data/lib/erbse/enhancer.rb +723 -0
- data/lib/erbse/error.rb +23 -0
- data/lib/erbse/evaluator.rb +88 -0
- data/lib/erbse/generator.rb +85 -0
- data/lib/erbse/helper.rb +47 -0
- data/lib/erbse/helpers/rails_form_helper.rb +197 -0
- data/lib/erbse/helpers/rails_helper.rb +353 -0
- data/lib/erbse/main.rb +516 -0
- data/lib/erbse/preprocessing.rb +58 -0
- data/lib/erbse/tiny.rb +144 -0
- data/lib/erbse/util.rb +22 -0
- data/lib/erbse/version.rb +3 -0
- data/test/assert-text-equal.rb +44 -0
- data/test/data/users-guide/Example.ejava +55 -0
- data/test/data/users-guide/array_example.result +9 -0
- data/test/data/users-guide/arraybuffer_example.result +9 -0
- data/test/data/users-guide/bipattern-example.rhtml +4 -0
- data/test/data/users-guide/bipattern_example.result +6 -0
- data/test/data/users-guide/bufvar-example.rb +10 -0
- data/test/data/users-guide/bufvar-example.result +17 -0
- data/test/data/users-guide/context.rb +6 -0
- data/test/data/users-guide/context.yaml +8 -0
- data/test/data/users-guide/def_method.rb +14 -0
- data/test/data/users-guide/def_method.result +3 -0
- data/test/data/users-guide/escape_example.result +9 -0
- data/test/data/users-guide/example.ec +27 -0
- data/test/data/users-guide/example.ecpp +30 -0
- data/test/data/users-guide/example.ejs +20 -0
- data/test/data/users-guide/example.eperl +18 -0
- data/test/data/users-guide/example.ephp +18 -0
- data/test/data/users-guide/example.eruby +6 -0
- data/test/data/users-guide/example.escheme +28 -0
- data/test/data/users-guide/example1.eruby +6 -0
- data/test/data/users-guide/example1.rb +17 -0
- data/test/data/users-guide/example1.result +16 -0
- data/test/data/users-guide/example10.rb +4 -0
- data/test/data/users-guide/example10.result +17 -0
- data/test/data/users-guide/example10.xhtml +14 -0
- data/test/data/users-guide/example10_x.result +17 -0
- data/test/data/users-guide/example11.php +20 -0
- data/test/data/users-guide/example11.result +23 -0
- data/test/data/users-guide/example11.rhtml +21 -0
- data/test/data/users-guide/example11_C.result +10 -0
- data/test/data/users-guide/example11_N.result +16 -0
- data/test/data/users-guide/example11_U.result +16 -0
- data/test/data/users-guide/example11_php.result +15 -0
- data/test/data/users-guide/example1_x.result +9 -0
- data/test/data/users-guide/example2.eruby +7 -0
- data/test/data/users-guide/example2.rb +10 -0
- data/test/data/users-guide/example2.result +27 -0
- data/test/data/users-guide/example2_trim.result +10 -0
- data/test/data/users-guide/example2_x.result +10 -0
- data/test/data/users-guide/example3.eruby +6 -0
- data/test/data/users-guide/example3.rb +10 -0
- data/test/data/users-guide/example31.result +22 -0
- data/test/data/users-guide/example32.result +4 -0
- data/test/data/users-guide/example3_e.result +8 -0
- data/test/data/users-guide/example4.eruby +3 -0
- data/test/data/users-guide/example4.rb +11 -0
- data/test/data/users-guide/example4.result +10 -0
- data/test/data/users-guide/example4_x.result +5 -0
- data/test/data/users-guide/example5.eruby +6 -0
- data/test/data/users-guide/example5.rb +16 -0
- data/test/data/users-guide/example5.result +7 -0
- data/test/data/users-guide/example6.rb +12 -0
- data/test/data/users-guide/example6.result +7 -0
- data/test/data/users-guide/example7.eruby +8 -0
- data/test/data/users-guide/example71.result +13 -0
- data/test/data/users-guide/example72.result +13 -0
- data/test/data/users-guide/example8.eruby +6 -0
- data/test/data/users-guide/example8_ruby.result +7 -0
- data/test/data/users-guide/example8_yaml.result +7 -0
- data/test/data/users-guide/example9.eruby +3 -0
- data/test/data/users-guide/example9.rb +8 -0
- data/test/data/users-guide/example9.result +9 -0
- data/test/data/users-guide/example91.result +5 -0
- data/test/data/users-guide/example92.result +4 -0
- data/test/data/users-guide/example_c.result +32 -0
- data/test/data/users-guide/example_java.result +56 -0
- data/test/data/users-guide/example_js.result +22 -0
- data/test/data/users-guide/example_perl.result +20 -0
- data/test/data/users-guide/example_php.result +19 -0
- data/test/data/users-guide/example_scheme.result +30 -0
- data/test/data/users-guide/example_scheme_display.result +29 -0
- data/test/data/users-guide/fasteruby-example.rb +8 -0
- data/test/data/users-guide/fasteruby-example.result +18 -0
- data/test/data/users-guide/fasteruby.rb +11 -0
- data/test/data/users-guide/fasteruby.result +38 -0
- data/test/data/users-guide/fasteruby.rhtml +15 -0
- data/test/data/users-guide/headerfooter-example.eruby +9 -0
- data/test/data/users-guide/headerfooter-example2.rb +8 -0
- data/test/data/users-guide/headerfooter-example2.rhtml +10 -0
- data/test/data/users-guide/headerfooter_example.result +11 -0
- data/test/data/users-guide/headerfooter_example2.result +13 -0
- data/test/data/users-guide/interpolation_example.result +9 -0
- data/test/data/users-guide/main_program1.rb +8 -0
- data/test/data/users-guide/main_program1.result +6 -0
- data/test/data/users-guide/main_program2.rb +8 -0
- data/test/data/users-guide/main_program2.result +6 -0
- data/test/data/users-guide/nocode-example.eruby +14 -0
- data/test/data/users-guide/nocode-php.result +20 -0
- data/test/data/users-guide/nocode_example.result +15 -0
- data/test/data/users-guide/normal-eruby-test.eruby +9 -0
- data/test/data/users-guide/normal_eruby_test.result +11 -0
- data/test/data/users-guide/notext-example.eruby +14 -0
- data/test/data/users-guide/notext-example.php +19 -0
- data/test/data/users-guide/notext-php.result +20 -0
- data/test/data/users-guide/notext_example.result +16 -0
- data/test/data/users-guide/percentline-example.rhtml +6 -0
- data/test/data/users-guide/percentline_example.result +9 -0
- data/test/data/users-guide/prefixedline-example.rb +9 -0
- data/test/data/users-guide/prefixedline-example.rhtml +6 -0
- data/test/data/users-guide/prefixedline_example.result +9 -0
- data/test/data/users-guide/printenable_example.result +4 -0
- data/test/data/users-guide/printenabled-example.eruby +3 -0
- data/test/data/users-guide/printenabled-example.rb +8 -0
- data/test/data/users-guide/printstatement_example.result +8 -0
- data/test/data/users-guide/simplify_example.result +9 -0
- data/test/data/users-guide/stderr.log +3 -0
- data/test/data/users-guide/stdout_exmple.result +9 -0
- data/test/data/users-guide/stringbuffer_example.result +9 -0
- data/test/data/users-guide/tail_260.result +4 -0
- data/test/data/users-guide/tailnewline.rhtml +3 -0
- data/test/data/users-guide/template1.rhtml +4 -0
- data/test/data/users-guide/template2.rhtml +4 -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 +233 -0
data/MIT-LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
copyright(c) 2006-2011 kuwata-lab.com all rights reserved.
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# Erbse
|
|
2
|
+
|
|
3
|
+
_An updated version of Erubis._
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
## Added features
|
|
8
|
+
|
|
9
|
+
* block support a la Rails.
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
== About Erubis
|
|
13
|
+
|
|
14
|
+
Erubis is an implementation of eRuby. It has the following features.
|
|
15
|
+
* Very fast, almost three times faster than ERB and even 10% faster than eruby
|
|
16
|
+
* Multi-language support (Ruby/PHP/C/Java/Scheme/Perl/Javascript)
|
|
17
|
+
* Auto escaping support
|
|
18
|
+
* Auto trimming spaces around '<% %>'
|
|
19
|
+
* Embedded pattern changeable (default '<% %>')
|
|
20
|
+
* Enable to handle Processing Instructions (PI) as embedded pattern (ex. '<?rb ... ?>')
|
|
21
|
+
* Context object available and easy to combine eRuby template with YAML datafile
|
|
22
|
+
* Print statement available
|
|
23
|
+
* Easy to extend and customize in subclass
|
|
24
|
+
* Ruby on Rails support
|
|
25
|
+
|
|
26
|
+
Erubis is implemented in pure Ruby. It requires Ruby 1.8 or higher.
|
|
27
|
+
Erubis now supports Ruby 1.9.
|
|
28
|
+
|
|
29
|
+
See doc/users-guide.html for details.
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
== Benchmark
|
|
36
|
+
|
|
37
|
+
'benchmark/erubybenchmark.rb' is a benchmark script of Erubis.
|
|
38
|
+
Try 'ruby erubybenchmark.rb' in benchmark directory.
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
# License
|
|
43
|
+
|
|
44
|
+
MIT License
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
# Authors
|
|
49
|
+
|
|
50
|
+
Copyright 2015 Nick Sutterer <apotonick@gmail.com>
|
|
51
|
+
Copyright 2006-2011 makoto kuwata <kwa(at)kuwata-lab.com>
|
data/benchmark/Makefile
ADDED
data/benchmark/bench.rb
ADDED
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
###
|
|
4
|
+
### $Release: 2.7.0 $
|
|
5
|
+
### copyright(c) 2006-2011 kuwata-lab.com all rights reserved.
|
|
6
|
+
###
|
|
7
|
+
|
|
8
|
+
require 'erb'
|
|
9
|
+
require 'erubis'
|
|
10
|
+
require 'erubis/tiny'
|
|
11
|
+
require 'erubis/engine/enhanced'
|
|
12
|
+
require 'yaml'
|
|
13
|
+
require 'cgi'
|
|
14
|
+
include ERB::Util
|
|
15
|
+
|
|
16
|
+
begin
|
|
17
|
+
require 'eruby'
|
|
18
|
+
rescue LoadError
|
|
19
|
+
ERuby = nil
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def File.write(filename, content)
|
|
23
|
+
File.open(filename, 'w') { |f| f.write(content) }
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
## change benchmark library to use $stderr instead of $stdout
|
|
28
|
+
require 'benchmark'
|
|
29
|
+
module Benchmark
|
|
30
|
+
class Report
|
|
31
|
+
def print(*args)
|
|
32
|
+
$stderr.print(*args)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
module_function
|
|
36
|
+
def print(*args)
|
|
37
|
+
$stderr.print(*args)
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class BenchmarkApplication
|
|
43
|
+
|
|
44
|
+
TARGETS = %w[eruby
|
|
45
|
+
ERB ERB(cached)
|
|
46
|
+
Erubis::Eruby Erubis::Eruby(cached)
|
|
47
|
+
Erubis::FastEruby Erubis::FastEruby(cached)
|
|
48
|
+
Erubis::TinyEruby
|
|
49
|
+
Erubis::ArrayBufferEruby
|
|
50
|
+
Erubis::PrintOutEruby
|
|
51
|
+
Erubis::StdoutEruby
|
|
52
|
+
]
|
|
53
|
+
|
|
54
|
+
def initialize(ntimes, context, targets=nil, params={})
|
|
55
|
+
@ntimes = ntimes
|
|
56
|
+
@context = context
|
|
57
|
+
@targets = targets && !targets.empty? ? targets : TARGETS.dup
|
|
58
|
+
@testmode = params[:testmode] || 'execute'
|
|
59
|
+
@erubyfile = params[:erubyfile] || 'erubybench.rhtml'
|
|
60
|
+
@printout = params[:printout] || false
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
attr_accessor :ntimes, :targets
|
|
64
|
+
attr_accessor :testmode, :erubyfile, :contextfile, :printout
|
|
65
|
+
|
|
66
|
+
def context2code(context, varname='context')
|
|
67
|
+
s = ''
|
|
68
|
+
context.each { |k, | s << "#{k} = #{varname}[#{k.inspect}]; " }
|
|
69
|
+
return s
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def perform_benchmark
|
|
73
|
+
width = 30
|
|
74
|
+
$stderr.puts "*** ntimes=#{@ntimes}, testmode=#{@testmode}"
|
|
75
|
+
Benchmark.bm(width) do |job|
|
|
76
|
+
for target in @targets do
|
|
77
|
+
method = "#{@testmode}_#{target.gsub(/::|-|\(/, '_').gsub(/\)/, '').downcase}"
|
|
78
|
+
#$stderr.puts "*** debug: method=#{method.inspect}"
|
|
79
|
+
next unless self.respond_to?(method)
|
|
80
|
+
filename = "bench_#{(target =~ /^(\w+)/) && $1.downcase}.rhtml"
|
|
81
|
+
title = target
|
|
82
|
+
output = nil
|
|
83
|
+
job.report(title) do
|
|
84
|
+
output = self.__send__(method, filename, @context)
|
|
85
|
+
end
|
|
86
|
+
File.write("output.#{target.gsub(/[^\w]/,'')}", output) if @printout && output && !output.empty?
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
##
|
|
92
|
+
|
|
93
|
+
def execute_eruby(filename, context)
|
|
94
|
+
return unless ERuby
|
|
95
|
+
#eval context2code(context)
|
|
96
|
+
list = context['list']
|
|
97
|
+
@ntimes.times do
|
|
98
|
+
ERuby.import(filename)
|
|
99
|
+
end
|
|
100
|
+
return nil
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def execute_erb(filename, context)
|
|
104
|
+
#eval context2code(context)
|
|
105
|
+
list = context['list']
|
|
106
|
+
output = nil
|
|
107
|
+
@ntimes.times do
|
|
108
|
+
eruby = ERB.new(File.read(filename))
|
|
109
|
+
output = eruby.result(binding())
|
|
110
|
+
print output
|
|
111
|
+
end
|
|
112
|
+
return output
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def execute_erb_cached(filename, context)
|
|
116
|
+
#eval context2code(context)
|
|
117
|
+
list = context['list']
|
|
118
|
+
output = nil
|
|
119
|
+
cachefile = filename + '.cache'
|
|
120
|
+
File.unlink(cachefile) if test(?f, cachefile)
|
|
121
|
+
@ntimes.times do
|
|
122
|
+
if !test(?f, cachefile) || File.mtime(filename) > File.mtime(cachefile)
|
|
123
|
+
eruby = ERB.new(File.read(filename))
|
|
124
|
+
File.write(cachefile, eruby.src)
|
|
125
|
+
else
|
|
126
|
+
eruby = ERB.new('')
|
|
127
|
+
#eruby.src = File.read(cachefile)
|
|
128
|
+
eruby.instance_variable_set("@src", File.read(cachefile))
|
|
129
|
+
end
|
|
130
|
+
output = eruby.result(binding())
|
|
131
|
+
print output
|
|
132
|
+
end
|
|
133
|
+
return output
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
## no cached
|
|
137
|
+
for klass in %w[Eruby FastEruby TinyEruby ArrayBufferEruby PrintOutEruby StdoutEruby] do
|
|
138
|
+
s = <<-END
|
|
139
|
+
def execute_erubis_#{klass.downcase}(filename, context)
|
|
140
|
+
#eval context2code(context)
|
|
141
|
+
list = context['list']
|
|
142
|
+
output = nil
|
|
143
|
+
@ntimes.times do
|
|
144
|
+
eruby = Erubis::#{klass}.new(File.read(filename))
|
|
145
|
+
output = eruby.result(binding())
|
|
146
|
+
print output
|
|
147
|
+
end
|
|
148
|
+
return output
|
|
149
|
+
end
|
|
150
|
+
END
|
|
151
|
+
eval s
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
## cached
|
|
155
|
+
for klass in %w[Eruby FastEruby] do
|
|
156
|
+
s = <<-END
|
|
157
|
+
def execute_erubis_#{klass.downcase}_cached(filename, context)
|
|
158
|
+
#eval context2code(context)
|
|
159
|
+
list = context['list']
|
|
160
|
+
cachefile = filename + '.cache'
|
|
161
|
+
File.unlink(cachefile) if test(?f, cachefile)
|
|
162
|
+
output = nil
|
|
163
|
+
@ntimes.times do
|
|
164
|
+
eruby = Erubis::#{klass}.load_file(filename)
|
|
165
|
+
output = eruby.result(binding())
|
|
166
|
+
print output
|
|
167
|
+
end
|
|
168
|
+
savefile = cachefile.sub(/\\.cache$/, '.#{klass.downcase}.cache')
|
|
169
|
+
File.rename(cachefile, savefile)
|
|
170
|
+
return output
|
|
171
|
+
end
|
|
172
|
+
END
|
|
173
|
+
eval s
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
##
|
|
177
|
+
|
|
178
|
+
def convert_eruby(filename, context)
|
|
179
|
+
return unless ERuby
|
|
180
|
+
#eval context2code(context)
|
|
181
|
+
list = context['list']
|
|
182
|
+
output = nil
|
|
183
|
+
@ntimes.times do
|
|
184
|
+
output = ERuby::Compiler.new.compile_string(File.read(filename))
|
|
185
|
+
end
|
|
186
|
+
return output
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
def convert_erb(filename, context)
|
|
190
|
+
#eval context2code(context)
|
|
191
|
+
list = context['list']
|
|
192
|
+
output = nil
|
|
193
|
+
@ntimes.times do
|
|
194
|
+
eruby = ERB.new(File.read(filename))
|
|
195
|
+
output = eruby.src
|
|
196
|
+
end
|
|
197
|
+
return output
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
for klass in %w[Eruby FastEruby TinyEruby]
|
|
201
|
+
s = <<-END
|
|
202
|
+
def convert_erubis_#{klass.downcase}(filename, context)
|
|
203
|
+
#eval context2code(context)
|
|
204
|
+
list = context['list']
|
|
205
|
+
output = nil
|
|
206
|
+
@ntimes.times do
|
|
207
|
+
eruby = Erubis::#{klass}.new(File.read(filename))
|
|
208
|
+
output = eruby.src
|
|
209
|
+
end
|
|
210
|
+
return output
|
|
211
|
+
end
|
|
212
|
+
END
|
|
213
|
+
eval s
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
require 'optparse'
|
|
220
|
+
|
|
221
|
+
class MainApplication
|
|
222
|
+
|
|
223
|
+
def parse_argv(argv=ARGV)
|
|
224
|
+
optparser = OptionParser.new
|
|
225
|
+
options = {}
|
|
226
|
+
['-h', '-n N', '-t erubyfile', '-f contextfile', '-A', '-e',
|
|
227
|
+
'-x exclude', '-m testmode', '-X', '-p', '-D'].each do |opt|
|
|
228
|
+
optparser.on(opt) { |val| options[opt[1].chr] = val }
|
|
229
|
+
end
|
|
230
|
+
begin
|
|
231
|
+
targets = optparser.parse!(argv)
|
|
232
|
+
rescue => ex
|
|
233
|
+
$stderr.puts "#{@script}: #{ex.to_s}"
|
|
234
|
+
exit(1)
|
|
235
|
+
end
|
|
236
|
+
return options, targets
|
|
237
|
+
end
|
|
238
|
+
|
|
239
|
+
def execute
|
|
240
|
+
@script = File.basename($0)
|
|
241
|
+
ntimes = 1000
|
|
242
|
+
targets = BenchmarkApplication::TARGETS.dup
|
|
243
|
+
testmode = 'execute'
|
|
244
|
+
contextfile = 'bench_context.yaml'
|
|
245
|
+
#
|
|
246
|
+
options, args = parse_argv(ARGV)
|
|
247
|
+
ntimes = options['n'].to_i if options['n']
|
|
248
|
+
targets = args if args && !args.empty?
|
|
249
|
+
targets = targets - options['x'].split(/,/) if options['x']
|
|
250
|
+
testmode = options['m'] if options['m']
|
|
251
|
+
contextfile = options['f'] if options['f']
|
|
252
|
+
erubyfile = options['t'] if options['t']
|
|
253
|
+
#
|
|
254
|
+
if options['h']
|
|
255
|
+
$stderr.puts "Usage: ruby #{@script} [..options..] [..targets..]"
|
|
256
|
+
$stderr.puts " -h : help"
|
|
257
|
+
$stderr.puts " -n N : loop N times"
|
|
258
|
+
$stderr.puts " -f datafile : context data filename (*.yaml)"
|
|
259
|
+
$stderr.puts " -x exclude : exclude target name"
|
|
260
|
+
$stdout.puts " -m testmode : 'execute' or 'convert' (default 'execute')"
|
|
261
|
+
$stderr.puts " -p : print output to file (filename: 'output.TARGETNAME')"
|
|
262
|
+
return
|
|
263
|
+
end
|
|
264
|
+
#
|
|
265
|
+
#if ! options['t']
|
|
266
|
+
for item in %w[eruby erb erubis]
|
|
267
|
+
fname = "bench_#{item}.rhtml"
|
|
268
|
+
header = File.read("templates/_header.html")
|
|
269
|
+
#body = File.read("templates/#{erubyfile}")
|
|
270
|
+
body = File.read("templates/#{fname}")
|
|
271
|
+
footer = File.read("templates/_footer.html")
|
|
272
|
+
content = header + body + footer
|
|
273
|
+
File.write(fname, content)
|
|
274
|
+
end
|
|
275
|
+
#
|
|
276
|
+
if options['e'] # escape
|
|
277
|
+
tuples = [
|
|
278
|
+
[ 'bench_eruby.rhtml', '<%= CGI.escapeHTML((\1).to_s) %>' ],
|
|
279
|
+
[ 'bench_erb.rhtml', '<%=h \1 %>' ],
|
|
280
|
+
[ 'bench_erubis.rhtml', '<%== \1 %>' ],
|
|
281
|
+
]
|
|
282
|
+
for fname, replace in tuples
|
|
283
|
+
content = File.read(fname).gsub(/<%= ?(.*?) ?%>/, replace)
|
|
284
|
+
File.write(fname, content)
|
|
285
|
+
end
|
|
286
|
+
targets.delete('Erubis::TinyEruby') ## because TinyEruby doesn't support '<%== =>'
|
|
287
|
+
end
|
|
288
|
+
#
|
|
289
|
+
context = YAML.load_file(contextfile)
|
|
290
|
+
#
|
|
291
|
+
params = {
|
|
292
|
+
:printout=>options['p'],
|
|
293
|
+
:testmode=>testmode,
|
|
294
|
+
}
|
|
295
|
+
app = BenchmarkApplication.new(ntimes, context, targets, params)
|
|
296
|
+
app.perform_benchmark()
|
|
297
|
+
end
|
|
298
|
+
|
|
299
|
+
end
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
if __FILE__ == $0
|
|
303
|
+
|
|
304
|
+
## open /dev/null
|
|
305
|
+
$stdout = File.open('/dev/null', 'w')
|
|
306
|
+
at_exit do
|
|
307
|
+
$stdout.close()
|
|
308
|
+
end
|
|
309
|
+
|
|
310
|
+
## start benchmark
|
|
311
|
+
MainApplication.new().execute()
|
|
312
|
+
|
|
313
|
+
end
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
list:
|
|
2
|
+
- name: Adobe Systems
|
|
3
|
+
name2: Adobe Systems Inc.
|
|
4
|
+
url: http://www.adobe.com
|
|
5
|
+
symbol: ADBE
|
|
6
|
+
price: 39.26
|
|
7
|
+
change: 0.13
|
|
8
|
+
ratio: 0.33
|
|
9
|
+
- name: Advanced Micro Devices
|
|
10
|
+
name2: Advanced Micro Devices Inc.
|
|
11
|
+
url: http://www.amd.com
|
|
12
|
+
symbol: AMD
|
|
13
|
+
price: 16.22
|
|
14
|
+
change: 0.17
|
|
15
|
+
ratio: 1.06
|
|
16
|
+
- name: Amazon.com
|
|
17
|
+
name2: Amazon.com Inc
|
|
18
|
+
url: http://www.amazon.com
|
|
19
|
+
symbol: AMZN
|
|
20
|
+
price: 36.85
|
|
21
|
+
change: -0.23
|
|
22
|
+
ratio: -0.62
|
|
23
|
+
- name: Apple
|
|
24
|
+
name2: Apple Inc.
|
|
25
|
+
url: http://www.apple.com
|
|
26
|
+
symbol: AAPL
|
|
27
|
+
price: 85.38
|
|
28
|
+
change: -0.87
|
|
29
|
+
ratio: -1.01
|
|
30
|
+
- name: BEA Systems
|
|
31
|
+
name2: BEA Systems Inc.
|
|
32
|
+
url: http://www.bea.com
|
|
33
|
+
symbol: BEAS
|
|
34
|
+
price: 12.46
|
|
35
|
+
change: 0.09
|
|
36
|
+
ratio: 0.73
|
|
37
|
+
- name: CA
|
|
38
|
+
name2: CA, Inc.
|
|
39
|
+
url: http://www.ca.com
|
|
40
|
+
symbol: CA
|
|
41
|
+
price: 24.66
|
|
42
|
+
change: 0.38
|
|
43
|
+
ratio: 1.57
|
|
44
|
+
- name: Cisco Systems
|
|
45
|
+
name2: Cisco Systems Inc.
|
|
46
|
+
url: http://www.cisco.com
|
|
47
|
+
symbol: CSCO
|
|
48
|
+
price: 26.35
|
|
49
|
+
change: 0.13
|
|
50
|
+
ratio: 0.5
|
|
51
|
+
- name: Dell
|
|
52
|
+
name2: Dell Corp.
|
|
53
|
+
url: http://www.dell.com/
|
|
54
|
+
symbol: DELL
|
|
55
|
+
price: 23.73
|
|
56
|
+
change: -0.42
|
|
57
|
+
ratio: -1.74
|
|
58
|
+
- name: eBay
|
|
59
|
+
name2: eBay Inc.
|
|
60
|
+
url: http://www.ebay.com
|
|
61
|
+
symbol: EBAY
|
|
62
|
+
price: 31.65
|
|
63
|
+
change: -0.8
|
|
64
|
+
ratio: -2.47
|
|
65
|
+
- name: Google
|
|
66
|
+
name2: Google Inc.
|
|
67
|
+
url: http://www.google.com
|
|
68
|
+
symbol: GOOG
|
|
69
|
+
price: 495.84
|
|
70
|
+
change: 7.75
|
|
71
|
+
ratio: 1.59
|
|
72
|
+
- name: Hewlett-Packard
|
|
73
|
+
name2: Hewlett-Packard Co.
|
|
74
|
+
url: http://www.hp.com
|
|
75
|
+
symbol: HPQ
|
|
76
|
+
price: 41.69
|
|
77
|
+
change: -0.02
|
|
78
|
+
ratio: -0.05
|
|
79
|
+
- name: IBM
|
|
80
|
+
name2: International Business Machines Corp.
|
|
81
|
+
url: http://www.ibm.com
|
|
82
|
+
symbol: IBM
|
|
83
|
+
price: 97.45
|
|
84
|
+
change: -0.06
|
|
85
|
+
ratio: -0.06
|
|
86
|
+
- name: Intel
|
|
87
|
+
name2: Intel Corp.
|
|
88
|
+
url: http://www.intel.com
|
|
89
|
+
symbol: INTC
|
|
90
|
+
price: 20.53
|
|
91
|
+
change: -0.07
|
|
92
|
+
ratio: -0.34
|
|
93
|
+
- name: Juniper Networks
|
|
94
|
+
name2: Juniper Networks, Inc
|
|
95
|
+
url: http://www.juniper.net/
|
|
96
|
+
symbol: JNPR
|
|
97
|
+
price: 18.96
|
|
98
|
+
change: 0.5
|
|
99
|
+
ratio: 2.71
|
|
100
|
+
- name: Microsoft
|
|
101
|
+
name2: Microsoft Corp
|
|
102
|
+
url: http://www.microsoft.com
|
|
103
|
+
symbol: MSFT
|
|
104
|
+
price: 30.6
|
|
105
|
+
change: 0.15
|
|
106
|
+
ratio: 0.49
|
|
107
|
+
- name: Oracle
|
|
108
|
+
name2: Oracle Corp.
|
|
109
|
+
url: http://www.oracle.com
|
|
110
|
+
symbol: ORCL
|
|
111
|
+
price: 17.15
|
|
112
|
+
change: 0.17
|
|
113
|
+
ratio: 1.0
|
|
114
|
+
- name: SAP
|
|
115
|
+
name2: SAP AG
|
|
116
|
+
url: http://www.sap.com
|
|
117
|
+
symbol: SAP
|
|
118
|
+
price: 46.2
|
|
119
|
+
change: -0.16
|
|
120
|
+
ratio: -0.35
|
|
121
|
+
- name: Seagate Technology
|
|
122
|
+
name2: Seagate Technology
|
|
123
|
+
url: http://www.seagate.com/
|
|
124
|
+
symbol: STX
|
|
125
|
+
price: 27.35
|
|
126
|
+
change: -0.36
|
|
127
|
+
ratio: -1.3
|
|
128
|
+
- name: Sun Microsystems
|
|
129
|
+
name2: Sun Microsystems Inc.
|
|
130
|
+
url: http://www.sun.com
|
|
131
|
+
symbol: SUNW
|
|
132
|
+
price: 6.33
|
|
133
|
+
change: -0.01
|
|
134
|
+
ratio: -0.16
|
|
135
|
+
- name: Yahoo
|
|
136
|
+
name2: Yahoo! Inc.
|
|
137
|
+
url: http://www.yahoo.com
|
|
138
|
+
symbol: YHOO
|
|
139
|
+
price: 28.04
|
|
140
|
+
change: -0.17
|
|
141
|
+
ratio: -0.6
|