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

Commit

Permalink
Created test directory and moved gcBench into it, eliminating caps fo…
Browse files Browse the repository at this point in the history
…r filenames.
  • Loading branch information
complexmath committed Mar 25, 2011
1 parent b19b697 commit 5ab96a6
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 0 deletions.
12 changes: 12 additions & 0 deletions test/gcbench/huge_single.d
@@ -0,0 +1,12 @@
import std.stdio, std.datetime, 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);
}
21 changes: 21 additions & 0 deletions test/gcbench/rand_large.d
@@ -0,0 +1,21 @@
/**Benchmark on uniformly distributed, random large allocations.*/

import std.random, core.memory, std.datetime, 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);
}
21 changes: 21 additions & 0 deletions test/gcbench/rand_small.d
@@ -0,0 +1,21 @@
/**Benchmark on uniformly distributed, random small allocations.*/

import std.random, core.memory, std.datetime, 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);
}
17 changes: 17 additions & 0 deletions test/gcbench/runall.d
@@ -0,0 +1,17 @@
/**This is a driver script that runs the benchmarks.*/

import std.stdio, std.process;

void main() {
system("dmd -O -inline -release huge_single.d");
system("dmd -O -inline -release rand_large.d");
system("dmd -O -inline -release rand_small.d");
system("dmd -O -inline -release tree1.d");
system("dmd -O -inline -release tree2.d");

system("huge_single");
system("rand_large");
system("rand_small");
system("tree1");
system("tree2");
}
62 changes: 62 additions & 0 deletions test/gcbench/tree1.d
@@ -0,0 +1,62 @@
/**Benchmark the GC on tree building. Thanks to Bearophile.*/

import std.stdio, std.conv, std.datetime;

class TreeNode {
private TreeNode left, right;
private int item;

this(int item) {
this.item = item;
}

this(TreeNode left, TreeNode right, int item){
this.left = left;
this.right = right;
this.item = item;
}

private static TreeNode bottomUpTree(int item, int depth) {
if (depth > 0) {
return new TreeNode(bottomUpTree(2 * item - 1, depth - 1),
bottomUpTree(2 * item, depth - 1),
item);
} else {
return new TreeNode(item);
}
}

private int itemCheck() {
if (left is null)
return item;
else
return item + left.itemCheck() - right.itemCheck();
}
}


void main(string[] args) {
auto sw = StopWatch(autoStart);

enum int minDepth = 4;
enum n = 18;

int maxDepth = (minDepth + 2 > n) ? minDepth + 2 : n;
int stretchDepth = maxDepth + 1;

int check = (TreeNode.bottomUpTree(0,stretchDepth)).itemCheck();

TreeNode longLivedTree = TreeNode.bottomUpTree(0, maxDepth);

for (int depth = minDepth; depth <= maxDepth; depth += 2) {
int iterations = 1 << (maxDepth - depth + minDepth);
check = 0;

foreach (int i; 1 .. iterations+1) {
check += (TreeNode.bottomUpTree(i, depth)).itemCheck();
check += (TreeNode.bottomUpTree(-i, depth)).itemCheck();
}
}

writeln("Tree1: ", sw.peek.seconds, " seconds");
}
20 changes: 20 additions & 0 deletions test/gcbench/tree2.d
@@ -0,0 +1,20 @@
/**Another tree building benchmark. Thanks again to Bearophile.*/

import std.stdio, std.container, std.range, std.datetime;

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

auto t = RedBlackTree!int(0);

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

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

0 comments on commit 5ab96a6

Please sign in to comment.