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 422
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 #79 from dawgfoto/master
Extended druntime benchmarks and small AA improvement
- Loading branch information
Showing
13 changed files
with
19,888 additions
and
60 deletions.
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
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,5 @@ | ||
| bin/* | ||
| obj/* | ||
| runbench | ||
| runbench.o | ||
| runbench.d.deps |
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,108 @@ | ||
| /** | ||
| * Benchmark bulk filling of AA. | ||
| * | ||
| * Copyright: Copyright Martin Nowak 2011 - 2011. | ||
| * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0) | ||
| * Authors: Martin Nowak | ||
| */ | ||
|
|
||
| import std.random, std.typetuple; | ||
|
|
||
| version (VERBOSE) import std.datetime, std.stdio; | ||
|
|
||
| alias TypeTuple!(ubyte, short, uint, long, void*, Object, ubyte[16], ubyte[64], | ||
| ubyte[256], ubyte[1024], ubyte[4096], ubyte[16384] | ||
| ) ValueTuple; | ||
|
|
||
| enum Size = 2 ^^ 24; | ||
| size_t trot; | ||
|
|
||
| void runTest(V)(ref V v) | ||
| { | ||
| version (VERBOSE) | ||
| { | ||
| StopWatch sw; | ||
| writef("%15-s %8u", V.stringof, Size / V.sizeof); | ||
|
|
||
| void start() | ||
| { | ||
| sw.reset; | ||
| sw.start; | ||
| } | ||
|
|
||
| void stop() | ||
| { | ||
| sw.stop; | ||
| writef(" %5u.%03u", sw.peek.seconds, sw.peek.msecs % 1000); | ||
| } | ||
| } | ||
| else | ||
| { | ||
| static void start() {} | ||
| static void stop() {} | ||
| } | ||
|
|
||
| V[size_t] aa; | ||
|
|
||
| start(); | ||
| foreach(k; 0 .. Size / V.sizeof) | ||
| { | ||
| aa[k] = v; | ||
| } | ||
| stop(); | ||
| aa.clear(); | ||
|
|
||
| start(); | ||
| foreach_reverse(k; 0 .. Size / V.sizeof) | ||
| { | ||
| aa[k] = v; | ||
| } | ||
| stop(); | ||
| aa.clear(); | ||
|
|
||
| start(); | ||
| foreach(ref k; 0 .. trot * (Size / V.sizeof)) | ||
| { | ||
| aa[k] = v; | ||
| k += trot - 1; | ||
| } | ||
| stop(); | ||
| aa.clear(); | ||
|
|
||
| start(); | ||
| foreach_reverse(ref k; 0 .. trot * (Size / V.sizeof)) | ||
| { | ||
| k -= trot - 1; | ||
| aa[k] = v; | ||
| } | ||
| stop(); | ||
| aa.clear(); | ||
|
|
||
| version (VERBOSE) writeln(); | ||
| } | ||
|
|
||
| void main() | ||
| { | ||
| version (RANDOMIZE) | ||
| trot = uniform(1, 200); | ||
| else | ||
| trot = 7; | ||
|
|
||
| version (VERBOSE) | ||
| { | ||
| writefln("==================== Bulk Test ===================="); | ||
| writefln("Filling %s KiB, times in s.", Size/1024); | ||
| writefln("Key step %27d | %7d | %7d | %7d", 1, -1, cast(int)trot, -cast(int)trot); | ||
| writefln("%15-s | %8s | %7s | %7s | %7s | %7s", | ||
| "Type", "num", "step", "revstep", "trot", "revtrot"); | ||
| }; | ||
|
|
||
| ValueTuple valTuple; | ||
| foreach(v; valTuple) | ||
| runTest(v); | ||
|
|
||
| version (VERBOSE) | ||
| { | ||
| writefln("==================== Test Done ===================="); | ||
| } | ||
| } |
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,57 @@ | ||
| /** | ||
| * Benchmark increasing/decreasing AA size. | ||
| * | ||
| * Copyright: Copyright Martin Nowak 2011 - 2011. | ||
| * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0) | ||
| * Authors: Martin Nowak | ||
| */ | ||
|
|
||
| import std.random; | ||
|
|
||
| enum Count = 1_000; | ||
| enum MinSize = 512; | ||
| enum MaxSize = 16_384; | ||
|
|
||
| void runTest(Random gen) | ||
| { | ||
| bool[uint] aa; | ||
|
|
||
| sizediff_t diff = MinSize; | ||
| size_t cnt = Count; | ||
|
|
||
| do | ||
| { | ||
| while (diff > 0) | ||
| { | ||
| auto key = uniform(0, MaxSize, gen); | ||
| if (!(key in aa)) | ||
| { | ||
| aa[key] = true; | ||
| --diff; | ||
| } | ||
| } | ||
|
|
||
| while (diff < 0) | ||
| { | ||
| auto key = uniform(0, MaxSize, gen); | ||
| if (!!(key in aa)) | ||
| { | ||
| aa.remove(key); | ||
| ++diff; | ||
| } | ||
| } | ||
|
|
||
| auto nsize = uniform(MinSize, MaxSize, gen); | ||
| diff = nsize - aa.length; | ||
|
|
||
| } while (--cnt); | ||
| } | ||
|
|
||
| void main() | ||
| { | ||
| version (RANDOMIZE) | ||
| auto gen = Random(unpredictableSeed); | ||
| else | ||
| auto gen = Random(12); | ||
| runTest(gen); | ||
| } |
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,28 @@ | ||
| /** | ||
| * Benchmark string hashing. | ||
| * | ||
| * Copyright: Copyright Martin Nowak 2011 - 2011. | ||
| * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0) | ||
| * Authors: Martin Nowak | ||
| */ | ||
|
|
||
| import std.array, std.file, std.path; | ||
|
|
||
| void runTest(string[] words) | ||
| { | ||
| size_t[string] aa; | ||
|
|
||
| foreach(word; words) | ||
| ++aa[word]; | ||
|
|
||
| assert(aa.length == 20795); | ||
| } | ||
|
|
||
| void main(string[] args) | ||
| { | ||
| // test/bin/aabench/string => test/extra-files/dante.txt | ||
| auto path = dirName(dirName(dirName(absolutePath(args[0])))); | ||
| path = buildPath(path, "extra-files", "dante.txt"); | ||
| auto words = split(std.file.readText(path)); | ||
| runTest(words); | ||
| } |
Oops, something went wrong.