Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
fix benchmarks
Browse files Browse the repository at this point in the history
 - The gcbenchs didn't compile due to changes in StopWatch.
 - I replaced the runall with a slightly more sophisticated runner
 - Stoping the time it takes to call system instead of
   stopping from within the program also measures the final
   GC collection.

 - You can run the tests with 'rdmd runbench' optionally
   giving a regex to match a subset of tests.
  • Loading branch information
MartinNowak committed Oct 12, 2011
1 parent 374ccc1 commit 8fe8bab
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 53 deletions.
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
6 changes: 1 addition & 5 deletions test/gcbench/huge_single.d
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,11 @@
* (See accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*/
import std.stdio, std.datetime, core.memory;
import std.stdio, core.memory;

void main(string[] args) {
enum mul = 1000;
auto ptr = GC.malloc(mul * 1_048_576, GC.BlkAttr.NO_SCAN);

auto sw = StopWatch(autoStart);
GC.collect();
immutable msec = sw.peek.msecs;
writefln("HugeSingle: Collected a %s megabyte heap in %s milliseconds.",
mul, msec);
}
6 changes: 1 addition & 5 deletions test/gcbench/rand_large.d
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,18 @@
* (See accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*/
import std.random, core.memory, std.datetime, std.stdio;
import std.random, core.memory, std.stdio;

enum nIter = 1000;

void main() {
auto ptrs = new void*[1024];

auto sw = StopWatch(autoStart);

// Allocate 1024 large blocks with size uniformly distributed between 1
// and 128 kilobytes.
foreach(i; 0..nIter) {
foreach(ref ptr; ptrs) {
ptr = GC.malloc(uniform(1024, 128 * 1024 + 1), GC.BlkAttr.NO_SCAN);
}
}

writefln("RandLarge: Done %s iter in %s milliseconds.", nIter, sw.peek.msecs);
}
6 changes: 1 addition & 5 deletions test/gcbench/rand_small.d
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,18 @@
* (See accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*/
import std.random, core.memory, std.datetime, std.stdio;
import std.random, core.memory, std.stdio;

enum nIter = 1000;

void main() {
auto ptrs = new void*[4096];

auto sw = StopWatch(autoStart);

// Allocate 1024 large blocks with size uniformly distributed between 8
// and 2048 bytes.
foreach(i; 0..nIter) {
foreach(ref ptr; ptrs) {
ptr = GC.malloc(uniform(8, 2048), GC.BlkAttr.NO_SCAN);
}
}

writefln("RandSmall: Done %s iter in %s milliseconds.", nIter, sw.peek.msecs);
}
28 changes: 0 additions & 28 deletions test/gcbench/runall.d

This file was deleted.

6 changes: 1 addition & 5 deletions test/gcbench/tree1.d
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* (See accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*/
import std.stdio, std.conv, std.datetime;
import std.stdio, std.conv;

class TreeNode {
private TreeNode left, right;
Expand Down Expand Up @@ -47,8 +47,6 @@ class TreeNode {


void main(string[] args) {
auto sw = StopWatch(AutoStart.yes);

enum int minDepth = 4;
enum n = 18;

Expand All @@ -68,6 +66,4 @@ void main(string[] args) {
check += (TreeNode.bottomUpTree(-i, depth)).itemCheck();
}
}

writeln("Tree1: ", sw.peek.seconds, " seconds");
}
7 changes: 2 additions & 5 deletions test/gcbench/tree2.d
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,18 @@
* (See accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*/
import std.stdio, std.container, std.range, std.datetime;
import std.stdio, std.container, std.range;

void main() {
auto sw = StopWatch(autoStart);
enum int range = 100;
enum int n = 1_000_000;

auto t = RedBlackTree!int(0);
auto t = redBlackTree!int();

for (int i = 0; i < n; i++) {
if (i > range)
t.removeFront();
t.insert(i);
}

writeln("Tree2: ", sw.peek.seconds, " seconds");
}

75 changes: 75 additions & 0 deletions test/runbench.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/**
* This is a driver script that runs the benchmarks.
*
* Copyright: Copyright David Simcha 2011 - 2011.
* License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
* Authors: David Simcha
*/

/* Copyright David Simcha 2011 - 2011.
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*/
import std.datetime, std.exception, std.file, std.getopt,
std.path, std.process, std.regex, std.stdio, std.string, std.typecons;

// cmdline flags
bool verbose;

void runCmd(string cmd)
{
if (verbose)
writeln(cmd);
enforce(!system(cmd));
}

void runTest(string pattern)
{
string[] sources;
auto re = regex(pattern, "g");
auto self = buildPath(curdir, "runbench.d");
foreach(DirEntry src; dirEntries(curdir, SpanMode.depth))
{
if (src.isFile && !match(src.name, re).empty &&
endsWith(src.name, ".d") && src.name != self)
{
sources ~= src.name;
}
}

foreach(ref src; sources)
{
writeln("COMPILING ", src);
auto bin = buildPath("bin", src.chomp(".d"));
runCmd("dmd -O -release -inline -op -odobj -of" ~ bin ~ " " ~ src);
src = bin;
}

foreach(bin; sources)
{
StopWatch sw;

version (Windows)
bin = bin.chompPrefix("./");

writeln("RUNNING ", baseName(bin));
sw.start;
runCmd(bin);
sw.stop;

auto p = sw.peek;
writefln(" took %s.%s sec.", p.seconds, p.msecs % 1000);
sw.reset;
}
}

void main(string[] args) {
getopt(args,
"verbose|v", &verbose,
);

args = args[1 .. $];
foreach(arg; args.length ? args : [r".*\.d"])
runTest(arg);
}

0 comments on commit 8fe8bab

Please sign in to comment.