1_000 def primes(range) range .reject {|number| number < 50 } .select(&:prime?) .first(10) end Benchmark.bmbm do |x| x.report("with lazy") do cycles.times { primes(range.lazy) } end x.report("without lazy") do cycles.times { primes(range) } end end
lazy 4.740000 0.390000 5.130000 ( 5.219114) --------------------------------------- total: 5.400000sec user system total real with lazy 0.260000 0.020000 0.280000 ( 0.280212) without lazy 5.090000 0.420000 5.510000 ( 5.576948)