diff --git a/benchmarks.yml b/benchmarks.yml index bc13b841..e6749e7b 100644 --- a/benchmarks.yml +++ b/benchmarks.yml @@ -256,6 +256,10 @@ str_concat: category: micro single_file: true ractor: true +struct-new-no-escape: + desc: instantiate new struct objects with fields in a loop to test allocation and escape analysis performance + category: micro + single_file: true structaref: desc: structaref tests the performance of getting Struct members category: micro diff --git a/benchmarks/struct-new-no-escape.rb b/benchmarks/struct-new-no-escape.rb new file mode 100644 index 00000000..1a45269f --- /dev/null +++ b/benchmarks/struct-new-no-escape.rb @@ -0,0 +1,16 @@ +require_relative '../harness/loader' + +Point = Struct.new(:x, :y) + +def test + p = Point.new(1, 2) + p.x + p.y +end + +run_benchmark(100) do + i = 0 + while i < 1_000_000 + test + i += 1 + end +end