From: "mame (Yusuke Endoh)" Date: 2012-03-21T23:35:40+09:00 Subject: [ruby-core:43537] [ruby-trunk - Bug #6183][Rejected] Enumerator::Lazy performance issue Issue #6183 has been updated by mame (Yusuke Endoh). Status changed from Open to Rejected Hello, Enumerator::Lazy is not a silver bullet; it removes the overhead for creating an intermediate array, but brings the drawback for calling a block. Unfortunately, the latter is much bigger than the former. Thus, in general, Lazy does bring performance drawback. The worth of Enumerator::Lazy is to extract first some elements from big array, especially, infinite sequence. For example: Prime.lazy.select {|x| x % 4 == 3 }.take(10).to_a The code becomes much complex without Lazy: a = [] Prime.each do |x| next if x % 4 != 3 a << x break if a.size == 10 end Anyway, this is not a bug. If you have any concrete idea to "fix" this issue, please reopen the ticket. Thank you, -- Yusuke Endoh ---------------------------------------- Bug #6183: Enumerator::Lazy performance issue https://bugs.ruby-lang.org/issues/6183#change-25017 Author: gregolsen (Innokenty Mikhailov) Status: Rejected Priority: Normal Assignee: Category: Target version: ruby -v: ruby 2.0.0dev (2012-03-17 trunk 35075) [x86_64-linux] I benchmarked Enumerator::Lazy and that's what I got: user system total real Lazy: 0.690000 0.010000 0.700000 ( 0.733160) Normal: 0.160000 0.010000 0.170000 ( 0.186695) It seems like even with 4 chain links and 3000 elements in initial array, Lazy enumerator is almost 4(!) times slower than the normal case. Instead of performance benefit we've got 4 times performance drawback. See test file attached. -- http://bugs.ruby-lang.org/