Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re^5: Performance, Abstraction and HOP

by runrig (Abbot)
on Sep 14, 2005 at 22:21 UTC ( #492064=note: print w/replies, xml ) Need Help??

in reply to Re^4: Performance, Abstraction and HOP
in thread Performance, Abstraction and HOP

I'm not sure that a memory hogging recursive function makes for a fair benchmark of function calling speed (even if the tail recursion could be optimized away in another language -- and if the tail recursion could be optimized away, you wouldn't be calling the function anymore, you'd just be doing a goto). I think this version of is more fair (which attempts to test the speed of function calling rather than memory allocation):
#!/usr/bin/perl #sum of number between 1 and 1,000,000 $n = 1_000_000; my $t = 0; $t = addup( $t, $n-- ) while $n; print "$t\n"; sub addup { $_[0] + $_[1]; }
and then the two come out closer:
$ time ./ 500000500000 real 0m5.68s user 0m5.48s sys 0m0.02s $ time ./ 500000500000 real 0m1.48s user 0m1.47s sys 0m0.01s

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://492064]
[1nickt]: $it = path("/foo")-> iterator(recurse => 1 );

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (13)
As of 2017-03-28 18:54 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (340 votes). Check out past polls.