0xDEADBEEF

RSS odkazy

benchmark-cache-line-prefetch.d

2. 4. 2021 #kód
module cacheLinePrefetchTest;

import std.algorithm;
import std.array;
import std.conv;
import std.datetime.stopwatch;
import std.random;
import std.stdio;

struct Line { ubyte[64] data; }

void main(string[] args) {
  auto iters = args[1].to!ulong;
  auto len = 1 << 24;

  Line[] lines = new Line[len];
  Line*[] points = lines.map!((ref l) => &l).array;
  randomShuffle(points);

  foreach (i; 0 .. iters) {
    ulong sink = 0;

    auto timer = StopWatch(AutoStart.yes);
    ulong prev;
    foreach (p; points) {
      // dependency
      sink += prev = (*(p+prev)).data[0];

      // no dependency
      //sink += (*p).data[0];
    }

    auto ns = timer.peek().total!"nsecs";

    writeln(ns / double(len), " ns/el");
    writeln(len * 64 / double(ns), "GB/s");
    writeln(sink);
  }
}
píše k47 (@kaja47, k47)