Advertisement
tbrowder

create-large-file.p6

Feb 3rd, 2016
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. #!/usr/bin/env perl6
  2.  
  3. # note: a run on juvat2 (2016-01-31) with 10 Gb was ~36 minutes
  4.  
  5. # 100 char string (counting the ending newline)
  6. my $str = "012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678\n";
  7. my $gb = 1_000_000_000;
  8.  
  9. my $prog = $*PROGRAM.basename;
  10. if !@*ARGS.elems {
  11. say "Usage: $prog <file size in Gb (an integer > -1)>\n";
  12. exit;
  13. }
  14.  
  15. # desired size in gigabytes
  16. my $ngb = shift @*ARGS;
  17. $ngb .= Int;
  18. #say $ngb.WHAT;
  19.  
  20. die "FATAL: '$ngb' is not an integer.\n"
  21. if $ngb.WHAT !~~ Int;
  22.  
  23. my $ofil = 'large-' ~ $ngb ~ '-gb-file.txt';
  24.  
  25. # how many (lines) iterations needed?
  26. my $slen = $str.chars;
  27. my $nlines = $ngb * $gb / $slen;
  28.  
  29. # if we create a small file for testing
  30. my $snlines = 100_000;
  31. my $ssize = $snlines * $slen / 1_000_000; # Mb
  32.  
  33. my $ostr = $ngb == 0 ?? "0 ($ssize Mb)" !! $ngb;
  34. $nlines = $snlines if $ngb == 0;
  35.  
  36. say "Requested file size (Gb): $ostr";
  37. say "String size: $slen";
  38. say "Number lines: $nlines";
  39.  
  40. my $fp = open($ofil, :w);
  41.  
  42. for 1 .. $nlines {
  43. $fp.print($str);
  44. }
  45.  
  46. say "see output file '$ofil'";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement