Hi,
I would like to apologize, but it looks like I had a technical problem in my 
measurements, and after double-checking it is indeed as all of you wrote: Perl 
does a very good optimization , and there is no real list creation involved.

Thank you all

Yossi

-----Original Message-----
From: Perl [mailto:perl-boun...@perl.org.il] On Behalf Of Shlomi Fish
Sent: Thursday, May 22, 2014 10:28 AM
To: Perl in Israel
Subject: Re: [Israel.pm] Perl performance optimization question

Hi Yossi,

On Thu, 22 May 2014 06:27:47 +0000
Yossi Itzkovich 
<yossi.itzkov...@ecitele.com<mailto:yossi.itzkov...@ecitele.com>> wrote:

> Hi,
>
> Here is a small test that shows the problem (memory consumption of
> counting the size of a huge hash, with not-so-small keys)
>
> -------
> my %hash;
> for (my $i=0; $i<5000000;$i++){
>         $hash{$i x 100}=$i};
> print "OK\n";
> sleep 20;  ###  Here the memory is about 3G print (scalar keys
> %hash,"\n");  sleep 10  ### here the memory is 3.5 G
> ------
>

With this program:

«
#!/usr/bin/perl

use strict;
use warnings;

my %hash;
for (my $i=0; $i<2000000;$i++)
{
        $hash{$i x 100}=$i;
};
print "OK\n";
my $l = <>;
print (scalar keys %hash,"\n");
print "Type enter to exit.\n";
$l = <>;

»

I don't see a noticeable increase in memory between the two stages. The memory
stays mostly the same at the time, according to htop. I tried with both
perl-5.18.2-4.mga5 and bleadperl on Mageia Linux x86-64 v5. What is your perl
version, the OS+distribution you are using, etc.?

Regards,

        Shlomi Fish

> Well, it means the list is being built, and it does consume a lot of memory
> (and CPU- but this is not my problem here).  In my real application it
> crashes, since I have bigger hash/keys, and I am getting "out of memory"
> crash.
>
> Isn't there a better way to get the hash size ?
>
> Yossi

--
-----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
Beginners Site for the Vim text editor - http://vim.begin-site.org/

When Chuck Norris disses your product, it’s not good publicity, even though
you can bet he’ll get the name right.
    — http://www.shlomifish.org/humour/bits/facts/Chuck-Norris/

Please reply to list if it's a mailing list post - http://shlom.in/reply .
_______________________________________________
Perl mailing list
Perl@perl.org.il<mailto:Perl@perl.org.il>
http://mail.perl.org.il/mailman/listinfo/perl

_______________________________________________
Perl mailing list
Perl@perl.org.il
http://mail.perl.org.il/mailman/listinfo/perl

Reply via email to