Last active
November 15, 2018 09:53
-
-
Save kenchan/b93764eb62f90fe8b884c605cf567f31 to your computer and use it in GitHub Desktop.
Float::INFINITYってrangeに使うとどうなんだっけ?
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
require 'benchmark/ips' | |
Benchmark.ips do |x| | |
x.report("2..50") { | |
case rand(50) | |
when 1 | |
1 | |
when 2..50 | |
50 | |
else | |
nil | |
end | |
} | |
x.report("2..Float::INFINITY") { | |
case rand(50) | |
when 1 | |
1 | |
when 2..Float::INFINITY | |
50 | |
else | |
nil | |
end | |
} | |
x.compare! | |
end |
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
$ ruby inifity_benchmark.rb | |
Warming up -------------------------------------- | |
2..50 152.772k i/100ms | |
2..Float::INFINITY 116.007k i/100ms | |
Calculating ------------------------------------- | |
2..50 2.604M (± 7.8%) i/s - 12.986M in 5.026051s | |
2..Float::INFINITY 1.799M (±21.1%) i/s - 8.120M in 5.042590s | |
Comparison: | |
2..50: 2603906.8 i/s | |
2..Float::INFINITY: 1798800.0 i/s - 1.45x slower | |
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
$ ruby inifity_benchmark.rb | |
Warming up -------------------------------------- | |
2..50 171.891k i/100ms | |
2..Float::INFINITY 135.066k i/100ms | |
Calculating ------------------------------------- | |
2..50 3.259M (± 8.7%) i/s - 16.330M in 5.058189s | |
2..Float::INFINITY 2.290M (± 7.5%) i/s - 11.481M in 5.047540s | |
Comparison: | |
2..50: 3259256.3 i/s | |
2..Float::INFINITY: 2289511.3 i/s - 1.42x slower |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment