in reply to 30 Spaces- 1 question
use strict; use Benchmark qw(cmpthese); my @x; $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; # http://www.cpan.org/doc/manual/html/pod/perlfunc/index.html # # Well, that was no help... fricking http conventions # cmpthese (1000000, { 'regexp' => ' foreach (@x) { /^((?:\S+\s*){1,30})/; print $1; } ', 'split_join' => ' foreach (@x) { print join ( " ", (split " ", $_,31)[0..29] ); } ', 'for_index_substr' => ' foreach (@x) { my $ind = index ($_, " "); for (0..29) { last if $ind == -1; $ind = index $_, " ", $ind; } print substr($_,0,$ind); } ', } );
and now the results (basically, a huge fricking waste of time, we are talking a MILLION reps on p166 here.)
Rate split_join for_index_substr regexp
split_join 69061/s -- -7% -7%
for_index_substr 73910/s 7% -- -1%
regexp 74627/s 8% 1% --
### second run, no changes... hmmm....
Rate for_index_substr split_join regexp
for_index_substr 68027/s -- -9% -9%
split_join 74349/s 9% -- -0%
regexp 74516/s 10% 0% --
At those rates, any of those would likely be waiting on the harddrive to feed them data. My dataset is about 3.5kB so that means 232MB/s feedrate on the WORST run there and 255MB/s on the best. =) Do it anyway you want. Not going to matter, not one iota, in the long run.
--
$you = new YOU;
honk() if $you->love(perl)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
(dchetlin: Benchmark fixes) 30 Spaces- 1 question
by dchetlin (Friar) on Oct 10, 2000 at 06:40 UTC | |
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 | |
|
RE: Re: 30 Spaces- 1 question
by AgentM (Curate) on Oct 09, 2000 at 18:59 UTC |