by swerling · 8y ago · 0 comments
I'm not sure if this is in the spirit of the test, but using regex reduced the time from 27s to 0.04s on my machine.
require 'benchmark'
contents = File.read("/tmp/200mb.txt")
find = "07123E1F482356C415F684407A3B8723E10B2CBBC0B8FCD6282C49D37C9C1ABC"
result = nil
elapsed = Benchmark.realtime do
result = (contents =~ /#{find}/)
end
puts "Found at index #{result} in #{elapsed}s"
(The search string was placed at the end of a 200mb file)