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 #79 from dawgfoto/master
Browse files Browse the repository at this point in the history
Extended druntime benchmarks and small AA improvement
  • Loading branch information
complexmath committed Oct 13, 2011
2 parents 374ccc1 + 3a625b3 commit 9a8a328
Show file tree
Hide file tree
Showing 13 changed files with 19,888 additions and 60 deletions.
15 changes: 8 additions & 7 deletions src/rt/aaA.d
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ private
}

extern (C) void* gc_malloc( size_t sz, uint ba = 0 );
extern (C) void* gc_calloc( size_t sz, uint ba = 0 );
extern (C) void gc_free( void* p );

// Convenience function to make sure the NO_INTERIOR gets set on the
Expand Down Expand Up @@ -245,7 +244,7 @@ body
aaA *e;
//printf("keyti = %p\n", keyti);
//printf("aa = %p\n", aa);
auto keysize = aligntsize(keyti.tsize());
immutable keytitsize = keyti.tsize();

if (!aa.a)
{ aa.a = new BB();
Expand All @@ -272,11 +271,13 @@ body

// Not found, create new elem
//printf("create new one\n");
size_t size = aaA.sizeof + keysize + valuesize;
e = cast(aaA *) gc_calloc(size);
memcpy(e + 1, pkey, keyti.tsize);
memset(cast(byte*)(e + 1) + keyti.tsize, 0, keysize - keyti.tsize);
size_t size = aaA.sizeof + aligntsize(keytitsize) + valuesize;
e = cast(aaA *) gc_malloc(size);
e.next = null;
e.hash = key_hash;
ubyte* ptail = cast(ubyte*)(e + 1);
memcpy(ptail, pkey, keytitsize);
memset(ptail + aligntsize(keytitsize), 0, valuesize); // zero value
*pe = e;

auto nodes = ++aa.a.nodes;
Expand All @@ -288,7 +289,7 @@ body
}

Lret:
return cast(void *)(e + 1) + keysize;
return cast(void *)(e + 1) + aligntsize(keytitsize);
}


Expand Down
5 changes: 5 additions & 0 deletions test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
bin/*
obj/*
runbench
runbench.o
runbench.d.deps
108 changes: 108 additions & 0 deletions test/aabench/bulk.d
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 ====================");
}
}
57 changes: 57 additions & 0 deletions test/aabench/resize.d
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);
}
28 changes: 28 additions & 0 deletions test/aabench/string.d
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);
}
Loading

0 comments on commit 9a8a328

Please sign in to comment.