Skip to content

Instantly share code, notes, and snippets.

@ptzn
Last active December 13, 2015 18:08
Show Gist options
  • Save ptzn/4953463 to your computer and use it in GitHub Desktop.
Save ptzn/4953463 to your computer and use it in GitHub Desktop.
search_for = '46846'
value = '00000'
stats = []
search_for.size.times do |index|
stats[index] ||= []
10.times do |digit|
value[index] = digit.to_s
puts "checking #{value}"
start_time = Time.now
10_000_000.times { search_for == value }
running_time = Time.now - start_time
stats[index] << { running_time: running_time, digit: digit}
puts "For #{digit} at #{index}: #{running_time}"
end
# setting slowest
value[index] = stats[index].sort { |stat1, stat2| stat1[:running_time] <=> stat2[:running_time] }.last[:digit].to_s
end
puts "Is it #{value}?"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment