in reply to Re^2: Simple Matching
in thread Simple Matching
It's only getting compiled once, just as if it was outside of eval, so what's the problem?
If you wanted to reuse the counter, make a sub if it:
$counters{$_} = eval "sub { \$_[0] =~ tr/\Q$_\E// }";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Simple Matching
by rnroot (Initiate) on Sep 28, 2009 at 06:11 UTC | |
| [reply] [d/l] |
by AnomalousMonk (Archbishop) on Sep 28, 2009 at 12:42 UTC | |
Update: Might be faster if possessive: 5.10 has possessive modifier: Bugfix: Changed (?> [^$suits])+ to (?> [^$suits]+) per ikegami Re^6: Simple Matching. | [reply] [d/l] [select] |
by ikegami (Patriarch) on Sep 28, 2009 at 15:53 UTC | |
Captures are slow, so it would be faster to build a regex without captures I also generalised some of the matching. Input validation is not a goal here.
Or maybe even built it manually here, but it can be built dynamically. Update: That last regex pattern gives me an idea:
Of course, if the input format was a number, it would be even faster:
| [reply] [d/l] [select] |
by BrowserUk (Patriarch) on Sep 29, 2009 at 00:54 UTC | |
It is a simple fact of life that if you can hard code a lookup table, it will be faster than building it on-the-fly, or choosing one conditionally. If you need best possible speed--and that is a big if--then the choice to store 10,000 lookup tables is a speed -v- memory trade-off that you might choose to make. If youreally need absolute best speed, then C or assembler are your only choices. But the surprising thing about Perl--the redeeming feature for all it faults--is that it rarely make you make that choice. Beyond the realms of either highly algorithmically complex; or no-alternative, cpu intensive--Perl's quirks, irregularities and non-orthogonality's are tailored--by experience and practice, over orthodoxy and dogma--to produce best possible results in best possible time..... with the proviso--and it is a big one--that you are not afraid to consider perfectionism, passe; correctness. contrived; elitism, irrelevant; and practicality paramount. Beyond the rarefied atmospheres of academic and dogmatic perfection, code that works for the common case. today; is far preferable to either perfection tomorrow. Strive for perfection; but don't exclude a solution today, for perfection tomorrow. Tomorrow rarely (I'm pragmatic; "never" is not a part of my vocabulary :) ever comes. Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
| [reply] |