TimesToDo=1000 testString="" for i in 1..1000 testString += "abababdedfg" end Regex1 = Regexp::new("^(a|b|c|d|e|f|g)+$"); Regex2 = Regexp::new("^[a-g]+$"); startTime = Time.new.to_f for i in 1..TimesToDo Regex1.match(testString) end print "Alternation takes %.3f seconds\n" % (Time.new.to_f - startTime); startTime = Time.new.to_f for i in 1..TimesToDo Regex2.match(testString) end print "Character class takes %.3f seconds\n" % (Time.new.to_f - startTime); ----------------------------------------------------------------------------- Copyright 1997-2024 Jeffrey Friedl