Advertisement
tbrowder

read-file-test.p6

Feb 3rd, 2016
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. #!/usr/bin/env perl6
  2.  
  3. # notes:
  4. # a run on juvat2 (2016-01-31) with 10 Gb input file was 22m25s
  5. # a run on bigtom (2016-01-31) with 10 Gb input file was 23m11s
  6. # the time for 'wc' on juvat2 was 1m57s
  7. # the time for 'wc' on bigtom was 1m30s
  8.  
  9. my $prog = $*PROGRAM.basename;
  10. if !@*ARGS.elems {
  11. say "Usage: $prog <input file>" ~ "\n";
  12. exit;
  13. }
  14.  
  15. my $ifil = shift @*ARGS;
  16.  
  17. die "FATAL: file '$ifil' not found.\n"
  18. if !$ifil.IO.f;
  19.  
  20. my $fsiz = $ifil.IO.s;
  21.  
  22. say " File '$ifil' size: $fsiz bytes";
  23.  
  24. my $nlines = 0;
  25. my $nchars = 0;
  26. for $ifil.IO.lines -> $line {
  27. ++$nlines;
  28. $nchars += $line.chars;
  29. }
  30.  
  31. # adjust for newlines being removed
  32. $nchars += $nlines;
  33.  
  34. say " Normal end.";
  35. say " For input file '$ifil':";
  36. say " Number lines: $nlines";
  37. say " Number chars: $nchars";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement