0xDEADBEEF

RSS odkazy english edition

iotest.d

1. 1. 2021
gdc-10 iotest.d -o test
for i in {10..18}; do
  sudo bash -c 'echo 1 > /proc/sys/vm/drop_caches'
  ./test really-big-file.zst $i
done
import core.sys.linux.fcntl;
import core.sys.linux.unistd;
import core.stdc.stdio : SEEK_SET;
import std.stdio : writeln, write;
import std.file : getSize;
import std.datetime.stopwatch;
import std.random : Xorshift32, uniform;
import std.string : toStringz;
import std.algorithm.sorting;
import std.conv : to;

enum pageSize = 1 << 12;

void main(string[] args) {
  auto fileName = args[1];
  auto readSize = 1 << to!uint(args[2]);
  randomReads(fileName, readSize);
  //seqReads(fileName, readSize);
}


void randomReads(string fileName, uint readSize) {
  auto fd = open(fileName.toStringz, O_RDONLY);
  auto fileSize = getSize(fileName);
  auto rand = Xorshift32(1338);
  ubyte[] buf = new ubyte[readSize];

  auto sw = StopWatch(AutoStart.no);
  auto times = new long[50];

  foreach (iter; 0 .. 50) {
    auto off = uniform(0, fileSize-readSize, rand) & ~(pageSize-1);
    assert(off % pageSize == 0);

    sw.start();

    check!lseek(fd, off, SEEK_SET);
    check!read(fd, buf.ptr, buf.length);

    times[iter] = sw.peek.total!"usecs";
  }

  sort(times);
  write("n=", readSize, " ");
  foreach (t; times) write(t, " ");
  writeln();
}


void seqReads(string fileName, uint readSize) {
  auto fd = open(fileName.toStringz, O_RDONLY);
  ubyte[] buf = new ubyte[readSize];

  auto sw = StopWatch(AutoStart.no);

  check!lseek(fd, pageSize * 47, SEEK_SET);

  foreach (iter; 0 .. 200) {
    sw.start();
    check!read(fd, buf.ptr, buf.length);
    writeln(iter, " ", sw.peek.total!"usecs");
  }
}

auto check(alias fn, T...)(T args) {
  auto res = fn(args);
  assert(res != -1);
  return res;
}
píše k47 (@kaja47, k47)