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

This is not a post complaining about speed. It’s a post about how expectations influence our 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.

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