-
-
Save phildionne/9232896 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Enumerator#lazy is very slow and should only be used when iterating over large/infinite collections | |
# where you know you are going to get your results quite early in the iteration. | |
require 'benchmark/ips' | |
Benchmark.ips do |r| | |
r.report("map") do | |
(0..50).map{ |i| 'lol' if i.even? } | |
end | |
r.report("lazy+map") do | |
(0..50).lazy.map { |i| 'lol' if i.even? }.to_a | |
end | |
end | |
Calculating ------------------------------------- | |
map 7726 i/100ms | |
lazy+map 2451 i/100ms | |
------------------------------------------------- | |
map 87178.8 (±2.6%) i/s - 440382 in 5.055076s | |
lazy+map 27059.9 (±2.7%) i/s - 137256 in 5.076049s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment