From: William Morgan Date: 2005-03-11T02:25:12+09:00 Subject: Re: Is iterating in lock-step possible? Excerpts from William Morgan's mail of 10 Mar 2005 (EST): > I see about a factor of ten slow-down in the following toy example. Um that would be, 1000. Not ten. 1000. In the following experiments I see factors of anywhere between 200 and 950, so three orders of magnitude seems reasonable. ruby -rgenerator -rbenchmark -e 'Benchmark.bm(7) do |b| (14 .. 19).each do |level| size = 2 ** level a = (0 ... size).to_a g = Generator.new a b.report("arr #{level}") { a.each { |x| x } } b.report("gen #{level}") { while g.next?; g.next; end } end end' arr 14 0.010000 0.000000 0.010000 ( 0.007526) gen 14 2.280000 0.600000 2.880000 ( 2.912238) arr 15 0.010000 0.000000 0.010000 ( 0.017132) gen 15 5.270000 0.030000 5.300000 ( 5.302015) arr 16 0.040000 0.000000 0.040000 ( 0.030965) gen 16 11.520000 0.660000 12.180000 ( 12.204337) arr 17 0.040000 0.000000 0.040000 ( 0.044533) gen 17 25.030000 3.370000 28.400000 ( 28.563181) arr 18 0.070000 0.000000 0.070000 ( 0.070832) gen 18 61.730000 0.500000 62.230000 ( 62.321825) arr 19 0.150000 0.000000 0.150000 ( 0.151578) gen 19 142.200000 10.050000 152.250000 (159.363150) Looks kinda super-linear. Anyways, just entertaining myself. -- William