From: bwv549 Date: 2007-04-04T02:05:03+09:00 Subject: Re: implementing an array based class > i'd love to see your tests using it. Thanks for the insight. I've included an arrayfields implementation on the above benchmark: Rehearsal -------------------------------------------------- ArrayFields 8.433333 0.800000 9.233333 ( 5.585626) Class1 5.566667 0.500000 6.066667 ( 3.631757) Class2 6.050000 0.550000 6.600000 ( 3.963679) Struct 3.583333 0.300000 3.883333 ( 2.335911) ArrayBased 2.033333 0.266667 2.300000 ( 1.381698) Array.new 1.950000 0.333333 2.283333 ( 1.371351) Array [] 0.833333 0.316667 1.150000 ( 0.689010) ---------------------------------------- total: 31.516667sec user system total real ArrayFields 8.516667 0.816667 9.333333 ( 5.609708) Class1 5.366667 0.650000 6.016667 ( 3.617349) Class2 5.933333 0.566667 6.500000 ( 3.893614) Struct 3.616667 0.266667 3.883333 ( 2.360849) ArrayBased 1.933333 0.316667 2.250000 ( 1.374079) Array.new 1.883333 0.333333 2.216667 ( 1.370410) Array [] 0.866667 0.283333 1.150000 ( 0.696223) Here's how I tested it (let me know if this is done incorrectly): require 'arrayfields' fields = %w(f1 f2 f3 f4 f5 f6 f7) bmbm(15) do |re| re.report("ArrayFields") { REP.times { x = [*attribute_array]; x.fields = fields } } ## .... same as before end I haven't tested the memory on it, but it would appear to be comparable to an Array (very low memory usage) from your implementation. It does have slightly higher overhead in the time required for creation (if I did it correctly). Nonetheless, arrayfields seems ideal for database work as you can simply label the fields without creating new classes for everything. In the particular case before me, I have only a handful of object types, but lots of them. Thanks, john