use Data::Dumper; use Time::HiRes qw( usleep ualarm gettimeofday tv_interval ); use re 'eval'; $stn = "aaaaaaammm38fdkkkkkkkk3,,,,,,,,,,sad909999999994lklllllllllllllz,,,,,,,,,dd888888882jk2kkd8d888d8djkjkjkjkkk3kk4k5kkkk65"; $iterations = 500; for (1..4) { $stn.=$stn; } print "Iterations: $iterations\n";~ print "Length: ".length($stn)."\n"; # Enlil 2 $t0 = [gettimeofday]; for (1..$iterations) { @res = enlil_2($stn); } print "Enlil 2: ".tv_interval( $t0 )."\n"; # Dingus 1 $t0 = [gettimeofday]; for (1..$iterations) { @res = dingus_1($stn); } print "Dingus 1: ".tv_interval( $t0 )."\n"; # Rasta 1 $t0 = [gettimeofday]; for (1..$iterations) { @res = rasta_1($stn); } print "Rasta 1: ".tv_interval( $t0 )."\n"; # TommyW 1 $t0 = [gettimeofday]; for (1..$iterations) { @res = tommyw_1($stn); } print "TommyW 1: ".tv_interval( $t0 )."\n"; # Robartes 1 $t0 = [gettimeofday]; for (1..$iterations) { @res = robartes_1($stn); } print "Robartes 1: ".tv_interval( $t0 )."\n"; # PhiRatE 1 $t0 = [gettimeofday]; for (1..$iterations) { @res = p_process($stn); } print "PhiRatE 1: ".tv_interval( $t0 )."\n"; # BrowserUk $t0 = [gettimeofday]; #! Set up big regex. 1-time hit. my $re ='(?:(.)(??{"$+*"}))?' x 500; $re = qr/$re/o; for (1..$iterations) { @res = browseruk($stn); } print "BrowserUk: ".tv_interval( $t0 )."\n"; # Dingus 2 $t0 = [gettimeofday]; for (1..$iterations) { @res = dingus_2($stn); } print "Dingus 2: ".tv_interval( $t0 )."\n"; # PhiRatE 2 $t0 = [gettimeofday]; for (1..$iterations) { @res = phirate_2($stn); } print "PhiRatE 2: ".tv_interval( $t0 )."\n"; # PhiRatE 3 $t0 = [gettimeofday]; for (1..$iterations) { @res = p_process_2($stn); } print "PhiRatE 3: ".tv_interval( $t0 )."\n"; sub browseruk { $_ = shift; my @c = m/$re/; #! THIS LINE DOES ALL THE WORK. #! This truncates the list to exclude null matches returned from regex. $#c = $#- -1; return \@c; } sub enlil_2 { my $string = shift; my @bah; while ($string =~ /((.)\2*)/g) { push (@bah, [$2,$-[1],$+[1] - $-[1]]); } return \@bah; } sub dingus_1 { my $string = shift; my (@res, $c, $p, $i); $p = 0; $c = substr($string,$p,1); for ($i=1; $i <<'END_OF_C_CODE'; void p_process(char *s) { char prev = 0; long count = 0; long pos = 0; long i=0; AV *array; Inline_Stack_Vars; Inline_Stack_Reset; while((*s != 0) || (prev != 0)) { if (count==0) { pos = i; prev = *s; count = 1; } else if (prev == *s) { count++; } else { array = newAV(); av_push(array,newSVpvn(&prev,1)); av_push(array,newSViv(pos)); av_push(array,newSViv(count)); Inline_Stack_Push(newRV_inc(array)); pos=i; prev = *s; count=1; } i++; s++; } Inline_Stack_Done; } void p_process_2(char *s) { char prev = 0; long count = 0; long i=0; AV *array; Inline_Stack_Vars; Inline_Stack_Reset; prev = *s; while((*s != 0) || (prev != 0)) { if (prev == *s) { count++; } else { array = newAV(); av_push(array,newSVpvn(&prev,1)); av_push(array,newSViv(i-count)); av_push(array,newSViv(count)); Inline_Stack_Push(newRV_inc(array)); prev = *s; count=1; } i++; s++; } Inline_Stack_Done; } END_OF_C_CODE