Created
June 7, 2016 20:35
-
-
Save justincampbell/4e5e78f6d6380527c0d2bc4b42bb86cb 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
ruby 2.2.1p85 (2015-02-26 revision 49769) [x86_64-darwin14] | |
user system total real | |
divide 0.070000 0.000000 0.070000 ( 0.069306) | |
gtlt 0.060000 0.000000 0.060000 ( 0.059579) | |
range_include 0.140000 0.000000 0.140000 ( 0.140579) | |
range_member 0.140000 0.000000 0.140000 ( 0.139238) | |
string_start_with 0.320000 0.010000 0.330000 ( 0.370943) | |
string_match 1.300000 0.020000 1.320000 ( 1.358586) |
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
puts RUBY_DESCRIPTION | |
require 'benchmark' | |
n = (ARGV[0] || 1_000_000).to_i | |
Benchmark.bm(18) do |bm| | |
bm.report :divide do | |
n.times { 250 / 100 == 2 } | |
end | |
bm.report :gtlt do | |
n.times { 250 >= 200 && 250 <= 299 } | |
end | |
bm.report :range_include do | |
range = (200..299) | |
n.times { range.include?(250) } | |
end | |
bm.report :range_member do | |
range = (200..299) | |
n.times { range.member?(250) } | |
end | |
bm.report :string_start_with do | |
two = '2'.freeze | |
n.times { 250.to_s.start_with?(two) } | |
end | |
bm.report :string_match do | |
regex = /^2/ | |
n.times { regex.match(250.to_s) } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment