Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save andreimerlescu/35ddb0eb1a1bb3236c416cdaafc4e1d5 to your computer and use it in GitHub Desktop.
Save andreimerlescu/35ddb0eb1a1bb3236c416cdaafc4e1d5 to your computer and use it in GitHub Desktop.
# ⇒ ruby string_find_test.rb
# Started 2020-01-02 15:20:04 -0500
# Ended 2020-01-02 15:20:05 -0500
# Speed 1.7854981422424316s
#
#
#
# Started 2020-01-02 15:20:05 -0500
# Ended 2020-01-02 15:20:09 -0500
# Speed 3.125840902328491s
start_time = Time.now
found = 0
(0..10000000).each do |i|
my_string = "abcdefg"
found += 1 if my_string.include? "cde"
end #/each
end_time = Time.now
puts "Started #{start_time}"
puts "Ended #{end_time}"
puts "Speed #{end_time.to_f - start_time.to_f}s"
puts ""
puts ""
puts ""
start_time = Time.now
found = 0
(0..10000000).each do |i|
found += 1 if 'aBcDe' =~ /bcd/i
end #/each
end_time = Time.now
puts "Started #{start_time}"
puts "Ended #{end_time}"
puts "Speed #{end_time.to_f - start_time.to_f}s"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment