Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
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 the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (9)
As of 2015-07-02 02:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (25 votes), past polls