Skip to content

Instantly share code, notes, and snippets.

@filipebarcos
Created March 14, 2015 01:05
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 filipebarcos/6bc81b4d6afdef070b55 to your computer and use it in GitHub Desktop.
Save filipebarcos/6bc81b4d6afdef070b55 to your computer and use it in GitHub Desktop.
require 'benchmark/ips'
Benchmark.ips do |x|
x.report("with lazy") do
(1..1_000_000).lazy
.select(&:odd?)
.map(&:to_s)
.take(1000)
end
x.report("without lazy") do
(1..1_000_000).select(&:odd?)
.map(&:to_s)
.take(1000)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment