forked from jruby/jruby
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbench_compilation.rb
121 lines (111 loc) · 2.5 KB
/
bench_compilation.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
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