Beefy Boxes and Bandwidth Generously Provided by pair Networks Frank
Syntactic Confectionary Delight
 
PerlMonks

Re: Re: Anyone use "xor" in conditionals?

by BrowserUk (Apostle)
 | Log in | Create a new user | The Monastery Gates | Super Search | 
 | Seekers of Perl Wisdom | Meditations | PerlMonks Discussion | 
 | Obfuscation | Reviews | Cool Uses For Perl | Perl News | Q&A | Tutorials | 
 | Poetry | Recent Threads | Newest Nodes | Donate | What's New | 

on Jul 15, 2003 at 01:15 UTC ( #274247=note: print w/ replies, xml ) Need Help??

in reply to Re: Anyone use "xor" in conditionals?
in thread Anyone use "xor" in conditionals?

Ah! But if it is out and out speeed we are after then I might have offered :)

sub buk2 { $_[0] % 4 ? 0 : $_[0] % 100 ? 1 : not $_[0] % 400; } Rate browseruk isleap abigail buk2 browseruk 82.8/s -- -40% -54% -67% isleap 138/s 67% -- -24% -45% abigail 180/s 118% 31% -- -28% buk2 251/s 203% 82% 39% --

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



Comment on Re: Re: Anyone use "xor" in conditionals?
Download Code
Re3: Anyone use "xor" in conditionals?
by dragonchild (Archbishop) on Jul 15, 2003 at 02:17 UTC
    And why haven't you offered this as a patch to Date::Leapyear or any of the other Date:: modules? Hmmm?!? Or, even better, offer both the pureperl and XS versions ...

    In other words, it's through these incremental improvements that modules are made as strong as they can be. That kind of code is exactly the code that belongs in modules. They're supposed to fast, commented, and full of black magic. That's why modules exist!

    ------
    We are the carpenters and bricklayers of the Information Age.

    Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

    Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.

      Mostly cos I'd never even considered looking at, never mind using a module to determine whether a year was a leapyear or not.

      I only looked up Date::Leapyear in order to find a representative example of "the conventional way". I was only responding to the question about xor, and never gave a thought to the performance until Abigail-II (rightly) posted the benchmark.

      From there, I couldn't not rise to the challenge could I :).


      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


        ++ BrowserUK for thinking like i do. :) how about this little gem from Net::Netmask...

               sort_by_ip_address       This function is included in "Net::Netmask"
                                        simply because there doesn't seem to be a bet-
                                        ter place to put it on CPAN.  It turns out
                                        that there is one method for sorting dotted-
                                        quads ("a.b.c.d") that is faster than all the
                                        rest.  This is that way.  Use it as
                                        "sort_by_ip_address(@list_of_ips)".
        
        sub sort_by_ip_address { return sort { pack("C4",split(/\./,$a)) cmp pack("C4",split(/\./,$ +b)) } @_ }

        which has to be about the worst possible.

Re: Anyone use "xor" in conditionals?
by Abigail-II (Bishop) on Jul 15, 2003 at 07:05 UTC
    I wasn't looking for the fastest solution to this particular problem. My 'solution' looked similar to the one from the Date module on purpose. I wanted to show the effect of changing the order, so I used the same style which would make it more obvious what the effect is.

    Nested ?: is of course faster than repeated statement modifiers.

    Abigail

    PS: Could you fix your sig? It doesn't seem to close its font element - replying in a textform with fontsize = 1 is very annoying.

      Hopefully, my sig. is now fixed.


      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

Login:
Password
remember me
What's my password?
Create A New User

Node Status?
node history
Node Type: note [id://274247]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (24)
Corion
GrandFather
Fletch
shmem
jdporter
Your Mother
holli
atcroft
kennethk
scorpio17
MidLifeXis
thezip
Eyck
pileofrogs
clinton
ssandv
hbm
goeb
rubasov
flamey
MikeDexter
smile4me
im2
ienh
As of 2010-02-09 20:31 GMT
Sections?
The Monastery Gates
Seekers of Perl Wisdom
Meditations
PerlMonks Discussion
Categorized Q&A
Tutorials
Obfuscated Code
Perl Poetry
Cool Uses for Perl
Perl News
Information?
PerlMonks FAQ
Guide to the Monastery
What's New at PerlMonks
Voting/Experience System
Tutorials
Reviews
Library
Perl FAQs
Other Info Sources
Find Nodes?
Nodes You Wrote
Super Search
List Nodes By Users
Newest Nodes
Recently Active Threads
Selected Best Nodes
Best Nodes
Worst Nodes
Saints in our Book
Leftovers?
The St. Larry Wall Shrine
Offering Plate
Awards
Craft
Snippets Section
Code Catacombs
Quests
Editor Requests
Buy PerlMonks Gear
PerlMonks Merchandise
Planet Perl
Perlsphere
Use Perl
Perl.com
Perl 5 Wiki
Perl Jobs
Perl Mongers
Perl Directory
Perl documentation
CPAN
Random Node
Voting Booth?

What level of existential comfort do you require?

Palace
Executive suite at the best hotel
Regular hotel in a decent part of town
Motel
Boarding house
Sleeping Bag on Couch in Basement
Any port in a storm
Camping under the freeway overpass
Jail
Other

Results (279 votes), past polls