-
-
Notifications
You must be signed in to change notification settings - Fork 921
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a benchmark for the compiler; better performance than I expected,…
… but it could be improved. Need a better benchmark for complex inspection. git-svn-id: http://svn.codehaus.org/jruby/trunk/jruby@7600 961051c9-f516-0410-bf72-c9f7e237a7b7
- Loading branch information
Showing
1 changed file
with
121 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,121 @@ | |||
require 'benchmark' | |||
require 'java' | |||
|
|||
src = File.read(__FILE__) | |||
StandardASMCompiler = org.jruby.compiler.impl.StandardASMCompiler | |||
ASTCompiler = org.jruby.compiler.ASTCompiler | |||
ASTInspector = org.jruby.compiler.ASTInspector | |||
|
|||
def parse(src) | |||
JRuby.parse(src, __FILE__, false) | |||
end | |||
|
|||
def inspect(node) | |||
inspector = ASTInspector.new | |||
inspector.inspect(node) | |||
inspector | |||
end | |||
|
|||
def compile(node, inspector) | |||
filename = node.position.file | |||
classname = filename.sub("/", ".").sub("\\", ".").sub(".rb", "") | |||
context = StandardASMCompiler.new(classname, filename) | |||
compiler = ASTCompiler.new | |||
compiler.compileRoot(node, context, inspector) | |||
end | |||
|
|||
TIMES = (ARGV[0] || 5).to_i | |||
TIMES.times { | |||
Benchmark.bm(30) {|bm| | |||
bm.report("1k * parse this file") { | |||
1000.times { parse(src) } | |||
} | |||
# this is a little misleading since inspect does not follow blocks, defs, classes, or modules | |||
bm.report("1k * inspect this file") { | |||
node = parse(src); | |||
1000.times { inspect(node) } | |||
} | |||
bm.report("1k * compile this file") { | |||
node = parse(src); | |||
inspector = inspect(node); | |||
1000.times { compile(node, inspector) } | |||
} | |||
} | |||
} | |||
|
|||
# Dummy clas to make this more than a trivial compilation | |||
class Dummy | |||
def dummy | |||
a,b,c,d,e,f,g,h,i,j = 1,2,3,4,5,6,7,8,9,0 | |||
a,b,c,d = :foo, :bar, :baz, :quux | |||
dummy2 | |||
end | |||
|
|||
def dummy2 | |||
a = 11111111111111111111111111111111111111111111111111111111111 | |||
b = 11111111111111111111111111111111111111111111111111111111111 | |||
c = 11111111111111111111111111111111111111111111111111111111111 | |||
d = "fooooooooooooooooooooooooooo" | |||
e = "barrrrrrrrrrrrrrrrrrrrrrrrrr" | |||
dummy3 | |||
end | |||
|
|||
def dummy3 | |||
if true; | |||
if true; | |||
if true; | |||
if true; | |||
if true; | |||
if true; | |||
if true; | |||
if true; | |||
if true; | |||
if true; | |||
else | |||
end | |||
else | |||
end | |||
else | |||
end | |||
else | |||
end | |||
else | |||
end | |||
else | |||
end | |||
else | |||
end | |||
else | |||
end | |||
else | |||
end | |||
else | |||
end | |||
dummy3 | |||
end | |||
|
|||
def dummy4 | |||
foo { foo { foo { foo { foo { foo { foo { foo { foo { foo }}}}}}}}} | |||
end | |||
def foo | |||
yield | |||
yield | |||
yield | |||
yield | |||
yield | |||
yield | |||
yield | |||
end | |||
|
|||
def == | |||
super | |||
super | |||
super | |||
super() | |||
super() | |||
super() | |||
super(1,2,3) | |||
super(1,2,3) | |||
super(1,2,3) | |||
end | |||
end |