Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env perl
- # notes:
- # a run on juvat2 (2016-01-31) with 10 Gb was ~2 minutes
- # a run on bigtom (2016-01-31) with 10 Gb was 1m37s
- use v5.14; # 'say'
- use autodie;
- use File::Basename;
- # 100 char string (counting the ending newline)
- my $str = "012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678\n";
- my $gb = 1_000_000_000;
- my $prog = basename($0);
- if (!@ARGV) {
- say "Usage: $prog <file size in Gb (an integer > -1)>\n";
- exit;
- }
- # desired size in gigabytes
- my $ngb = shift @ARGV;
- die "FATAL: '$ngb' is not an integer.\n"
- if $ngb =~ /[^\d]+/;
- my $ofil = "large-${ngb}-gb-file.txt";
- # how many lines (iterations) needed?
- my $slen = length $str;
- 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";
- open my $fp, '>', $ofil;
- for (1 .. $nlines) {
- print $fp $str;
- }
- say "see output file '$ofil'";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement