#!/usr/bin/perl use Benchmark qw(timethese cmpthese ); my %step3list = ( icate => 'ic', ative => '', alize => 'al', iciti => 'ic', ical => 'ic', ful => '', ness => '', foo => 'bar' ); my @step3list_reg = keys %step3list; my @step3list_sex = map $_=reverse, (keys %step3list); my @step4list =qw( al able ance ant ate ence ent ement er ible ic ism iti ive ize ment ou ous boo ); my @step4list_sex = map $_=reverse, @step4list; sub COUNT (){ 100_000 } #sub COUNT (){ 1 } my $ta = timethese (COUNT, { regexes_4p0s1 => sub { my $match; foreach (@step4list){ #print "$_: "; #if (($match) = /^ if (/^ ( a (?: ble | n(?:ce|t) | te | l ) | e (?: ment | n(?:ce|t) | r ) | i (?: ble | sm | ti | ve | ze | c ) | ment | ous? ) $/x) { #print "matches expected set using regexes. $match:$`|$&|$+|$'\n"; } else { #print "doesn't match expected set using regexes.\n"; } } }, sexeger_4p0s1 => sub { my $match; foreach (@step4list_sex){ #print "$_: "; #if (($match) = /^ if (/^ #4p0s1r: # No performance gains matching in reverse ( (?: elb | (?:ec|t)n | et | l ) a | (?: tnem | (?:ec|t)n | r ) e | (?: elb | ms | it | ev | ez | c ) i | tnem | s?uo ) $/x) { #$match = reverse $match; #print "matches expected set using sexeger. $match:$`|$&|$+|$'\n"; } else { #print "doesn't match expected set using sexeger.\n"; } } }, sexeger_4p1s1 => sub { my $match; foreach (@step4list_sex){ #print "$_: "; #if (($match) = /^ if (/^ #4p1s1r: # However, this has significant performance gains ( (?: e(?:lb|cn|t) | tn | l ) a | (?: tnem | (?:ec|t)n | r ) e | (?: e(?:lb|[vz]) | it | ms | c ) i | tnem | s?uo ) $/x) { #$match = reverse $match; #print "matches expected set using sexeger. $match:$`|$&|$+|$'\n"; } else { #print "doesn't match expected set using sexeger.\n"; } } }, }); cmpthese($ta); my $tb = timethese (COUNT, { regexes_3p0s1 => sub { my $match; foreach (@step3list_reg){ #print "$_: "; #if (($match) = /^ if (/^ #3p0s1: # Less optimal #( (?: (?: icat | ativ | aliz ) e | iciti | (?: ica | fu ) l | ness ) $/x) { #$match = $1; #print "matches expected set using regexes. $match:$`|$&|$+|$'\n"; } else { #print "doesn't match expected set using regexes.\n"; } } }, sexeger_3p1s0 => sub { my $match; #foreach (@step3list_reg){ foreach (@step3list_sex){ #print "$_: "; #if (reverse=~/^ #if (($match) = /^ if (/^ #3p1s0r: # More optimal - performance gains in reverse #( (?: e (?: taci | vita | zila ) | itici | l (?: aci | uf ) | ssen ) $/x) { #$match = $1; #$match = reverse $1; #$match = reverse $match; #print "matches expected set using sexeger. $match:$`|$&|$+|$'\n"; } else { #print "doesn't match expected set using sexeger.\n"; } } } }); cmpthese($tb); __END__ =head1 NAME sextest.pl - Test Sexeger performance =head1 DESCRIPTION An example script to test various sexeger performance attributes. =head1 AUTHOR "darksym" :) =head1 Benchmark Example Ouput Benchmark: timing 100000 iterations of regexes_4p0s1, sexeger_4p0s1, sexeger_4p1 s1... regexes_4p0s1: 23 wallclock secs (18.66 usr + 0.01 sys = 18.66 CPU) @ 5357.89/s (n=100000) sexeger_4p0s1: 33 wallclock secs (26.89 usr + 0.03 sys = 26.92 CPU) @ 3714.45/s (n=100000) sexeger_4p1s1: 29 wallclock secs (24.48 usr + 0.02 sys = 24.49 CPU) @ 4082.93/s (n=100000) Rate sexeger_4p0s1 sexeger_4p1s1 regexes_4p0s1 sexeger_4p0s1 3714/s -- -9% -31% sexeger_4p1s1 4083/s 10% -- -24% regexes_4p0s1 5358/s 44% 31% -- Benchmark: timing 100000 iterations of regexes_3p0s1, sexeger_3p1s0... regexes_3p0s1: 8 wallclock secs ( 7.10 usr + 0.00 sys = 7.10 CPU) @ 14081.41/ s (n=100000) sexeger_3p1s0: 6 wallclock secs ( 6.26 usr + -0.01 sys = 6.25 CPU) @ 16000.00/ s (n=100000) Rate regexes_3p0s1 sexeger_3p1s0 regexes_3p0s1 14081/s -- -12% sexeger_3p1s0 16000/s 14% -- =cut