author | cu |
Tue, 03 Oct 2017 23:35:16 +0100 | |
changeset 513 | 676e6484f29b |
parent 474 | 4bdf0dedd708 |
child 558 | 447ed6c7cdad |
permissions | -rw-r--r-- |
420
25bc57b32efa
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
411
diff
changeset
|
1 |
# example provided by Daniel Baldwin |
58 | 2 |
|
226
e3c454e31224
updated so that it works with more recent versions of Ruby
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
121
diff
changeset
|
3 |
nums = (1..1000) |
57 | 4 |
|
474 | 5 |
#iterate through the nums 1-1000 |
57 | 6 |
nums.each do |i| |
7 |
||
8 |
start_time = Time.now |
|
9 |
string = "a" * i |
|
474 | 10 |
|
11 |
#create a new regular expression based on current value of i |
|
226
e3c454e31224
updated so that it works with more recent versions of Ruby
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
121
diff
changeset
|
12 |
re_str = "a?" * i + "+" + "a" * i |
e3c454e31224
updated so that it works with more recent versions of Ruby
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
121
diff
changeset
|
13 |
re = Regexp.new(re_str) |
57 | 14 |
|
60 | 15 |
re.match(string) |
474 | 16 |
|
17 |
#if re.match(string) |
|
60 | 18 |
# puts "matched string a * #{i} with regex #{re}" |
19 |
#else |
|
20 |
# puts "unmatched string a * #{i} with regex #{re}" |
|
21 |
#end |
|
57 | 22 |
|
60 | 23 |
puts "#{i} %.5f" % (Time.now - start_time) |
57 | 24 |
end |