#!/usr/bin/perl
use utf8;
use strict;
use warnings;
use Capture::Tiny 'capture';
use IO::File;

my $fn;
$fn = 'ddbench.txt';
my $fh = IO::File->new($fn, 'w');
binmode($fh, ':utf8');

sub work
{
  my $cmdline = pop;
  capture {
    print "# $cmdline\n\n";
    system($cmdline);
  } stdout => $fh, stderr => $fh;
}

print $fh "Die folgenden Tests werden im RAID-5 auf der einzigen";
print $fh " Partition (XFS) durchgeführt\n\n";

unlink('tempfile');

for (my $i = 0; $i < 10; $i++)
{
  printf $fh "\nDURCHLAUF %i:\n\n", ($i+1);
  print $fh "Test der Schreibgeschwindigkeit\n\n";
  work("dd if=/dev/zero of=tempfile bs=1M count=1024 conv=fdatasync,notrunc");
  print $fh "Leeren des Lesecaches vor dem Test der Lesegeschwindigkeit\n\n";
  work("echo 3 > /proc/sys/vm/drop_caches");
  print $fh "Test der Lesegeschwindigkeit\n\n";
  work("dd if=tempfile of=/dev/null bs=1M count=1024");
}

print $fh "\n\nTests beendet.";
