Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Garbage collection at subroutine return

by izut (Chaplain)
on Feb 15, 2007 at 14:51 UTC ( [id://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.

    Anno

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (2)
As of 2024-04-26 01:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found