Created
August 15, 2016 09:40
-
-
Save dskecse/d929d5fa1274eaa70e636f19c8ca74c1 to your computer and use it in GitHub Desktop.
ruby 2.3.1
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' | |
n = 5_000_000 | |
Benchmark.bmbm do |x| | |
x.report('String#match') do | |
n.times do | |
'metadata:foo=bar'.match(/metadata:/) | |
end | |
end | |
x.report('String#=~') do | |
n.times do | |
'metadata:foo=bar' =~ /metadata:/ | |
end | |
end | |
x.report('String#start_with?') do | |
n.times do | |
'metadata:foo=bar'.start_with? 'metadata:' | |
end | |
end | |
end | |
# Rehearsal ------------------------------------------------------ | |
# String#match 5.010000 0.010000 5.020000 ( 5.031097) | |
# String#=~ 1.460000 0.000000 1.460000 ( 1.461489) | |
# String#start_with? 0.680000 0.000000 0.680000 ( 0.694000) | |
# --------------------------------------------- total: 7.160000sec | |
# user system total real | |
# String#match 4.960000 0.010000 4.970000 ( 4.975006) | |
# String#=~ 1.420000 0.000000 1.420000 ( 1.423937) | |
# String#start_with? 0.640000 0.000000 0.640000 ( 0.641189) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment