#!/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. time_start = Time::now 10000.times do s1 =~ /\[\[(([A-Z]\w*)\.)?(.*)(#([A-Z]\w*))?\](\[(.*)\])?\]/ s2 =~ /\[\[(([A-Z]\w*)\.)?(.*)(#([A-Z]\w*))?\](\[(.*)\])?\]/ s3 =~ /\[\[(([A-Z]\w*)\.)?(.*)(#([A-Z]\w*))?\](\[(.*)\])?\]/ s4 =~ /\[\[(([A-Z]\w*)\.)?(.*)(#([A-Z]\w*))?\](\[(.*)\])?\]/ s5 =~ /\[\[(([A-Z]\w*)\.)?(.*)(#([A-Z]\w*))?\](\[(.*)\])?\]/ end puts (Time::now - time_start).to_s puts $&