Re: efficiency of hash of hashes/lists

2005-05-24 Thread Dave Gray
> > # access test for 2d
> > ($su, $ss) = times;
> > for my $i (0 .. $hashsize-1) {
> > $oned{$l1[$i]}{$l2[$i]}++
> 
> I think you should be operating on %twod here.

LOL, thanks. Original poster take note:

generating hashes..!
base  0.03  0.00   0.03
  1D  0.24  0.00   0.24
  2D  0.22  0.00   0.22

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




Re: efficiency of hash of hashes/lists

2005-05-24 Thread Paul Johnson
On Tue, May 24, 2005 at 02:13:49PM -0400, Dave Gray wrote:

> On 5/23/05, Peter Rabbitson <[EMAIL PROTECTED]> wrote:
> > On Mon, May 23, 2005 at 01:40:08PM -0400, Zhenhai Duan wrote:
> > > I tried hash (where the members of a group are joined with ":"), and hash
> > > of hash. It happended that hash of hash is slower than single hash.
> > >
> > > Hash:
> > > $groups{$g1} = "$member1:$member2";
> > >
> > > Hash of hash
> > > $groups{$g1}{$member1} = 1;
> > >
> > > Method 1 is faster, even I need to do a split to get the members.
> > 
> > Can you post some code? Without it the above statement is not very credible
> > to say the least.
> 
> The 1D approach seems to be approximately 3 times as fast (on x86
> Linux). Anyone get different results?
> 
> #!/usr/bin/perl
> use strict;
> use warnings;
> 
> my @ra = ('a' .. 'z', 'A' .. 'Z');
> my ($seqlen, $hashsize) = (4, 7);
> 
> my (%oned, %twod) = ((),());
> my (@l1, @l2) = ((),());
> 
> $|++;
> print "generating hashes";
> for my $i (1 .. $hashsize) {
> my $key1 = join('', @ra[map(int(rand($#ra))+1, 1 .. $seqlen)]);
> push @l1, $key1;
> my $key2 = join('', @ra[map(int(rand($#ra))+1, 1 .. $seqlen)]);
> push @l2, $key2;
> $oned{"$key1:$key2"}++;
> $twod{$key1}{$key2}++;
> print '.' if not $i % int($hashsize/10);
> }
> print "!\n";
> 
> # baseline
> my ($su, $ss) = times;
> for (1 .. $hashsize) { }
> my ($eu, $es) = times;
> my ($tu, $ts) = ($eu - $su, $es - $ss);
> my $tt = $tu + $ts;
> printf "%20s %5.2f %5.2f %6.2f\n", 'base', $tu, $ts, $tt;
> 
> # access test for 1d
> ($su, $ss) = times;
> for my $i (0 .. $hashsize-1) {
> $oned{"$l1[$i]:$l2[$i]"}++
> }
> ($eu, $es) = times;
> ($tu, $ts) = ($eu - $su, $es - $ss);
> $tt = $tu + $ts;
> printf "%20s %5.2f %5.2f %6.2f\n", '1D', $tu, $ts, $tt;
> 
> # access test for 2d
> ($su, $ss) = times;
> for my $i (0 .. $hashsize-1) {
> $oned{$l1[$i]}{$l2[$i]}++

I think you should be operating on %twod here.

> }
> ($eu, $es) = times;
> ($tu, $ts) = ($eu - $su, $es - $ss);
> $tt = $tu + $ts;
> printf "%20s %5.2f %5.2f %6.2f\n", '2D', $tu, $ts, $tt;

But your real gains will come when you want to do something which does
not require iterating through all the elements you have created.

-- 
Paul Johnson - [EMAIL PROTECTED]
http://www.pjcj.net

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




Re: efficiency of hash of hashes/lists

2005-05-24 Thread Philip M. Gollucci

Dave Gray wrote:


On 5/23/05, Peter Rabbitson <[EMAIL PROTECTED]> wrote:
 


On Mon, May 23, 2005 at 01:40:08PM -0400, Zhenhai Duan wrote:
   


I tried hash (where the members of a group are joined with ":"), and hash
of hash. It happended that hash of hash is slower than single hash.

Hash:
$groups{$g1} = "$member1:$member2";

Hash of hash
$groups{$g1}{$member1} = 1;

Method 1 is faster, even I need to do a split to get the members.
 


Can you post some code? Without it the above statement is not very credible
to say the least.
   



The 1D approach seems to be approximately 3 times as fast (on x86
Linux). Anyone get different results?
 


FreeBSD 6.x-current w/ perl5.9.3 and ithreads.

[ttyp0] [EMAIL PROTECTED] /usr/home/pgollucci rv=0 26 >perl test.pl
generating hashes..!
   base  0.02  0.00   0.02
 1D  0.14  0.00   0.14



--
END 
-

   What doesn't kill us, can only make us stronger.
  Nothing is impossible.

Philip M. Gollucci ([EMAIL PROTECTED]) 301.254.5198
Consultant / http://p6m7g8.net/Resume/resume.shtml
Senior Developer / Liquidity Services, Inc.  
http://www.liquidityservicesinc.com



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




Re: efficiency of hash of hashes/lists

2005-05-24 Thread Dave Gray
On 5/23/05, Peter Rabbitson <[EMAIL PROTECTED]> wrote:
> On Mon, May 23, 2005 at 01:40:08PM -0400, Zhenhai Duan wrote:
> > I tried hash (where the members of a group are joined with ":"), and hash
> > of hash. It happended that hash of hash is slower than single hash.
> >
> > Hash:
> > $groups{$g1} = "$member1:$member2";
> >
> > Hash of hash
> > $groups{$g1}{$member1} = 1;
> >
> > Method 1 is faster, even I need to do a split to get the members.
> 
> Can you post some code? Without it the above statement is not very credible
> to say the least.

The 1D approach seems to be approximately 3 times as fast (on x86
Linux). Anyone get different results?

#!/usr/bin/perl
use strict;
use warnings;

my @ra = ('a' .. 'z', 'A' .. 'Z');
my ($seqlen, $hashsize) = (4, 7);

my (%oned, %twod) = ((),());
my (@l1, @l2) = ((),());

$|++;
print "generating hashes";
for my $i (1 .. $hashsize) {
my $key1 = join('', @ra[map(int(rand($#ra))+1, 1 .. $seqlen)]);
push @l1, $key1;
my $key2 = join('', @ra[map(int(rand($#ra))+1, 1 .. $seqlen)]);
push @l2, $key2;
$oned{"$key1:$key2"}++;
$twod{$key1}{$key2}++;
print '.' if not $i % int($hashsize/10);
}
print "!\n";

# baseline
my ($su, $ss) = times;
for (1 .. $hashsize) { }
my ($eu, $es) = times;
my ($tu, $ts) = ($eu - $su, $es - $ss);
my $tt = $tu + $ts;
printf "%20s %5.2f %5.2f %6.2f\n", 'base', $tu, $ts, $tt;

# access test for 1d
($su, $ss) = times;
for my $i (0 .. $hashsize-1) {
$oned{"$l1[$i]:$l2[$i]"}++
}
($eu, $es) = times;
($tu, $ts) = ($eu - $su, $es - $ss);
$tt = $tu + $ts;
printf "%20s %5.2f %5.2f %6.2f\n", '1D', $tu, $ts, $tt;

# access test for 2d
($su, $ss) = times;
for my $i (0 .. $hashsize-1) {
$oned{$l1[$i]}{$l2[$i]}++
}
($eu, $es) = times;
($tu, $ts) = ($eu - $su, $es - $ss);
$tt = $tu + $ts;
printf "%20s %5.2f %5.2f %6.2f\n", '2D', $tu, $ts, $tt;

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




Re: efficiency of hash of hashes/lists

2005-05-23 Thread Peter Rabbitson
On Mon, May 23, 2005 at 01:40:08PM -0400, Zhenhai Duan wrote:
> I tried hash (where the members of a group are joined with ":"), and hash 
> of hash. It happended that hash of hash is slower than single hash.
> 
> Hash:
> $groups{$g1} = "$member1:$member2";
> 
> 
> Hash of hash
> $groups{$g1}{$member1} = 1;
> 
> Method 1 is faster, even I need to do a split to get the members.


Can you post some code? Without it the above statement is not very credible 
to say the least.

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




Re: efficiency of hash of hashes/lists

2005-05-23 Thread Zhenhai Duan
I tried hash (where the members of a group are joined with ":"), and hash 
of hash. It happended that hash of hash is slower than single hash.


Hash:
$groups{$g1} = "$member1:$member2";


Hash of hash
$groups{$g1}{$member1} = 1;

Method 1 is faster, even I need to do a split to get the members.
 -Zhenhai

Zhenhai Duan 
Assistant Professor 
Department of Computer Science 
Florida State University 
Tallahassee, FL 32306-4530


Phone: (850) 645-1561
Fax:   (850) 644-0058
Email: [EMAIL PROTECTED]
URL:   http://www.cs.fsu.edu/~duan
=

On Sun, 22 May 2005, Jeff 'japhy' Pinyan wrote:


On May 22, Zhenhai Duan said:

I am wondering if the performance (time efficiency) of hash of hash is bad. 
I has this impression from the code I developed. Basically my structure 
needs to hold the members of different groups. I have different choices:


hash of hash
$groups{$g1}{$member1} = 1;
but this one is really slow from what i see.


How have you seen this to be slow?

--
Jeff "japhy" Pinyan %  How can we ever be the sold short or
RPI Acacia Brother #734 %  the cheated, we who for every service
http://japhy.perlmonk.org/  %  have long ago been overpaid?
http://www.perlmonks.org/   %-- Meister Eckhart



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




RE: efficiency of hash of hashes/lists

2005-05-22 Thread Charles K. Clarkson
Zhenhai Duan  wrote:

: Can anyone give me some suggestions which one is better?

Whichever is easiest to read is probably the better solution.
Unless you are dealing with a finished program where you need
additional speed, let readability be your guide.


HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328


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




Re: efficiency of hash of hashes/lists

2005-05-22 Thread Jeff 'japhy' Pinyan

On May 22, Zhenhai Duan said:

I am wondering if the performance (time efficiency) of hash of hash is bad. I 
has this impression from the code I developed. Basically my structure needs to 
hold the members of different groups. I have different choices:


hash of hash
$groups{$g1}{$member1} = 1;
but this one is really slow from what i see.


How have you seen this to be slow?

--
Jeff "japhy" Pinyan %  How can we ever be the sold short or
RPI Acacia Brother #734 %  the cheated, we who for every service
http://japhy.perlmonk.org/  %  have long ago been overpaid?
http://www.perlmonks.org/   %-- Meister Eckhart

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




efficiency of hash of hashes/lists

2005-05-22 Thread Zhenhai Duan

Hi,

I am wondering if the performance (time efficiency) of hash 
of hash is bad. I has this impression from the code I developed. Basically 
my structure needs to hold the members of different groups. I have 
different choices:


hash:
$groups{$g1} = "$member1:$member2:$member3...";
but everytime I need the members of a group, I need to do a split, and 
when I need to check if a member is in a group, I need to do a loop.


hash of hash
$groups{$g1}{$member1} = 1;
but this one is really slow from what i see.

hash of lists
$groups{$g1} = ($member1, $member2, ...);
I need a loop for checking if a member is in a group.

another hash
$groups{$g1:$member1} = 1;

Can anyone give me some suggestions which one is better? Many thanks,
 -Zhenhai

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