diff --git a/benchmarks.yml b/benchmarks.yml index 5b61fd2f..6c57bff5 100644 --- a/benchmarks.yml +++ b/benchmarks.yml @@ -202,6 +202,15 @@ object-new: category: micro single_file: true ractor: true +object-new-initialize: + desc: instantiate a new object and call initialize in a loop to test allocation and initialization performance + category: micro + single_file: true + ractor: true +object-new-no-escape: + desc: instantiate new objects with ivars in a loop to test allocation and escape analysis performance + category: micro + single_file: true respond_to: desc: respond_to tests the performance of the respond_to? method. category: micro diff --git a/benchmarks/object-new-initialize.rb b/benchmarks/object-new-initialize.rb new file mode 100644 index 00000000..bb90dbf1 --- /dev/null +++ b/benchmarks/object-new-initialize.rb @@ -0,0 +1,22 @@ +require_relative '../harness/loader' + +class C + def initialize(a, b, c, d) + @a = a + @b = b + @c = c + @d = d + end +end + +def test + C.new(1, 2, 3, 4) +end + +run_benchmark(100) do + i = 0 + while i < 1_000_000 + test + i += 1 + end +end diff --git a/benchmarks/object-new-no-escape.rb b/benchmarks/object-new-no-escape.rb new file mode 100644 index 00000000..5c38e03d --- /dev/null +++ b/benchmarks/object-new-no-escape.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