From: Robert Brown <[EMAIL PROTECTED]>
> Casey West writes:
>  > : "Does the regular expression mechanism in perl optimize regular >
>  : expressions such as the one you used earlier in this thread so that
>  > : the execution overhead is nearly as good as the C approach I
>  outlined > : earlier in this thread?  In other words, for the problem
>  stated > : earlier, does o(C) = o(perl)?  > > The answer is, C almost
>  always going to be much faster almost all the > time, YMMV.  Really
>  the only way to tell is with tests and benchmarks, > but you can
>  almost always bet on C.
> 
> Sorry again for my confusing way of expressing myself.  Although I
> wrote my example in C, that was because I am a novice perl programmer,
> but an experienced C programmer, so I expressed my algorithm in C.
> 
> The idea was to compare the execution effeciency of a perl regular
> expression approach to a less syntacticly compact algorithmic approach
> using loops and conditionals, still written in perl, to edit the
> string.  I just used C so you all would not beat me up over perl
> syntax details instead of answering the real question.
> 
> Is perl going to be comparably efficient whichever way you code it, or
> is the explicit test and loop approach usually going to be faster for
> simple jobs?  I want to know when to use the regex approach and when
> not to.

1. Perl builtins and especialy the regular expression engine is 
heavily optimized. So it might very well be quicker to use a regexp 
from Perl than to implement the same stuff in C. Unless you spend a 
lot of time tweaking the code.

2. One regexp (assuming its created well) will almost always be 
quicker than several loops and ifs in Perl.

While you should not use a regexp where the "normal" functions 
suffice, you should not go into great lengths implementing something 
that would be simple as a regexp. It'll be harder to maintain and 
most probably slower.

3. If you really need to know which solution is quicker
        use Benchmark;
 

Jenda
===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
        -- Terry Pratchett in Sourcery


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to