Skip to content

Instantly share code, notes, and snippets.

@jnthn
Last active August 29, 2015 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jnthn/03e2082ca5ed20ff8d44 to your computer and use it in GitHub Desktop.
Save jnthn/03e2082ca5ed20ff8d44 to your computer and use it in GitHub Desktop.
Given this example code, where we uncomment one of the commented lines (and yeah, this is a
very slow way to do a Range, but I didn't actually implement ranges yet):
my $i = 0;
my $nums := GLRSeq.from-loop({ ++$i }, { $i < 100000 });
my @b := GLRArrayCircumfix();
# @b = $nums.GLRmap({ next unless .is-prime; $_ });
# @b = $nums.race(:degree(1)).GLRmap({ next unless .is-prime; $_ });
# @b = $nums.race(:degree(2)).GLRmap({ next unless .is-prime; $_ });
# @b = $nums.race(:degree(3)).GLRmap({ next unless .is-prime; $_ });
# @b = $nums.race(:degree(4)).GLRmap({ next unless .is-prime; $_ });
die 'oops' unless @b.elems == 9592;
I get (on my unloaded quad core machine):
* Without .race: 24.6s
* With .race(:degree(1)): 25.7s (don't pay off the overhead, but we see it's not crazy overhead)
* With .race(:degree(2)): 15.7s
* With .race(:degree(3)): 13.0s
* With .race(:degree(4)): 11.9s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment