This repository has been archived by the owner on Oct 12, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 426
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1230 from MartinNowak/aaStomper
new AA benchmark with cache stomping
- Loading branch information
Showing
2 changed files
with
67 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters