Last active
April 27, 2018 14:43
-
-
Save jdfrens/338b1129507d8a255af14bf99c546b0e to your computer and use it in GitHub Desktop.
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 characters
require 'benchmark' | |
foo = [[8, nil], [8, 99]] * 10_000_000 | |
Benchmark.bm(7) do |x| | |
x.report("to_i") do | |
foo.each { |(a, b)| [a, b.to_i].max } | |
end | |
x.report("compact") do | |
foo.each { |(a, b)| [a, b].compact.max } | |
end | |
end |
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 characters
Ruby 2.2.7: | |
user system total real | |
to_i 7.890000 0.020000 7.910000 ( 7.916156) | |
compact 7.870000 0.010000 7.880000 ( 7.890511) | |
Ruby 2.4.2: | |
user system total real | |
to_i 2.120000 0.000000 2.120000 ( 2.132754) | |
compact 3.930000 0.010000 3.940000 ( 3.937682) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Looks like some good stuff coming with 2.6...
... for the sake of comparison: https://gist.github.com/peterwmwong/bc1b6bd56f613134b5bfb2d2962c39ae