Project

General

Profile

Bug #18144 » no_timeout.rb

duerst (Martin Dürst), 09/02/2021 06:44 AM

 
1
require 'timeout'
2

    
3
text   = '"a' * 80_000
4
re = "[\"']([^\"']+)[\"'].*END"
5
puts re.inspect
6
regexp = Regexp.compile(re)
7
match = nil
8
t1 = t2 = 0
9
begin
10
  Timeout::timeout(10) do
11
    t1 = Time.now
12
    match = text.match regexp
13
    t2 = Time.now
14
  end
15
  puts "match: #{!!match}, time: #{t2-t1}"
16
rescue Timeout::Error
17
  puts "timeout"
18
end
19