Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

You learn something every day

by Jasper (Chaplain)
on Aug 01, 2003 at 13:36 UTC ( #279954=perlmeditation: print w/ replies, xml ) Need Help??

Looking over my cow-orker's shoulder today, and criticising (those who can't do, teach!) I was pointing out to him that:
{ local $" = '|'; $good = $file =~ /^(@patterns)$/; }
is around thirty times faster than
for my $pattern (@patterns) { $good = 1, last if $file =~ /^$pattern$/ }
But he did have something curious in there, and (now to my point) I learned that  (?i:foo) does a case-insensitive non-remembering pattern match. I can't imagine if I'll ever use it, but I thought it was cute.

Has anyone else learned anything interesting today?

Jasper

Comment on You learn something every day
Select or Download Code
Re: You learn something every day
by nimdokk (Vicar) on Aug 01, 2003 at 14:00 UTC
    Well, I haven't learned anything today (yet), but the other day I learned that I really did know how to set up PGP to do a decrypt of a file. Now, if we can just get it to run properly in Windows from an unattached batch script.... :-)


    "Ex libris un peut de tout"
Re: You learn something every day
by Anonymous Monk on Aug 01, 2003 at 14:43 UTC

    Well, I discovered that if I put the following in my code:

    our $tom = "a big worthless poopyhead";

    and a guy named Tom who just so happens to be on the same development team as myself decides to look over said code in an attempt to understand what the sub that follows the declaration does, then he may become somewhat upset.

    I wonder what lesson tomorrow holds for me :-/

      Kyle?

Re: You learn something every day
by diotalevi (Canon) on Aug 01, 2003 at 15:02 UTC

    Its just a lickalized /i flag. So instead /i applying to your entire regex you apply it only to the parts it needs to be. Its a nice thing and I use it a lot.

Re: You learn something every day
by sauoq (Abbot) on Aug 02, 2003 at 00:28 UTC
    Has anyone else learned anything interesting today?

    No, but maybe you'll help me out on that score...

    You said,

    "Looking over my cow-orker's shoulder today"
    and that got me to wondering:
    • Just how do you "ork" a cow?
    • It isn't illegal, is it?
    • Can you get a degree in cow-orking? (That would have to be a B.S. I guess.)
    • How do you pay your cow-orker? Is he salaried? Hourly? Or do you pay by the cow?

    :-)

    -sauoq
    "My two cents aren't worth a dime.";
    

      You mean you've never orked?

      Been there, done that. I even have the T-shirt & cap :))


      Examine what is said, not who speaks.
      "Efficiency is intelligent laziness." -David Dunham
      "When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller
      If I understand your problem, I can solve it! Of course, the same can be said for you.

        What will they invent next? You can't even make a typing error or someone has made it into a web-site and starts merchandising it!

        CountZero

        "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

      Orkers of the world, unite! You have only your cows to lose!
Re: You learn something every day
by demerphq (Chancellor) on Aug 04, 2003 at 13:19 UTC

    is around thirty times faster

    Actually this dependent on the size of @patterns. When I benchmark them against each other i get more like a 100% speedup. Precalculating a hash of the patterns and then doing a hash lookup is infinitely faster.

    Testing 100 Benchmark: running bigrex, forex, hash, each for at least 1 CPU second +s... bigrex: 1 wallclock secs ( 1.09 usr + 0.02 sys = 1.11 CPU) @ 19 +103.70/s (n=21186) forex: 1 wallclock secs ( 1.11 usr + 0.00 sys = 1.11 CPU) @ 44 +43.24/s (n=4932) hash: 2 wallclock secs ( 1.14 usr + 0.00 sys = 1.14 CPU) @ 16 +32288.34/s (n=1862441) Rate forex bigrex hash forex 4443/s -- -77% -100% bigrex 19104/s 330% -- -99% hash 1632288/s 36636% 8444% -- Testing 10000 Benchmark: running bigrex, forex, hash, each for at least 1 CPU second +s... bigrex: 1 wallclock secs ( 1.06 usr + 0.00 sys = 1.06 CPU) @ 83 +.80/s (n=89) forex: 2 wallclock secs ( 1.03 usr + 0.00 sys = 1.03 CPU) @ 42 +.68/s (n=44) hash: 1 wallclock secs ( 1.05 usr + 0.00 sys = 1.05 CPU) @ 13 +97043.89/s (n=1464102) Rate forex bigrex hash forex 42.7/s -- -49% -100% bigrex 83.8/s 96% -- -100% hash 1397044/s 3273428% 1666934% -- Testing 100000 Benchmark: running bigrex, forex, hash, each for at least 1 CPU second +s... bigrex: 1 wallclock secs ( 1.08 usr + 0.00 sys = 1.08 CPU) @ 7 +.42/s (n=8) forex: 2 wallclock secs ( 1.17 usr + 0.00 sys = 1.17 CPU) @ 4 +.27/s (n=5) hash: 2 wallclock secs ( 1.03 usr + 0.00 sys = 1.03 CPU) @ 12 +19285.16/s (n=1257083) Rate forex bigrex hash forex 4.27/s -- -43% -100% bigrex 7.42/s 74% -- -100% hash 1219285/s 28579944% 16429768% --

    So id say you learned something new today too. :-) (use a hash...)


    ---
    demerphq

    <Elian> And I do take a kind of perverse pleasure in having an OO assembly language...
      aha, but @patterns didn't contain just strings, it was full of all sort of regular expression trickery. Show me a hash lookup that'll work for that!

      Jasp

      Also, just in case anyone thought cow-orker really was a type, don't you read Dilbert?

        The use of /^(...)$/ lead me to believe it was simply strings. If @patterns is fully regexes then why not build the final regex only once with qr//?


        ---
        demerphq

        <Elian> And I do take a kind of perverse pleasure in having an OO assembly language...
Re: You learn something every day
by Juerd (Abbot) on Aug 05, 2003 at 07:46 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://279954]
Approved by broquaint
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2014-07-13 01:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (244 votes), past polls