In my testing, this is faster:
Brent Laabs
11

Thanks Brent! I hadn’t thought of this at all. Now that you’ve pointed this out to me, I feel that your version is the best illustration yet as to why learning 6 is to forget 5. BTW, I haven’t ventured into parallelizing at all, so your comment gave me the reasons I need.

However, I did some testing using your suggestions and experience the opposite of you. Here’s the code:

my $start = now;
say "^yl: " ~ @array.grep(*.starts-with("yl")).elems;
say "Ordinary Grep duration: " ~ now - $start;
$start = now;
say "^yl: " ~ @array.hyper.grep(*.starts-with("yl")).elems;
say "Hyper Grep duration: " ~ now - $start;
$start = now;
say "^yl: " ~ @array.race.grep(*.starts-with("yl")).elems;
say "race Grep duration: " ~ now - $start;

What’s interesting is that the ordinary grep is the fastest in my testing:

Output:
^yl: 1563
Ordinary Grep duration: 1.4747359
^yl: 1563
Hyper Grep duration: 10.06229302
^yl: 1563
race Grep duration: 5.56080517

As I’ve noted quite a few times in these blog posts, my machine is a relatively old MacBook Pro — 2013 version with a two-core i7 processor. Could it be that my machine is not quite up to the task of parallelization, and that attempts to parallelize incurres a speed penalty instead?

Like what you read? Give Jo Christian Oterhals a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.