I am afraid, I have different stats with my study:

I ran for 100,000 loops and for 1,000,000 loops but yet, the map,grep
contexts are giving me efficient stats than the foreach loop stuff. Since
our comparing contexts differ, there might be significant difference between
the two approaches, I guess. Else, how can you attribute the difference in
stats?

Here is my code:

use Benchmark;
open(INP,">t.txt");

my $expressiveCode = sub {
                                                        $hash{'jmj'} =
['john','doe','laura','george','bill','nelson'];
                                                        for $ele (
@{$hash{'jmj'}} )
                                                        {
                                                                if( $ele eq
'george' )
                                                                {
        
print INP "Take working Vacation Bud!\n";
                                                                }
                                                        }
                                                 };
my $idiomaticCode = sub{#Mode Idiomatic Way and is more efficient too!
                                                map { print INP "Take
working vacation bud\n"; }
                                                grep{$_ eq 'george'}
                                                @{$hash{'jmj'}};
                                                };
close(INP);
timethis(1000000, $expressiveCode);
timethis(1000000, $idiomaticCode);


Please refer attachment for the stats(small file).

-- Rex
-----Original Message-----
From: Luke Bakken [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, August 07, 2001 4:57 PM
To: [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]; [EMAIL PROTECTED]
Subject: RE: Hashes with multiple values per key


<<attachment: Perl.jpg>>

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to