Re: There's no LIMIT to my SPLITting headache.
- From: Dave <dave@xxxxxxxxxx>
- Date: Sat, 11 Jun 2005 21:32:06 -0400
Mark Seger wrote:
> The most enlightening experience I've had with perl was discovering that:
>
> statement if $a=~/aaa|bbb|ccc/
>
> is a LOT slower than
>
> statement if $a=~/aaa/ || $a=~/bbb/ || $a=~/ccc/
>
> by a factor of about 7, at least when I checked it out on both a 3.5GHz
> Xeon and a 1.5GHz Intanium 2. The moral to the story is nothing beats a
> few simple tests.
Not by a long shot on my machine, running Perl 5.8.7.
=code
use Benchmark qw(:hireswallclock cmpthese);
my $pat = 'A Perl Paaattern';
my $match = 0;
cmpthese(0, {
'Code1' => '$match = 1 if $pat =~/aaa/ || $pat=~/bbb/ || $pat=~/ccc/',
'Code2' => '$match = 1 if $pat =~/aaa|bbb|ccc/',
});
=cut
Time::HiRes is compiled on my machine.
Granted, that's a *very* simple pattern, but the shorter code came out
ahead 5/5 times by a wide margin.
___________________________
Rate Code1 Code2
___________________________
Code1 2775928/s -- -62%
Code2 7368521/s 165% --
___________________________
Code1 2888905/s -- -63%
Code2 7777375/s 169% --
___________________________
Code2 2647141/s -- -64%
Code1 7289831/s 175% --
___________________________
Code1 2742926/s -- -62%
Code2 7313196/s 167% --
___________________________
Code1 2803761/s -- -61%
Code2 7211258/s 157% --
---------------------------
Or if I set $pat to a string of the output from 'perldoc Time::HiRes'
Code1 2657898/s -- -70%
Code2 8771367/s 230% --
Dave
.
- Follow-Ups:
- Re: There's no LIMIT to my SPLITting headache.
- From: Mark Seger
- Re: There's no LIMIT to my SPLITting headache.
- From: Mark Seger
- Re: There's no LIMIT to my SPLITting headache.
- From: Mark Seger
- Re: There's no LIMIT to my SPLITting headache.
- From: use63net
- Re: There's no LIMIT to my SPLITting headache.
- From: Sisyphus
- Re: There's no LIMIT to my SPLITting headache.
- References:
- There's no LIMIT to my SPLITting headache.
- From: use63net
- Re: There's no LIMIT to my SPLITting headache.
- From: Brian Wakem
- Re: There's no LIMIT to my SPLITting headache.
- From: Mark Seger
- There's no LIMIT to my SPLITting headache.
- Prev by Date: Re: Slice returned hash or access to its elements without assigning to a variable
- Next by Date: Re: Mail::DomainKeys example needed
- Previous by thread: Re: There's no LIMIT to my SPLITting headache.
- Next by thread: Re: There's no LIMIT to my SPLITting headache.
- Index(es):
Relevant Pages
|
|