1 // Written by Piotr Modzelewski <http://petermodzelewski.blogspot.com/>
2 // Found at http://www.dsource.org/projects/tango/wiki/GCBenchmark
8 this(int item, TreeNode left=null, TreeNode right=null) {
15 return left is null ? item : item + left.check - right.check;
19 TreeNode makeTree(int item, int depth) {
21 return new TreeNode(item, makeTree(2*item-1, depth-1),
22 makeTree(2*item, depth-1));
24 return new TreeNode(item);
27 void main(char[][] args) {
30 int maxDepth = (minDepth + 2) > n ? minDepth + 2 : n;
32 int check = makeTree(0, maxDepth + 1).check;
34 auto longLivedTree = makeTree(0, maxDepth);
36 for (int depth = minDepth; depth <= maxDepth; depth += 2) {
37 int iterations = 1 << (maxDepth - depth + minDepth);
40 for (int i = 1; i <= iterations; i++)
41 check += (makeTree(i, depth)).check
42 + (makeTree(-i, depth)).check;