#! perl -slw use strict; use Time::HiRes qw( gettimeofday tv_interval ); my $re = ''; $re .="(?:(?:(.)(?:\\$_*))|\$)" for 1 .. 500; $re = qr/$re/o; my @chars = ( "A" .. "Z", "a" .. "z", 0 .. 9, qq( ),qw(! @ $ % ^ & *) ); for ( 0 .. 100 ) { my $max_size = int(rand(600)) + 2; my $stn = ""; $stn .= @chars[rand @chars] x int(rand(9)) for 1 .. $max_size; my $iterations = int(rand(600)) + 500; print 'STRING:', $stn; print 'Iterations: ', $iterations; print 'Length: ', length($stn); for my $sub ( qw/Enlil_2 Dingus_1 PhiRatE_2 Rasta_1 TommyW_1 Robartes_1 BrowserUk Dingus_2 Enlil_1/ ){ #! p_process_2/ ) { my $res; my $t0 = [gettimeofday]; for (1..$iterations) { no strict 'refs'; $res = &{$sub}($stn); } printf "%20s: %7.5f sec/iteration found:%3d\n", $sub, tv_interval( $t0 )/$iterations, scalar @$res; } } sub BrowserUk { $_ = shift; my @c = m/$re/; $#c = $#- -1; return \@c; } sub Enlil_1 { $_ = shift; my @bah; my $old_pos = 0; while ( /((.)\2*)/g ) { push @bah, [$2,$old_pos,length($1)]; $old_pos = pos(); } return \@bah; } sub Enlil_2 { $_ = shift; my @bah; while ( /((.)\2*)/g) { push (@bah, [$2,$-[1],$+[1] - $-[1]]); } return \@bah; } sub Dingus_1 { my $string = shift; my ($p, $c, $i, @res) = (0, substr($string,0,1)); for ($i=1; $i## Iterations: 936 Length: 875 Enlil_2: 0.00455 sec/iteration found:190 Dingus_1: 0.00340 sec/iteration found:190 PhiRatE_2: 0.00007 sec/iteration found: 3 Rasta_1: 0.00875 sec/iteration found:190 TommyW_1: 0.00397 sec/iteration found:190 Robartes_1: 0.00673 sec/iteration found:190 BrowserUk: 0.00301 sec/iteration found:190 Dingus_2: 0.00260 sec/iteration found:190 Enlil_1: 0.00260 sec/iteration found:190 Iterations: 602 Length: 1476 Enlil_2: 0.00795 sec/iteration found:330 Dingus_1: 0.00599 sec/iteration found:330 PhiRatE_2: 0.00118 sec/iteration found: 67 Rasta_1: 0.01551 sec/iteration found:330 TommyW_1: 0.00707 sec/iteration found:330 Robartes_1: 0.01159 sec/iteration found:330 BrowserUk: 0.00687 sec/iteration found:330 Dingus_2: 0.00452 sec/iteration found:330 Enlil_1: 0.00471 sec/iteration found:330 Iterations: 1067 Length: 70 Enlil_2: 0.00035 sec/iteration found: 14 Dingus_1: 0.00028 sec/iteration found: 14 PhiRatE_2: 0.00026 sec/iteration found: 14 Rasta_1: 0.00067 sec/iteration found: 14 TommyW_1: 0.00029 sec/iteration found: 14 Robartes_1: 0.00049 sec/iteration found: 14 BrowserUk: 0.00056 sec/iteration found: 14 Dingus_2: 0.00021 sec/iteration found: 14 Enlil_1: 0.00023 sec/iteration found: 14 Iterations: 995 Length: 363 Enlil_2: 0.00182 sec/iteration found: 75 Dingus_1: 0.00140 sec/iteration found: 75 PhiRatE_2: 0.00136 sec/iteration found: 75 Rasta_1: 0.00352 sec/iteration found: 75 TommyW_1: 0.00156 sec/iteration found: 75 Robartes_1: 0.00277 sec/iteration found: 75 BrowserUk: 0.00123 sec/iteration found: 75 Dingus_2: 0.00107 sec/iteration found: 75 Enlil_1: 0.00105 sec/iteration found: 75