Is this comparison valid?

G

gamo

I have installed 5.18, and think that if hashes are randomized, maybe
a simple hash could substitute the shuffle operations, but I'm not sure
if the comparison is valid.

#!/usr/local/bin/perl -w

use List::Util qw(shuffle);
use Benchmark qw:)all);

for (1..100_000){
$list[$_] = $_;
$hash{$_} = $_;
}

cmpthese(-3, {
'shuffle' => sub { @aleat=shuffle(@list); },
'newhash' => sub { @aleat=values(%hash); },
});
timethese(-3, {
'shuffle' => sub { @aleat=shuffle(@list); },
'newhash' => sub { @aleat=values(%hash); },
});




__END__
 
J

Jürgen Exner

I have installed 5.18, and think that if hashes are randomized,

Where did you read that hashes are randomized? AFAIK the sequence is
deterministic although of no practical value (and therefore may appear
to be randomized to the casual observer).

jue
 
G

gamo

Where did you read that hashes are randomized? AFAIK the sequence is
deterministic although of no practical value (and therefore may appear
to be randomized to the casual observer).

jue
-------------------

in perldelta

it says:

Hash randomization

The seed used by Perl's hash function is now random. This means that
the order which keys/values will be returned from functions like
"keys()", "values()", and "each()" will differ from run to run.
 
J

Jürgen Exner

Where did you read that hashes are randomized? AFAIK the sequence is
deterministic although of no practical value (and therefore may appear
to be randomized to the casual observer).

jue
-------------------

in perldelta

it says:

Hash randomization

The seed used by Perl's hash function is now random. This means that
the order which keys/values will be returned from functions like
"keys()", "values()", and "each()" will differ from run to run.


Interesting.

Thanks

jue
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top