Is this comparison valid?

Discussion in 'Perl Misc' started by gamo@telecable.es, Jun 9, 2013.

  1. Guest

    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__
     
    , Jun 9, 2013
    #1
    1. Advertising

  2. wrote:
    >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
     
    Jürgen Exner, Jun 9, 2013
    #2
    1. Advertising

  3. Guest

    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.
     
    , Jun 9, 2013
    #3
  4. wrote:
    >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
     
    Jürgen Exner, Jun 9, 2013
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. LV

    .Net Comparison

    LV, Aug 27, 2003, in forum: ASP .Net
    Replies:
    4
    Views:
    1,418
    William Ryan
    Aug 31, 2003
  2. bettervssremoting
    Replies:
    0
    Views:
    1,873
    bettervssremoting
    Mar 1, 2005
  3. Anand P Paralkar
    Replies:
    2
    Views:
    9,510
    Srinivasan Venkataramanan
    Aug 4, 2003
  4. Deepu
    Replies:
    1
    Views:
    261
    ccc31807
    Feb 7, 2011
  5. Replies:
    0
    Views:
    144
Loading...

Share This Page