Skip to content

Instantly share code, notes, and snippets.

@kaisersparpick
Last active July 19, 2018 18:40
Show Gist options
  • Save kaisersparpick/289b4a346a02cd1148324729145c36a2 to your computer and use it in GitHub Desktop.
Save kaisersparpick/289b4a346a02cd1148324729145c36a2 to your computer and use it in GitHub Desktop.
constant width = 80;
my int $total-lines = 0;
my int $total-words = 0;
my $excludes = set <cache css data node_modules vendor views>;
sub say-so($name, $lines, $words) {
say (join '', $name, ' ' x (60 - $name.chars), ' | ', ' ' x (5 - $lines.chars), $lines, ' | ', ' ' x (6 - $words.chars), $words)
}
sub count-stuff(Str $dir) {
my int $subtotal-lines = 0;
my int $subtotal-words = 0;
sub doit($dir) {
my @dirs = $dir;
while @dirs {
for dir @dirs.shift -> $file {
if ($file.f && $file.extension eq 'js') {
given $file.open.slurp {
my @lines := .lines.cache;
my @words := .words.cache;
$subtotal-lines += @lines;
$subtotal-words += @words;
say-so($file, @lines.elems, @words.elems);
}
}
elsif ($file.d && $file.basename ∉ $excludes ) {
@dirs.push: $file;
}
}
}
}
doit($dir);
say '-' x width;
say-so('Subtotal', $subtotal-lines, $subtotal-words);
say '';
$total-lines += $subtotal-lines;
$total-words += $subtotal-words;
}
my $start = now;
count-stuff('/home/user/project1');
count-stuff('/home/user/project2');
say '=' x width;
say-so('Total', $total-lines, $total-words);
my $stop = now;
say '';
say "start: $start, stop: $stop, diff: {$stop-$start}";
@kaisersparpick
Copy link
Author

kaisersparpick commented Jul 19, 2018

P6 zoffix with sprintf
start: Instant:1531998216.837400, stop: Instant:1531998267.874560, diff: 51.03716087
start: Instant:1531998292.896695, stop: Instant:1531998293.286463, diff: 0.396683

P6 zoffix
start: Instant:1531999977.222276, stop: Instant:1532000027.986536, diff: 50.76426054
start: Instant:1532000075.094041, stop: Instant:1532000075.457947, diff: 0.3639063

This is Rakudo Star version 2018.01 built on MoarVM version 2018.01 implementing Perl 6.c.
Ubuntu 16.04

@kaisersparpick
Copy link
Author

do
start: Instant:1532009937.977974, stop: Instant:1532010033.088108, diff: 95.1101349
start: Instant:1532008874.049037, stop: Instant:1532008874.557006, diff: 0.5079693

race
start: Instant:1532009239.234297, stop: Instant:1532009239.735399, diff: 0.5011022

atomic
start: Instant:1532008968.334444, stop: Instant:1532008968.837879, diff: 0.503434

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