The Q6600
Benchmarks Game

binary-trees Java OpenJ9 #6 program

source code


/**
 * The Computer Language Benchmarks Game
 * https://salsa.debian.org/benchmarksgame-team/benchmarksgame/
 *
 * Loosely based on Jarkko Miettinen's implementation. Requires Java 8.
 *
 * contributed by Heikki Salokanto.
 * modified by Chandra Sekar
 * modified by Mike Krüger
 * *reset*
 */

public class binarytrees {
    public static void main(String[] args) throws Exception {
        int n = args.length > 0 ? Integer.parseInt(args[0]) : 0;
        int minDepth = 4;
        int maxDepth = Math.max(minDepth + 2, n);
        int stretchDepth = maxDepth + 1;
        int check = (TreeNode.create(stretchDepth)).check();
        
        System.out.println("stretch tree of depth " + (maxDepth + 1) + "\t check: " + check);

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

           for (int i = 1; i <= iterations; i++)
           {
                check += (TreeNode.create(depth)).check();
           }
           System.out.println(iterations + "\t trees of depth " + depth + "\t check: " + check);
        }

        System.out.println("long lived tree of depth " + maxDepth + "\t check: " + longLivedTree.check());
    }

    static class TreeNode {
        TreeNode left, right;

        static TreeNode create(int depth)
        {
            return ChildTreeNodes(depth);
        }
         
        static TreeNode ChildTreeNodes(int depth)
        {
            TreeNode node = new TreeNode();
            if (depth > 0)
            {
                node.left = ChildTreeNodes(depth - 1);
                node.right = ChildTreeNodes(depth - 1);
            }
            return node;
        }

        int check() {
            return left == null ? 1 : left.check() + right.check() + 1;
        }
    }
}
    

notes, command-line, and program output

NOTES:
64-bit Ubuntu quad core
openjdk 14 2020-03-17
OpenJDK Runtime Environment AdoptOpenJDK (build 14+36)
Eclipse OpenJ9 VM AdoptOpenJDK
build openj9-0.19.0 (JIT enabled, AOT enabled)



Tue, 05 May 2020 00:42:25 GMT

MAKE:
mv binarytrees.openj9-6.openj9 binarytrees.java
/opt/src/openj9-openjdk-14/bin/javac -d .  binarytrees.java

4.40s to complete and log all make actions

COMMAND LINE:
/opt/src/openj9-openjdk-14/bin/java -Xshareclasses   binarytrees 21

PROGRAM OUTPUT:
stretch tree of depth 22	 check: 8388607
2097152	 trees of depth 4	 check: 65011712
524288	 trees of depth 6	 check: 66584576
131072	 trees of depth 8	 check: 66977792
32768	 trees of depth 10	 check: 67076096
8192	 trees of depth 12	 check: 67100672
2048	 trees of depth 14	 check: 67106816
512	 trees of depth 16	 check: 67108352
128	 trees of depth 18	 check: 67108736
32	 trees of depth 20	 check: 67108832
long lived tree of depth 21	 check: 4194303