Perl 6 small stuff #9: Vantage points and the perception of speed

# Perl 5$ time perl -E 'my @a = "a".."z"; my @e = map join("", map $a[rand @a], 1..8), 1..1_000_000; say "P5: $e[0]";'P5: glgvlxzmreal 0m3.563s
user 0m3.478s
sys 0m0.069s
$ time perl6 -e 'my @a = "a".."z"; my @e = map { map( { @a.pick }, 1..8).join }, 1..1_000_000; say "P6: @e[0]";'P6: uywokcshreal 0m49.320s
user 0m49.029s
sys 0m0.296s
my @e = ((@a.pick for ^8).join("") for ^1_000_000);
my @e = (pick(8, "a".."z").join for ^1_000_000);
File: optimized-gather.p6my @alphabet = "a".."z";
my @array = (@alphabet.roll(8).join for ^1_000_000);
say "^yl: " ~ @array.grep(*.starts-with("yl")).elems;
Run:
$ time perl6 optimized-gather.p6
Output:
^yl: 1452
real 0m8.536s
user 0m8.438s
sys 0m0.254s

--

--

--

Norwegian with many interests. Programming being one of them.

Love podcasts or audiobooks? Learn on the go with our new app.

Deploy your Meteor Web and Android App using MUP

A Short History of Objective-C

Getting Started with GoLang and MongoDB

Applications of Custom Fields in WordPress

Kafka Transactions — Integrating with Legacy Systems

Know your variables

Kiali releases 1.34 to 1.39: Feature update

Infrastructure as Code using Terraform on AWS Cloud

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Jo Christian Oterhals

Jo Christian Oterhals

Norwegian with many interests. Programming being one of them.

More from Medium

Best LinkedIn Practices for Remote Software Developers

The art of polite code reviews

My Engineering Journey at Midtrans: Addressing Problems One Step at A Time

Top tips for running Hack days