use strict; use Time::HiRes 'time'; #TimesToDo, TestString, Regex sub test { my $TimesToDo = shift; my $TestString = shift() x 1000; my $Count = $TimesToDo; my $StartTime = time(); while ($Count-- > 0) { $TestString =~m/^$_[2]+$/; } my $EndTime = time(); return $EndTime - $StartTime; } sub main { my $result = test(1000,"abababdedfg","(a|b|c|d|e|f|g)"); printf("Alternation takes %.3f seconds.\n", $result); $result = test(1000,"abababdedfg","[a-g]"); printf("Character class %.3f seconds.\n", $result); } unless (caller) {main ()}