Skip to content

Commit 38b1d0f

Browse files
committed
* add GC benchmark suite
replace runbench.d with a version derived from d_do_test.d
1 parent 6e4ab34 commit 38b1d0f

File tree

13 files changed

+978
-92
lines changed

13 files changed

+978
-92
lines changed

benchmark/aabench/bulk.d

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,17 @@
66
* Authors: Martin Nowak
77
*/
88

9-
import std.random, std.typetuple;
9+
// EXECUTE_ARGS: 20
10+
11+
import std.random, std.typetuple, std.conv;
1012

1113
version (VERBOSE) import std.datetime, std.stdio;
1214

1315
alias TypeTuple!(ubyte, short, uint, long, void*, Object, ubyte[16], ubyte[64],
1416
ubyte[256], ubyte[1024], ubyte[4096], ubyte[16384]
1517
) ValueTuple;
1618

17-
enum Size = 2 ^^ 24;
19+
size_t Size = 2 ^^ 24;
1820
size_t trot;
1921

2022
void runTest(V)(ref V v)
@@ -81,8 +83,11 @@ void runTest(V)(ref V v)
8183
version (VERBOSE) writeln();
8284
}
8385

84-
void main()
86+
void main(string[] args)
8587
{
88+
if (args.length > 1)
89+
Size = 1 << to!int(args[1]);
90+
8691
version (RANDOMIZE)
8792
trot = uniform(1, 200);
8893
else

benchmark/aabench/string.d

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
* Authors: Martin Nowak
77
*/
88

9+
// EXECUTE_ARGS: extra-files/dante.txt
10+
911
import std.array, std.file, std.path;
1012

1113
void runTest(string[] words)
@@ -20,9 +22,15 @@ void runTest(string[] words)
2022

2123
void main(string[] args)
2224
{
23-
// test/bin/aabench/string => test/extra-files/dante.txt
24-
auto path = dirName(dirName(dirName(absolutePath(args[0]))));
25-
path = buildPath(path, "extra-files", "dante.txt");
25+
string path;
26+
if (args.length > 1)
27+
path = args[1];
28+
else
29+
{
30+
// test/bin/aabench/string => test/extra-files/dante.txt
31+
path = dirName(dirName(dirName(absolutePath(args[0]))));
32+
path = buildPath(path, "extra-files", "dante.txt");
33+
}
2634
auto words = split(std.file.readText(path));
2735
runTest(words);
2836
}

benchmark/gcbench/conalloc.d

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/**
2+
* The goal of this program is to do very CPU intensive work with allocations in threads
3+
*
4+
* Copyright: Copyright Leandro Lucarella 2014.
5+
* License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
6+
* Authors: Leandro Lucarella
7+
*/
8+
// EXECUTE_ARGS: 50 4 extra-files/dante.txt
9+
10+
import core.thread;
11+
import core.atomic;
12+
import std.conv;
13+
import std.file;
14+
import std.digest.sha;
15+
16+
auto N = 100;
17+
auto NT = 2;
18+
19+
__gshared ubyte[] BYTES;
20+
shared(int) running; // Atomic
21+
22+
void main(char[][] args)
23+
{
24+
auto fname = args[0];
25+
if (args.length > 3)
26+
fname = args[3];
27+
if (args.length > 2)
28+
NT = to!(int)(args[2]);
29+
if (args.length > 1)
30+
N = to!(int)(args[1]);
31+
N /= NT;
32+
33+
atomicStore(running, NT);
34+
BYTES = cast(ubyte[]) std.file.read(fname);
35+
auto threads = new Thread[NT];
36+
foreach(ref thread; threads)
37+
{
38+
thread = new Thread(&doSha);
39+
thread.start();
40+
}
41+
while (atomicLoad(running))
42+
{
43+
auto a = new ubyte[](BYTES.length);
44+
a[] = cast(ubyte[]) BYTES[];
45+
Thread.yield();
46+
}
47+
foreach(thread; threads)
48+
thread.join();
49+
}
50+
51+
void doSha()
52+
{
53+
for (size_t i = 0; i < N; i++)
54+
{
55+
auto sha = new SHA1; // undefined identifier SHA512?
56+
sha.put(BYTES);
57+
}
58+
running += -1;
59+
}
60+

benchmark/gcbench/conappend.d

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/**
2+
* The goal of this program is to do concurrent allocations in threads
3+
*
4+
* Copyright: Copyright Leandro Lucarella 2014.
5+
* License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
6+
* Authors: Leandro Lucarella
7+
*/
8+
// EXECUTE_ARGS: 50 4 extra-files/dante.txt
9+
10+
import core.thread;
11+
import core.atomic;
12+
import std.conv;
13+
import std.file;
14+
import std.exception;
15+
16+
auto N = 100;
17+
auto NT = 2;
18+
19+
__gshared ubyte[] BYTES;
20+
shared(int) running; // Atomic
21+
22+
void main(char[][] args)
23+
{
24+
auto fname = args[0];
25+
if (args.length > 3)
26+
fname = args[3];
27+
if (args.length > 2)
28+
NT = to!(int)(args[2]);
29+
if (args.length > 1)
30+
N = to!(int)(args[1]);
31+
N /= NT;
32+
33+
atomicStore(running, NT);
34+
BYTES = cast(ubyte[]) std.file.read(fname);
35+
auto threads = new Thread[NT];
36+
foreach(ref thread; threads)
37+
{
38+
thread = new Thread(&doAppend);
39+
thread.start();
40+
}
41+
while (atomicLoad(running))
42+
{
43+
auto a = new ubyte[](BYTES.length);
44+
a[] = cast(ubyte[]) BYTES[];
45+
Thread.yield();
46+
}
47+
foreach(thread; threads)
48+
thread.join();
49+
}
50+
51+
void doAppend()
52+
{
53+
for (size_t i = 0; i < N; i++)
54+
{
55+
int[] arr;
56+
for (int j = 0; j < 1000; j++)
57+
arr ~= j;
58+
59+
int sum = 0;
60+
foreach (a; arr)
61+
sum += a;
62+
enforce(sum == 1000 * 999 / 2, "bad sum");
63+
}
64+
running += -1;
65+
}
66+

benchmark/gcbench/concpu.d

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/**
2+
* The goal of this program is to do very CPU intensive work in threads
3+
*
4+
* Copyright: Copyright Leandro Lucarella 2014.
5+
* License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
6+
* Authors: Leandro Lucarella
7+
*/
8+
// EXECUTE_ARGS: 50 4 extra-files/dante.txt
9+
10+
import core.thread;
11+
import core.atomic;
12+
import std.conv;
13+
import std.file;
14+
import std.digest.sha;
15+
16+
auto N = 100;
17+
auto NT = 2;
18+
19+
__gshared ubyte[] BYTES;
20+
shared(int) running; // Atomic
21+
22+
void main(char[][] args)
23+
{
24+
auto fname = args[0];
25+
if (args.length > 3)
26+
fname = args[3];
27+
if (args.length > 2)
28+
NT = to!(int)(args[2]);
29+
if (args.length > 1)
30+
N = to!(int)(args[1]);
31+
N /= NT;
32+
33+
atomicStore(running, NT);
34+
BYTES = cast(ubyte[]) std.file.read(fname);
35+
auto threads = new Thread[NT];
36+
foreach(ref thread; threads)
37+
{
38+
thread = new Thread(&doSha);
39+
thread.start();
40+
}
41+
while (atomicLoad(running))
42+
{
43+
auto a = new void[](BYTES.length);
44+
a[] = cast(void[]) BYTES[];
45+
Thread.yield();
46+
}
47+
foreach(thread; threads)
48+
thread.join();
49+
}
50+
51+
void doSha()
52+
{
53+
auto sha = new SHA1; // undefined identifier SHA512?
54+
for (size_t i = 0; i < N; i++)
55+
{
56+
sha.put(BYTES);
57+
}
58+
running += -1;
59+
}
60+

benchmark/gcbench/dlist.d

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/**
2+
* Copyright: Copyright Rainer Schuetze 2014.
3+
* License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
4+
* Authors: Rainer Schuetze
5+
*
6+
* This test reads a text file, then splits the result into white space delimited words.
7+
* The result is a double linked list of strings referencing the full text.
8+
* Regarding GC activity, this test probes collection of linked lists.
9+
*/
10+
// EXECUTE_ARGS: extra-files/dante.txt 100 9767600
11+
12+
import std.stdio;
13+
import std.conv;
14+
import std.file;
15+
import std.string;
16+
import std.exception;
17+
18+
// double-linked list with circular next/prev pointers
19+
struct Node
20+
{
21+
string token;
22+
Node* next; // first in root
23+
Node* prev; // last in root
24+
}
25+
26+
void main(string[] args)
27+
{
28+
enforce(args.length > 2, "usage: dlist <file-name> <iterations> [expected-result]");
29+
string txt = cast(string) std.file.read(args[1]);
30+
uint cnt = to!uint(args[2]);
31+
uint allwords = 0;
32+
for(uint i = 0; i < cnt; i++)
33+
{
34+
Node* rootNode = new Node;
35+
rootNode.next = rootNode;
36+
rootNode.prev = rootNode;
37+
38+
auto words = txt.split();
39+
foreach(w; words)
40+
{
41+
Node* n = new Node;
42+
n.token = w;
43+
// insert at end of list
44+
n.next = rootNode;
45+
n.prev = rootNode.prev;
46+
rootNode.prev.next = n;
47+
rootNode.prev = n;
48+
}
49+
50+
for(Node* p = rootNode.next; p != rootNode; p = p.next)
51+
allwords++;
52+
}
53+
writeln("words: ", allwords);
54+
55+
if(args.length > 3)
56+
enforce(allwords == to!size_t(args[3]));
57+
}

benchmark/gcbench/rand_small.d

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,17 @@
1111
* (See accompanying file LICENSE or copy at
1212
* http://www.boost.org/LICENSE_1_0.txt)
1313
*/
14-
import std.random, core.memory, std.stdio;
14+
import std.random, core.memory, std.stdio, std.conv;
1515

16-
enum nIter = 1000;
16+
void main(string[] args)
17+
{
18+
size_t nIter = 1000;
19+
if(args.length > 1)
20+
nIter = to!size_t(args[1]);
1721

18-
void main() {
1922
auto ptrs = new void*[4096];
2023

21-
// Allocate 1024 large blocks with size uniformly distributed between 8
24+
// Allocate large blocks with size uniformly distributed between 8
2225
// and 2048 bytes.
2326
foreach(i; 0..nIter) {
2427
foreach(ref ptr; ptrs) {

benchmark/gcbench/slist.d

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/**
2+
* Copyright: Copyright Rainer Schuetze 2014.
3+
* License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
4+
* Authors: Rainer Schuetze
5+
*
6+
* This test reads a text file, then splits the result into white space delimited words.
7+
* The result is a single linked list of strings referencing the full text.
8+
* Regarding GC activity, this test probes collection of linked lists.
9+
*/
10+
// EXECUTE_ARGS: extra-files/dante.txt 100 9767600
11+
12+
import std.stdio;
13+
import std.conv;
14+
import std.file;
15+
import std.string;
16+
import std.exception;
17+
18+
struct Node
19+
{
20+
string token;
21+
Node* next;
22+
}
23+
24+
void main(string[] args)
25+
{
26+
enforce(args.length > 2, "usage: slist <file-name> <iterations> [expected-result]");
27+
string txt = cast(string) std.file.read(args[1]);
28+
uint cnt = to!uint(args[2]);
29+
uint allwords = 0;
30+
for(uint i = 0; i < cnt; i++)
31+
{
32+
Node* firstNode;
33+
auto words = txt.split();
34+
foreach(w; words)
35+
{
36+
Node* n = new Node;
37+
n.token = w;
38+
n.next = firstNode;
39+
firstNode = n;
40+
}
41+
42+
for(Node* p = firstNode; p; p = p.next)
43+
allwords++;
44+
}
45+
writeln("words: ", allwords);
46+
47+
if(args.length > 3)
48+
enforce(allwords == to!size_t(args[3]));
49+
}

0 commit comments

Comments
 (0)