Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Dominus's scratchpad

by Dominus (Parson)
on Jun 01, 2004 at 22:19 UTC ( #358683=scratchpad: print w/replies, xml ) Need Help??

use strict; use warnings; use Memoize; $| = 1; memoize('f_fenLisesi'); my $LARGE_N = shift || 300_000; for (\&f_fenLisesi, \&f_mjd, \&f_swampyankee) { print "7! = ", $_->(7), "\n"; } time_this( \&f_fenLisesi, 'fenLisesi' ); time_this( \&f_mjd, 'mjd' ); time_this( \&f_swampyankee, 'swampyankee'); exit( 0 ); #--------------------------------------------------+ sub time_this { my ($cref, $test_name) = @_; my $start = time(); print "testing $test_name: "; for (1 .. $LARGE_N) { $cref->( $_ ); } printf "%d second(s)\n", time() - $start; } #--------------------------------------------------+ sub f_swampyankee { my ($n) = @_; my $sum = 0; for my $i (1 .. $n) { $sum += $i; } $sum; } ##--------------------------------------------------+ sub f_fenLisesi { my ($n) = @_; return 1 if $n == 1; $n + f_fenLisesi( $n - 1 ); } ##--------------------------------------------------+ my @fact; BEGIN {@fact = (0)} sub f_mjd { my ($n) = @_; while ($#fact < $n) { push @fact, @fact + $fact[-1]; } return $fact[$n]; }
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (None)
    As of 2017-04-28 05:00 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      I'm a fool:











      Results (517 votes). Check out past polls.