Project

General

Profile

Actions

Misc #19693

closed

Data initialization is significantly slower than Struct

Added by janosch-x (Janosch Müller) 12 months ago. Updated 12 months ago.

Status:
Closed
Assignee:
-
[ruby-core:113656]

Description

Maybe there is potential to make it as fast as Struct?

require 'benchmark/ips'

S = Struct.new(:a, :b, :c, :d, :e, :f, :g, :h, :i, :j)
D = Data.define(:a, :b, :c, :d, :e, :f, :g, :h, :i, :j)

Benchmark.ips do |x|
  x.report('Struct') { S.new(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) }
  x.report('Data')   { D.new(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) }
  x.compare!
end; 1

# => [...]
# =>             Struct:  6916530.4 i/s
# =>               Data:  1507259.5 i/s - 4.59x  slower
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0