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 #1074 from MartinNowak/runbench
Browse files Browse the repository at this point in the history
improve benchmark script
  • Loading branch information
rainers committed Jan 5, 2015
2 parents bd3a2fb + 91d890a commit 36ed59b
Show file tree
Hide file tree
Showing 12 changed files with 178 additions and 619 deletions.
9 changes: 3 additions & 6 deletions benchmark/aabench/bulk.d
Expand Up @@ -5,9 +5,6 @@
* License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
* Authors: Martin Nowak
*/

// EXECUTE_ARGS: 20

import std.random, std.typetuple, std.conv;

version (VERBOSE) import std.datetime, std.stdio;
Expand All @@ -16,7 +13,7 @@ alias TypeTuple!(ubyte, short, uint, long, void*, Object, ubyte[16], ubyte[64],
ubyte[256], ubyte[1024], ubyte[4096], ubyte[16384]
) ValueTuple;

size_t Size = 2 ^^ 24;
size_t Size = 2 ^^ 20;
size_t trot;

void runTest(V)(ref V v)
Expand Down Expand Up @@ -52,15 +49,15 @@ void runTest(V)(ref V v)
aa[k] = v;
}
stop();
aa.clear();
aa.destroy();

start();
foreach_reverse(k; 0 .. Size / V.sizeof)
{
aa[k] = v;
}
stop();
aa.clear();
aa.destroy();

start();
foreach(ref k; 0 .. trot * (Size / V.sizeof))
Expand Down
13 changes: 1 addition & 12 deletions benchmark/aabench/string.d
Expand Up @@ -5,9 +5,6 @@
* License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
* Authors: Martin Nowak
*/

// EXECUTE_ARGS: extra-files/dante.txt

import std.array, std.file, std.path;

void runTest(string[] words)
Expand All @@ -22,15 +19,7 @@ void runTest(string[] words)

void main(string[] args)
{
string path;
if (args.length > 1)
path = args[1];
else
{
// test/bin/aabench/string => test/extra-files/dante.txt
path = dirName(dirName(dirName(absolutePath(args[0]))));
path = buildPath(path, "extra-files", "dante.txt");
}
auto path = args.length > 1 ? args[1] : "extra-files/dante.txt";
auto words = split(std.file.readText(path));
runTest(words);
}
15 changes: 6 additions & 9 deletions benchmark/gcbench/conalloc.d
Expand Up @@ -5,29 +5,27 @@
* License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
* Authors: Leandro Lucarella
*/
// EXECUTE_ARGS: 50 4 extra-files/dante.txt

import core.thread;
import core.atomic;
import std.conv;
import std.file;
import std.digest.sha;

auto N = 100;
auto NT = 2;
auto N = 50;
auto NT = 4;

__gshared ubyte[] BYTES;
shared(int) running; // Atomic

void main(char[][] args)
void main(string[] args)
{
auto fname = args[0];
auto fname = "extra-files/dante.txt";
if (args.length > 3)
fname = args[3];
if (args.length > 2)
NT = to!(int)(args[2]);
NT = to!int(args[2]);
if (args.length > 1)
N = to!(int)(args[1]);
N = to!int(args[1]);
N /= NT;

atomicStore(running, NT);
Expand Down Expand Up @@ -57,4 +55,3 @@ void doSha()
}
running += -1;
}

11 changes: 4 additions & 7 deletions benchmark/gcbench/conappend.d
Expand Up @@ -5,23 +5,21 @@
* License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
* Authors: Leandro Lucarella
*/
// EXECUTE_ARGS: 50 4 extra-files/dante.txt

import core.thread;
import core.atomic;
import std.conv;
import std.file;
import std.exception;

auto N = 100;
auto NT = 2;
auto N = 50;
auto NT = 4;

__gshared ubyte[] BYTES;
shared(int) running; // Atomic

void main(char[][] args)
void main(string[] args)
{
auto fname = args[0];
auto fname = "extra-files/dante.txt";
if (args.length > 3)
fname = args[3];
if (args.length > 2)
Expand Down Expand Up @@ -63,4 +61,3 @@ void doAppend()
}
running += -1;
}

11 changes: 4 additions & 7 deletions benchmark/gcbench/concpu.d
Expand Up @@ -5,23 +5,21 @@
* License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
* Authors: Leandro Lucarella
*/
// EXECUTE_ARGS: 50 4 extra-files/dante.txt

import core.thread;
import core.atomic;
import std.conv;
import std.file;
import std.digest.sha;

auto N = 100;
auto NT = 2;
auto N = 50;
auto NT = 4;

__gshared ubyte[] BYTES;
shared(int) running; // Atomic

void main(char[][] args)
void main(string[] args)
{
auto fname = args[0];
auto fname = "extra-files/dante.txt";
if (args.length > 3)
fname = args[3];
if (args.length > 2)
Expand Down Expand Up @@ -57,4 +55,3 @@ void doSha()
}
running += -1;
}

12 changes: 3 additions & 9 deletions benchmark/gcbench/dlist.d
Expand Up @@ -7,8 +7,6 @@
* The result is a double linked list of strings referencing the full text.
* Regarding GC activity, this test probes collection of linked lists.
*/
// EXECUTE_ARGS: extra-files/dante.txt 100 9767600

import std.stdio;
import std.conv;
import std.file;
Expand All @@ -25,9 +23,8 @@ struct Node

void main(string[] args)
{
enforce(args.length > 2, "usage: dlist <file-name> <iterations> [expected-result]");
string txt = cast(string) std.file.read(args[1]);
uint cnt = to!uint(args[2]);
string txt = cast(string) std.file.read(args.length > 1 ? args[1] : "extra-files/dante.txt");
uint cnt = args.length > 2 ? to!uint(args[2]) : 100;
uint allwords = 0;
for(uint i = 0; i < cnt; i++)
{
Expand All @@ -50,8 +47,5 @@ void main(string[] args)
for(Node* p = rootNode.next; p != rootNode; p = p.next)
allwords++;
}
writeln("words: ", allwords);

if(args.length > 3)
enforce(allwords == to!size_t(args[3]));
enforce(allwords == (args.length > 3 ? to!size_t(args[3]) : 9767600));
}
12 changes: 3 additions & 9 deletions benchmark/gcbench/slist.d
Expand Up @@ -7,8 +7,6 @@
* The result is a single linked list of strings referencing the full text.
* Regarding GC activity, this test probes collection of linked lists.
*/
// EXECUTE_ARGS: extra-files/dante.txt 100 9767600

import std.stdio;
import std.conv;
import std.file;
Expand All @@ -23,9 +21,8 @@ struct Node

void main(string[] args)
{
enforce(args.length > 2, "usage: slist <file-name> <iterations> [expected-result]");
string txt = cast(string) std.file.read(args[1]);
uint cnt = to!uint(args[2]);
string txt = cast(string) std.file.read(args.length > 1 ? args[1] : "extra-files/dante.txt");
uint cnt = args.length > 2 ? to!uint(args[2]) : 100;
uint allwords = 0;
for(uint i = 0; i < cnt; i++)
{
Expand All @@ -42,8 +39,5 @@ void main(string[] args)
for(Node* p = firstNode; p; p = p.next)
allwords++;
}
writeln("words: ", allwords);

if(args.length > 3)
enforce(allwords == to!size_t(args[3]));
enforce(allwords == (args.length > 3 ? to!size_t(args[3]) : 9767600));
}
8 changes: 2 additions & 6 deletions benchmark/gcbench/testgc3.d
Expand Up @@ -6,16 +6,14 @@
* A 32-bit process can be sensitive to false pointers as hash values
* in the AAs can reference arbitrary addresses.
*/
// EXECUTE_ARGS: 4 200

import std.c.stdio;
import std.conv;
import std.exception;

int main(string[] args)
{
int cnt = 1;
int num = 1000;
int cnt = 4;
int num = 200;
if (args.length > 1)
cnt = to!int(args[1]);
if (args.length > 2)
Expand All @@ -36,10 +34,8 @@ int main(string[] args)
sum = 0;
foreach(s; aa[4711])
sum += s;
printf("finished %lld\n", sum);
enforce(sum == 4711 * num + 10000 * num * (num - 1) / 2);
aa[] = null;
}
return 0;
}

7 changes: 2 additions & 5 deletions benchmark/gcbench/tree1.d
Expand Up @@ -11,8 +11,6 @@
* (See accompanying file LICENSE or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*/
// EXECUTE_ARGS: 14 4

import std.stdio, std.conv, std.exception;

class TreeNode {
Expand Down Expand Up @@ -50,9 +48,8 @@ class TreeNode {

void main(string[] args) {

enforce(args.length > 2, "usage: tree1 <n> <minDepth>");
int n = to!int(args[1]);
int minDepth = to!int(args[2]);
int n = args.length > 1 ? to!int(args[1]) : 14;
int minDepth = args.length > 2 ? to!int(args[2]) : 4;

int maxDepth = (minDepth + 2 > n) ? minDepth + 2 : n;
int stretchDepth = maxDepth + 1;
Expand Down
8 changes: 2 additions & 6 deletions benchmark/gcbench/tree2.d
Expand Up @@ -11,15 +11,12 @@
* (See accompanying file LICENSE or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*/
// EXECUTE_ARGS: 7000000 100

import std.stdio, std.container, std.range, std.conv, std.exception;

void main(string[] args)
{
enforce(args.length > 2, "usage: tree2 <n> <range>");
int n = to!int(args[1]);
int range = to!int(args[2]);
int n = args.length > 1 ? to!int(args[1]) : 7000000;
int range = args.length > 2 ? to!int(args[2]) : 100;

auto t = redBlackTree!int();

Expand All @@ -29,4 +26,3 @@ void main(string[] args)
t.insert(i);
}
}

12 changes: 3 additions & 9 deletions benchmark/gcbench/words.d
Expand Up @@ -9,8 +9,6 @@
* Regarding GC activity, this test probes concatenation of long strings and appending
* to a large array of strings.
*/
// EXECUTE_ARGS: extra-files/dante.txt 100 9767600

import std.stdio;
import std.conv;
import std.file;
Expand All @@ -19,9 +17,8 @@ import std.exception;

void main(string[] args)
{
enforce(args.length > 2, "usage: words <file-name> <duplicates> [expected-result]");
string txt = cast(string) std.file.read(args[1]);
uint cnt = to!uint(args[2]);
string txt = cast(string)std.file.read(args.length > 1 ? args[1] : "extra-files/dante.txt");
uint cnt = args.length > 2 ? to!uint(args[2]) : 100;

string data;
for(int b = 31; b >= 0; b--)
Expand All @@ -32,8 +29,5 @@ void main(string[] args)
}

auto words = data.split().length;
writeln("words: ", words);

if(args.length > 3)
enforce(words == to!size_t(args[3]));
enforce(words == (args.length > 3 ? to!size_t(args[3]) : 9767600));
}

0 comments on commit 36ed59b

Please sign in to comment.