From 6a860bf068cf2f6b883c9ab04e908dd6da90d55f Mon Sep 17 00:00:00 2001 From: Max Bernstein Date: Tue, 17 Feb 2026 12:18:25 -0500 Subject: [PATCH] Add new benchmark testing initialize performance --- benchmarks.yml | 5 +++++ benchmarks/object-new-ivars.rb | 25 +++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 benchmarks/object-new-ivars.rb diff --git a/benchmarks.yml b/benchmarks.yml index 5b61fd2f..4f8e4ef3 100644 --- a/benchmarks.yml +++ b/benchmarks.yml @@ -202,6 +202,11 @@ object-new: category: micro single_file: true ractor: true +object-new-ivars: + desc: instantiate a new object with ivars in a loop to test allocation and escape analysis performance + category: micro + single_file: true + ractor: true respond_to: desc: respond_to tests the performance of the respond_to? method. category: micro diff --git a/benchmarks/object-new-ivars.rb b/benchmarks/object-new-ivars.rb new file mode 100644 index 00000000..5c38e03d --- /dev/null +++ b/benchmarks/object-new-ivars.rb @@ -0,0 +1,25 @@ +require_relative '../harness/loader' + +class Point + attr_reader :x, :y + def initialize(x, y) + @x = x + @y = y + end + + def ==(other) + @x == other.x && @y == other.y + end +end + +def test + Point.new(1, 2) == Point.new(1, 2) +end + +run_benchmark(100) do + i = 0 + while i < 1_000_000 + test + i += 1 + end +end