#!/usr/bin/env ruby # This is one of several little programs to attempt to test the speed of # various means of using an RE to search a string. # This is the default case, which simply checks the string using the RE. # "[" is ASCII 91 s1 = "This is a test." s2 = "Wednesday is another day." s3 = "---*** A Possible Heading" s4 = " * A possible list item" s5 = "A long string with a link hidden within, in other words, [[Web.WikiHome][a link]]." # The following RE is not exactly correct, but I think it will serve for test purposes. # Similar to re_test6.rb, but (1) not finished, and (2) intending to use a # destructive slice instead of a substring approach. At the moment, I can't # imagine this is faster than re_test6.rb, and that is so much slower than the # pure RE approach, I'm not going to pursue this. time_start = Time::now 10000.times do for i in (0..s1.length-6) do if s1[0] == 91 s1 =~ /\A\[\[(([A-Z]\w*)\.)?(.*)(#([A-Z]\w*))?\](\[(.*)\])?\]/ else s1.slice!(0) end end x=1 if x==0 puts "True" puts "Wednesday" else puts "False" puts "Wednesday" end end puts (Time::now - time_start).to_s puts $&