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

Re^2: Check even numbers?

by BrowserUk (Patriarch)
on Aug 07, 2006 at 08:25 UTC ( [id://565904]=note: print w/replies, xml ) Need Help??


in reply to Re: Check even numbers?
in thread Check even numbers?

I assume you are aware, (and it probably should be mentioned), that the referenced method is (I assume), a joke along the same lines as the included method of finding tomorrow's date:

sub tomorrow_date { sleep 86_400; return localtime(); }

Without all the compile-time reductions, lazy evaluation etc. that most properly functional languages benefit from, this method of determining the eveness of a number is ludicrously inefficient--6000+ times slower than the normal method:

#! perl -slw use strict; use Benchmark qw[ cmpthese ]; no warnings 'recursion'; sub odd { my $number = shift; return !even ($number); } sub even { my $number = abs shift; return 1 if $number == 0; return od +d ($number - 1); } cmpthese -5, { normal => q[ my $n; $_ & 1 and $n++ for 1 .. 1000; ], functional => q[ my $n; even( $_ ) and $n++ for 1 .. 1000; ], }; __END__ c:\test>junk s/iter functional normal functional 1.50 -- -100% normal 2.41e-004 625042% --

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://565904]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (2)
As of 2025-01-17 04:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which URL do you most often use to access this site?












    Results (55 votes). Check out past polls.