Created
October 23, 2012 18:53
-
-
Save dongyemeng/3940780 to your computer and use it in GitHub Desktop.
Test the performance of perl on regex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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