in reply to Re: 30 Spaces- 1 question
in thread 30 Spaces- 1 question
Also, and more minorly, your for_index_substr routine isn't working -- $_ is being re-aliased on the second for loop and the actual target string is being lost.
I took the liberty of making a couple of changes and re-running:
use strict; use Benchmark qw(cmpthese); my @x; my @result; $x[0]= "mark " x 35; $x[1]= "asdfasdfasdfasdfasdf " x 35; $x[2]= "as " x 31; $x[3]= "asdfasdfasdfasdfasdfasdf " x 100; $x[4]= "asdfasdfasdfasdfasdfasdf " x 10; cmpthese (-5, { 'regexp' => sub { my $i; foreach (@x) { /^((?:\S+\s*){1,30})/; $result[$i++]{REx} = $1; } }, 'split_join' => sub { my $i; foreach (@x) { $result[$i++]{split} = join " ", (split " ", $_,31)[0..29]; } }, 'for_index_substr' => sub { my $i; foreach (@x) { my $ind = index ($_, " "); for my $foo (0..28) { last if $ind == -1; $ind = index $_, " ", $ind + 1; } $result[$i++]{index} = substr($_,0,$ind); } }, } ); for (@result) { print "bad!" unless ($_{REx} eq $_{split} and $_{split} eq $_{index}); }
This produces:
Rate split_join for_index_substr regexp split_join 4294/s -- -7% -27% for_index_substr 4618/s 8% -- -21% regexp 5849/s 36% 27% --
-dlc
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: (dchetlin: Benchmark fixes) 30 Spaces- 1 question
by extremely (Priest) on Oct 10, 2000 at 08:29 UTC | |
by dchetlin (Friar) on Oct 10, 2000 at 08:34 UTC | |
by extremely (Priest) on Oct 10, 2000 at 08:39 UTC |