It is benchmarks about OpenStruct.
The ostruct gem warn bellow message with Warning[:performance] = true
OpenStruct use is discouraged for performance reasons
- Mac mini (Apple M1)
- OS: macOS 14.16
- Ruby: 3.3.5 (+YJIT)
$ ruby --yjit benchmark_struct.rb
ruby 3.3.5 (2024-09-03 revision ef084cc8f4) +YJIT [arm64-darwin23]
times: 10000
Rehearsal ----------------------------------------------------------
OpenStruct.new (args) 0.072869 0.001233 0.074102 ( 0.074971)
OpenStruct.new (blank) 0.001441 0.000091 0.001532 ( 0.001578)
Struct.new (args) 0.001368 0.000029 0.001397 ( 0.001442)
OpenStruct (assign) 0.000917 0.000086 0.001003 ( 0.001051)
Struct (assign) 0.000387 0.000012 0.000399 ( 0.000452)
OpenStruct (read) 0.000825 0.000019 0.000844 ( 0.000858)
Struct (read) 0.000358 0.000007 0.000365 ( 0.000367)
------------------------------------------------- total: 0.079642sec
user system total real
OpenStruct.new (args) 0.069159 0.000443 0.069602 ( 0.069667)
OpenStruct.new (blank) 0.001309 0.000060 0.001369 ( 0.001381)
Struct.new (args) 0.001212 0.000001 0.001213 ( 0.001211)
OpenStruct (assign) 0.000685 0.000005 0.000690 ( 0.000688)
Struct (assign) 0.000349 0.000001 0.000350 ( 0.000348)
OpenStruct (read) 0.000733 0.000002 0.000735 ( 0.000745)
Struct (read) 0.000305 0.000000 0.000305 ( 0.000305)
$ ruby --yjit benchmark_method_missing.rb
ruby 3.3.5 (2024-09-03 revision ef084cc8f4) +YJIT [arm64-darwin23]
times: 10000
Rehearsal -------------------------------------------------------------------------
OpenStruct.new (without args) 0.001591 0.000190 0.001781 ( 0.001780)
MethodMissingClass.new (without args) 0.000912 0.000011 0.000923 ( 0.000923)
OpenStruct (assign) 0.000753 0.000028 0.000781 ( 0.000781)
MethodMissingClass (assign) 0.003194 0.000066 0.003260 ( 0.003263)
OpenStruct (read) 0.000826 0.000021 0.000847 ( 0.000848)
MethodMissingClass (read) 0.002592 0.000057 0.002649 ( 0.002652)
---------------------------------------------------------------- total: 0.010241sec
user system total real
OpenStruct.new (without args) 0.001136 0.000023 0.001159 ( 0.001158)
MethodMissingClass.new (without args) 0.000699 0.000004 0.000703 ( 0.000702)
OpenStruct (assign) 0.000655 0.000001 0.000656 ( 0.000657)
MethodMissingClass (assign) 0.002662 0.000009 0.002671 ( 0.002674)
OpenStruct (read) 0.000727 0.000000 0.000727 ( 0.000727)
MethodMissingClass (read) 0.002228 0.000021 0.002249 ( 0.002248)