Skip to content

Commit 951cc3d

Browse files
authored
Add struct new micro benchmark (#536)
Benchmark allocating, writing, and reading fields
1 parent a5d4ae8 commit 951cc3d

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

‎benchmarks.yml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,10 @@ str_concat:
256256
category: micro
257257
single_file: true
258258
ractor: true
259+
struct-new-no-escape:
260+
desc: instantiate new struct objects with fields in a loop to test allocation and escape analysis performance
261+
category: micro
262+
single_file: true
259263
structaref:
260264
desc: structaref tests the performance of getting Struct members
261265
category: micro

‎benchmarks/struct-new-no-escape.rb‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
require_relative '../harness/loader'
2+
3+
Point = Struct.new(:x, :y)
4+
5+
def test
6+
p = Point.new(1, 2)
7+
p.x + p.y
8+
end
9+
10+
run_benchmark(100) do
11+
i = 0
12+
while i < 1_000_000
13+
test
14+
i += 1
15+
end
16+
end

0 commit comments

Comments
 (0)