http://qs321.pair.com?node_id=665486


in reply to Re^4: Sorting keys of hash table by values
in thread Sorting keys of hash table by values

2000 and 5000 keys, 1000 and 3000 iterations.

Code:

srand 0; my @letters = split //, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRS +TUVWXYZ'; sub rnd_string{ my $string; for( 1 .. (5 + int rand 10)){ $string .= $letters[ rand @letters ]; } #say $string; return $string; } my %hash; for(1 .. 5_000){ $hash{rnd_string()} = rand; } my @sorted_keys; for(1..3_000){ #@sorted_keys = sort { $hash{$b} <=> $hash{$a} } keys %hash; @sorted_keys = reverse sort { $hash{$a} <=> $hash{$b} } keys %hash +; #@sorted_keys = sort { -( $hash{$a} <=> $hash{$b} ) } keys %hash; } say scalar @sorted_keys;