Speed isn’t everything. Sometimes clarity and elegance get precedence. I think Perl 6 enables elegance, so much so that I don’t mind that it’s not a speed daemon [1]. Perl 5 on the other hand is. And we shouldn’t expect any less of it, since 5 has been trimmed and tinkered with for a quarter of a century now.

Perl 6 is the newcomer, so it’d be unreasonable to expect the same optimisation. But the thing is that guys like me, i.e. people with some Perl 5 experience, are carriers of perl5-isms. Some of those -isms spill over when we write Perl 6 code [2]. Not only do I expect the result to be the same, but if I’m honest also that it’d match some of 5’s speed.

Consider the code below.

# 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: glgvlxzm real 0m3.563s

user 0m3.478s

sys 0m0.069s

This snippet generates an array of 1,000,000 eight-character strings (in itself not very interesting, but I’ll use the array later on for something else). My old-ish MacBook Pro Perl 5 uses around 3,5 seconds to generate one million strings and populate an array with them.

If I — out of habit — program the same thing in Perl 6, using my perl 5 thinking, I end up with almost similar code.

$ 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: uywokcsh real 0m49.320s

user 0m49.029s

sys 0m0.296s

The result’s exactly what I expected, what’s unexpected is the time the program takes to complete [3]. Had Perl 6 been called, say, Camelia or Century or whatever else, I think I wouldn’t have thought about speed in these terms. Sure, I’d notice that it was a little sluggish. I’d maybe compare the results to Python or Julia or Perl 5 and been a little surprised, but I wouldn’t have expected 1:1 similarity speed wise.

Perhaps I’d be more occupied with the ways Perl 6 enables beautiful, readable and concise code. Because those are, to me, Perl 6’s main selling points at the moment. It’s just that as it is now, in the shadow of Perl 5, they’re a little easy to forget.

If you’re interested you can now go on to read the second part: Perl small stuff #9½: Perception of speed — benchmarking grep. In that one I discover that it’s really the small stuff that makes a big difference

One day later: Read Simon Proctor’s insightful comment below. He pointed me to the Perl 6 solution that is the fastest [5].