-
-
Save Altai-man/bb7a57736ea272553edc2dbbfc61af45 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.