Skip to content

Instantly share code, notes, and snippets.

@dongyemeng
Created October 23, 2012 18:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dongyemeng/3940780 to your computer and use it in GitHub Desktop.
Save dongyemeng/3940780 to your computer and use it in GitHub Desktop.
Test the performance of perl on regex
use Benchmark;
#start timer
for ( $j = 1 ; $j <= 100*1000 ; $j = $j * 10 ) {
print "# of Iteration:", $j, "\n";
#test cases
$str1 =
"a ligament (e.g. <i>Distichodus</i>, Vari, 1979, fig. 42 )or sheath of connective tissue (e.g. <i>Hoplias</i> )connected to the medial face of the maxilla, and permitting considerable freedom of movement to the posterior end of the maxilla";
$str2 =
", Vari, 1979, fig. 42 )or sheath of connective tissue (e.g. <i>Hoplias</i> )connected to the medial face of the maxilla, and permitting considerable freedom of movement to the posterior end of the maxilla";
$str3 =
" )connected to the medial face of the maxilla, and permitting considerable freedom of movement to the posterior end of the maxilla";
$str4 =
"ectopterygoid inserted on the ventral surface of the area near the vomer-rnesethmoid articulation (hypothesized fusion in <i>Hepsetus odoe</i> )by means of a ligament attached to a socket or bony facet";
$str5 = " )by means of a ligament attached to a socket or bony facet";
$t0 = Benchmark->new;
#run the test cases for a given # of iterations
for ( $i = 0 ; $i < $j ; $i++ ) {
$str1 =~ /(.*?)<i>\s*([^<]*)\s*<\/i>(.*)/;
$str2 =~ /(.*?)<i>\s*([^<]*)\s*<\/i>(.*)/;
$str3 =~ /(.*?)<i>\s*([^<]*)\s*<\/i>(.*)/;
$str4 =~ /(.*?)<i>\s*([^<]*)\s*<\/i>(.*)/;
$str5 =~ /(.*?)<i>\s*([^<]*)\s*<\/i>(.*)/;
}
#end timer
$t1 = Benchmark->new;
#print out time
$td = timediff( $t1, $t0 );
print "Time is:", timestr($td), "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment