When should I use Struct vs. OpenStruct?

后端 未结 9 1152
孤城傲影
孤城傲影 2020-11-28 00:35

In general, what are the advantages and disadvantages of using an OpenStruct as compared to a Struct? What type of general use-cases would fit each of these?

9条回答
  •  無奈伤痛
    2020-11-28 01:18

    Using @Robert code, I add Hashie::Mash to the benchmark item and got this result:

                               user     system      total        real
    Hashie::Mash slow      3.600000   0.000000   3.600000 (  3.755142)
    Hashie::Mash fast      3.000000   0.000000   3.000000 (  3.318067)
    OpenStruct slow       11.200000   0.010000  11.210000 ( 12.095004)
    OpenStruct fast       10.900000   0.000000  10.900000 ( 12.669553)
    Struct slow            0.370000   0.000000   0.370000 (  0.470550)
    Struct fast            0.140000   0.000000   0.140000 (  0.145161)
    

提交回复
热议问题