Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env perl6
- # note: a run on juvat2 (2016-01-31) with 10 Gb was ~36 minutes
- # 100 char string (counting the ending newline)
- my $str = "012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678\n";
- my $gb = 1_000_000_000;
- my $prog = $*PROGRAM.basename;
- if !@*ARGS.elems {
- say "Usage: $prog <file size in Gb (an integer > -1)>\n";
- exit;
- }
- # desired size in gigabytes
- my $ngb = shift @*ARGS;
- $ngb .= Int;
- #say $ngb.WHAT;
- die "FATAL: '$ngb' is not an integer.\n"
- if $ngb.WHAT !~~ Int;
- my $ofil = 'large-' ~ $ngb ~ '-gb-file.txt';
- # how many (lines) iterations needed?
- my $slen = $str.chars;
- my $nlines = $ngb * $gb / $slen;
- # if we create a small file for testing
- my $snlines = 100_000;
- my $ssize = $snlines * $slen / 1_000_000; # Mb
- my $ostr = $ngb == 0 ?? "0 ($ssize Mb)" !! $ngb;
- $nlines = $snlines if $ngb == 0;
- say "Requested file size (Gb): $ostr";
- say "String size: $slen";
- say "Number lines: $nlines";
- my $fp = open($ofil, :w);
- for 1 .. $nlines {
- $fp.print($str);
- }
- say "see output file '$ofil'";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement