I was working on another email part of my Modern Ruby Email Course so I did some benchmarks on `Data.define` vs `Struct` vs `OpenStruct`

- When creating new objects, Struct is the fastest, Open Struct the slowest
- When accessing attributes, Data(dot)define is slightly faster

Creating new objects

Here is a ``bmbm` benchmark result

#Ruby #Benchmark #ValueObject

Creating new objects

Here is the `ibs` benchmark result:

Creating new objects

Here is the `memory` benchmark result:

Accessing attributes

This time `Data.define` is maybe the fastest one but there is not a signifiant difference to `Struct`. On the other side `OpenStruct` is almost twice as slow.

#Ruby #Benchmark #ValueObject

Here is the `bmbm` benchmark result:
Here is the `ibs` benchmark result:

I run this on my local machine:
• Apple M3 PRO
• 36 GB
• Running Mac OS 14.4 (23E214)
• Ruby 3.3.0

You can explore the repo with the code that I run and all the resources at https://github.com/lucianghinda/value-object-in-ruby-benchmarks

GitHub - lucianghinda/value-object-in-ruby-benchmarks: A series of micro benchmarks about Data.define vs Struct vs OpenStruct in #Ruby

A series of micro benchmarks about Data.define vs Struct vs OpenStruct in #Ruby - lucianghinda/value-object-in-ruby-benchmarks

GitHub
Ruby Benchmark: Data.define, Struct, OpenStruct

Compare `Data.define`, `Struct`, `OpenStruct` in Ruby: object creation and accessing attributes

All about coding
@lucian neat! Thanks for sharing.
@jrthreadgill You are welcome. Glad that you found it useful