Skip to content

Commit 6e3ec43

Browse files
authored
Add new benchmark testing initialize performance (#478)
These benchmarks will stress inlining and load-store forwarding and escape analysis. When each is implemented, we will see a big bump in these benchmarks in ZJIT.
1 parent fde3e58 commit 6e3ec43

3 files changed

Lines changed: 56 additions & 0 deletions

File tree

benchmarks.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,15 @@ object-new:
202202
category: micro
203203
single_file: true
204204
ractor: true
205+
object-new-initialize:
206+
desc: instantiate a new object and call initialize in a loop to test allocation and initialization performance
207+
category: micro
208+
single_file: true
209+
ractor: true
210+
object-new-no-escape:
211+
desc: instantiate new objects with ivars in a loop to test allocation and escape analysis performance
212+
category: micro
213+
single_file: true
205214
respond_to:
206215
desc: respond_to tests the performance of the respond_to? method.
207216
category: micro
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
require_relative '../harness/loader'
2+
3+
class C
4+
def initialize(a, b, c, d)
5+
@a = a
6+
@b = b
7+
@c = c
8+
@d = d
9+
end
10+
end
11+
12+
def test
13+
C.new(1, 2, 3, 4)
14+
end
15+
16+
run_benchmark(100) do
17+
i = 0
18+
while i < 1_000_000
19+
test
20+
i += 1
21+
end
22+
end

benchmarks/object-new-no-escape.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
require_relative '../harness/loader'
2+
3+
class Point
4+
attr_reader :x, :y
5+
def initialize(x, y)
6+
@x = x
7+
@y = y
8+
end
9+
10+
def ==(other)
11+
@x == other.x && @y == other.y
12+
end
13+
end
14+
15+
def test
16+
Point.new(1, 2) == Point.new(1, 2)
17+
end
18+
19+
run_benchmark(100) do
20+
i = 0
21+
while i < 1_000_000
22+
test
23+
i += 1
24+
end
25+
end

0 commit comments

Comments
 (0)