in reply to Re: Rosetta Code: Long List is Long (Updated Solutions)
in thread Rosetta Code: Long List is Long
Some wiser monk might correct me, but I think this difference is because "simple" blocks can be internally optimized
(edited: typoes corrected after reading the replies)
my @sorted = sort @unsorted; my @sorted = sort { $a <=> $b } @unsorted; my @sorted = sort { $a cmp $b } @unsorted;
Are all internally optimized to something simple and efficient. Once the block gets more complicated, like having multiple statements and/or multiple expressions, every block has to be wrapped in scopes *for each call* to that sub. This is one of the reasons why the Larry-Rossler Guttman-Rosler Transform is so efficient.
my @sorted = sort { $a->{id} <=> $b->{id} || $a->{foo} cmp $b->{foo} } + @unsorted; # SLOW my @sorted = map { $_->[1] } sort { $a->[0] cmp $b->[0] } map { pack " +l>A*", $_->{id}, $_->{foo} } @unsorted; # FAST
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: Rosetta Code: Long List is Long (Updated Solutions)
by jwkrahn (Abbot) on Dec 09, 2022 at 20:53 UTC | |
by eyepopslikeamosquito (Archbishop) on Dec 09, 2022 at 21:17 UTC | |
by jwkrahn (Abbot) on Dec 09, 2022 at 22:47 UTC | |
by eyepopslikeamosquito (Archbishop) on Dec 10, 2022 at 13:53 UTC | |
by eyepopslikeamosquito (Archbishop) on Jan 02, 2023 at 09:58 UTC |