Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Re: Garbage collection at subroutine return

by izut (Chaplain)
on Feb 15, 2007 at 14:51 UTC ( #600213=note: print w/replies, xml ) Need Help??

in reply to Garbage collection at subroutine return

I have nothing to add to liverpole's suggestion, but the way you're doing your benchmark test. There's a Benchmark module available, which is really easy to use. If you write a benchmark code with it once, you'll never write a time calculation again. It is useful to compare results too.

Here is a code that compares liverpole's suggestion and the way you tried it first:

use strict; use warnings; use Benchmark qw(:all); my $limit = 1_000; sub do_it_tcarmeli { my %do_it_tcarmeli; foreach my $i ( 0 .. $limit ) { $do_it_tcarmeli{$i} = 1; } return; } my %do_it_liverpole; sub do_it_liverpole { foreach my $i ( 0 .. $limit ) { $do_it_liverpole{$i} = 1; } return; } cmpthese( -10, { do_it_tcarmeli => \&do_it_tcarmeli, do_it_liverpole => \&do_it_liverpole, } );

Igor 'izut' Sutton
your code, your rules.

Replies are listed 'Best First'.
Re^2: Garbage collection at subroutine return
by Anno (Deacon) on Feb 15, 2007 at 19:32 UTC
    Ah, but you're measuring the total run time of the subs. That's probably going to swamp out the effect of garbage collection on return. tcarmeli took care to measure only the return time. Benchmark doesn't give much support for that kind of timing.

    Oh, and "code" (in the sense of program text) is a mass noun and doesn't take an indefinite article.


Log In?

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (8)
As of 2021-03-02 21:50 GMT
Find Nodes?
    Voting Booth?
    My favorite kind of desktop background is:

    Results (64 votes). Check out past polls.