Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
Merge pull request #1230 from MartinNowak/aaStomper
Browse files Browse the repository at this point in the history
new AA benchmark with cache stomping
  • Loading branch information
rainers committed May 1, 2015
2 parents d04176f + 9dbc1c1 commit 649ac78
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 1 deletion.
66 changes: 66 additions & 0 deletions benchmark/aabench/stomper.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/**
* Benchmark hash with cache stomping.
*
* Copyright: Copyright Martin Nowak 2015 - .
* License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
* Authors: Martin Nowak
*/
import std.file, std.algorithm, std.random, std.math;

// exponential distribution around mean
struct ExpRandom
{
double mean;
Xorshift32 gen;

this(double mean)
{
this.mean = mean;
gen = Xorshift32(unpredictableSeed);
}

size_t front()
{
return lround(mean * -log(uniform!"()"(0.0, 1.0, gen)));
}

alias gen this;
}

struct CacheStomper
{
ExpRandom rnd;
size_t i;
ubyte[] mem;

this(size_t avgBytesPerCall)
{
rnd = ExpRandom(avgBytesPerCall / 64.0);
mem = new ubyte[](32 * 1024 * 1024);
}

void stomp()
{
immutable n = rnd.front();
rnd.popFront();
foreach (_; 0 .. n)
++mem[(i += 64) & ($ - 1)];
}
}

void main(string[] args)
{
auto path = args.length > 1 ? args[1] : "extra-files/dante.txt";
auto words = splitter(cast(string) read(path), ' ');

size_t[string] aa;
auto stomper = CacheStomper(1000);
foreach (_; 0 .. 10)
{
foreach (word; words)
{
++aa[word];
stomper.stomp();
}
}
}
2 changes: 1 addition & 1 deletion benchmark/aabench/string.d
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
* Authors: Martin Nowak
*/
import std.array, std.file, std.path;
import std.algorithm, std.file;

void runTest(R)(R words)
{
Expand Down

0 comments on commit 649ac78

Please sign in to comment.