This repository has been archived by the owner on Oct 12, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created test directory and moved gcBench into it, eliminating caps fo…
…r filenames.
- Loading branch information
1 parent
b19b697
commit 5ab96a6
Showing
6 changed files
with
153 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); | ||
} | ||
|