Skip to content

Instantly share code, notes, and snippets.

@taq
Created November 3, 2012 19:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save taq/4008465 to your computer and use it in GitHub Desktop.
Save taq/4008465 to your computer and use it in GitHub Desktop.
Ruby 2.0 lazy enumerators bigger collection performance
require "benchmark"
include Benchmark
values = (0..1000).to_a
bm(10) do |bench|
bench.report("regular") do
values.map { |x| x * 10 }.select { |x| x > 30 }
end
bench.report("lazy") do
values.lazy.map { |x| x * 10 }.select { |x| x > 30 }
end
end
# user system total real
# regular 0.000000 0.000000 0.000000 ( 0.000229)
# lazy 0.000000 0.000000 0.000000 ( 0.000018)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment