Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re^3: sort of misunderstanding of sort -- Discipulus's shuffle

by Discipulus (Canon)
on Mar 22, 2023 at 08:43 UTC ( [id://11151121]=note: print w/replies, xml ) Need Help??


in reply to Re^2: sort of misunderstanding of sort
in thread sort of misunderstanding of sort

Just for fun..

obfuscated shuffle can be sort {--$|} but, as expected, List::Util shuffle is a bit more performant

use strict; use warnings; use Benchmark qw(cmpthese); use List::Util qw(shuffle); my $count = 10000; my @numbers = 0..10000; cmpthese($count, { 'List::Util::shuffle' => sub { my @shuffled = shuffle @numbers }, 'Discipulus::shuffle' => sub { my @shuffled = sort { int rand(3) - + 1 } @numbers }, 'Discipulus::--$|fle' => sub { my @shuffled = sort { --$| } @numbe +rs }, }); __END__ Rate Discipulus::--$|fle Discipulus::shuffle Lis +t::Util::shuffle Discipulus::--$|fle 164/s -- -52% + -95% Discipulus::shuffle 342/s 108% -- + -89% List::Util::shuffle 3107/s 1793% 809% + --

L*

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

Replies are listed 'Best First'.
Re^4: sort of misunderstanding of sort -- Discipulus's shuffle
by bliako (Monsignor) on Mar 22, 2023 at 12:24 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11151121]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (2)
As of 2024-04-26 06:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found