#!/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 tries to speed up the RE search by first looking to see if the first # character of the string matches the first character of the RE (i.e., is a # match even possible. # "-" is ASCII 45 s1 = "This is a test." s2 = "Wednesday is another day." s3 = "---*** A Possible Heading" time_start = Time::now 10000.times do if s1[0] == 45 then /\A---\*{3}/ =~ s1 end if s2[0] == 45 then /\A---\*{3}/ =~ s2 end if s3[0] == 45 then /\A---\*{3}/ =~ s3 end end puts (Time::now - time_start).to_s