Skip to content

Instantly share code, notes, and snippets.

@Altai-man

Altai-man/foo.p6 Secret

Created June 24, 2019 15:29
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 Altai-man/bb7a57736ea272553edc2dbbfc61af45 to your computer and use it in GitHub Desktop.
Save Altai-man/bb7a57736ea272553edc2dbbfc61af45 to your computer and use it in GitHub Desktop.
use v6.c;
use Pod::Load;
sub recursive-dir($dir) is export {
my @todo = $dir;
gather while @todo {
my $d = @todo.shift;
for dir($d) -> $f {
if $f.f {
take $f;
}
else {
@todo.append: $f.path;
}
}
}
}
sub read-dir($dir) {
recursive-dir("doc/$dir/")
.grep({.path ~~ / '.pod6' $/})
.map({
.path.subst("doc/$dir/", '')
.subst(rx{\.pod6$}, '')
.subst(:g, '/', '::')
=> $_
});
}
sub MAIN {
my @files = [read-dir($_).Slip for <Type Programs Native Language>][0..100];
# secuencial
my $start = now;
for @files {
load($_.value);
}
my $end = now;
my $elapsed = ($end - $start);
say "Secuencial => $elapsed";
# parallel
$start = now;
my @ts;
for ^10 {
@ts.push: start {
loop {
last if @files.elems == 0;
my $file = @files.shift;
load($file.value);
CATCH {
default {
.note;
}
}
}
}
}
await Promise.allof(@ts);
$end = now;
$elapsed = ($end - $start );
say "Parallel => $elapsed";
}
@JJ
Copy link

JJ commented Jun 25, 2019

Even if Pod::Load works, which it does, there's still the problem of the low-level filesystem routines, and out-of-Rakudo access to filesystem itself. It's probably never a (very) good idea to parallelize that, because it's going to be sequential no matter what. Even if you eliminate a bit of overhead, it's going to come back at you with a vengeance when you go to the OS to do stuff.
Baseline is: disk drives do not have many cores.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment