Last active
August 29, 2015 13:56
-
-
Save fbernier/9231807 to your computer and use it in GitHub Desktop.
Revisions
-
fbernier revised this gist
Feb 26, 2014 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,8 @@ # 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. # This benchmark is purposely made to advantage the lazy version, without much success. require 'benchmark/ips' class Enumerator::Lazy -
fbernier revised this gist
Feb 26, 2014 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ # 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' -
fbernier revised this gist
Feb 26, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ # Enumerator#lazy is quite slow and should only be used when iterating over large collections # where you need few results and you know you are going to get them quite early in the iteration. require 'benchmark/ips' -
fbernier revised this gist
Feb 26, 2014 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,5 @@ # Enumerator#lazy is quite slow and should only be used when iterating over large collections where you need few results and you know you are going to get them quite early in the iteration. require 'benchmark/ips' -
fbernier revised this gist
Feb 26, 2014 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,5 @@ # Enumerator#lazy is quite slow and should only be used when iterating over large collections where you need few results and you know you are going to get them quite early in the iteration. require 'benchmark/ips' class Enumerator::Lazy -
fbernier revised this gist
Feb 26, 2014 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -22,4 +22,6 @@ def filter_map Calculating ------------------------------------- map+compact 12035 i/100ms filter_map 10588 i/100ms ------------------------------------------------- map+compact 135411.8 (±0.9%) i/s - 685995 in 5.066383s filter_map 114386.4 (±4.9%) i/s - 571752 in 5.010041s -
fbernier created this gist
Feb 26, 2014 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,25 @@ require 'benchmark/ips' class Enumerator::Lazy def filter_map Lazy.new(self) do |yielder, *values| result = yield *values yielder << result if result end end end Benchmark.ips do |r| r.report("map+compact") do (0..50).map{|a| 'lol' if a.even?}.compact.first(5) end r.report("filter_map") do (0..50).lazy.filter_map{|a| 'lol' if a.even?}.first(5) end end Calculating ------------------------------------- map+compact 12035 i/100ms filter_map 10588 i/100ms -------------------------------------------------