/mobile Handheld Friendly website

 performance measurements

Each table row shows performance measurements for this Java program with a particular command-line input value N.

 N  CPU secs Elapsed secs Memory KB Code B ≈ CPU Load
120.210.21432584  0% 0% 0% 95%
160.930.9397,816584  0% 3% 1% 100%
2023.1023.14450,320584  0% 1% 1% 100%

Read the ↓ make, command line, and program output logs to see how this program was run.

Read binary-trees benchmark to see what this program should do.

 notes

java version "1.8.0"
Java(TM) SE Runtime Environment (build 1.8.0-b132)
Java HotSpot(TM) 64-Bit Server VM (build 25.0-b70, mixed mode)

 binary-trees Java #3 program source code

/* The Computer Language Benchmarks Game
 * http://benchmarksgame.alioth.debian.org/
 *
 * contributed by Jarkko Miettinen
 * modified by Daryl Griffith
*/

public class binarytrees {

    public static void main(String[] args) {
        int maxDepth;
        
        {
            int n = 0;
            
            if (args.length > 0) {
                n = Integer.parseInt(args[0]);
            }
            maxDepth = (6 > n) ? 6 : n;
        }
        {
            int stretchDepth = maxDepth + 1;

            System.out.println("stretch tree of depth " + stretchDepth + 
		"\t check: " + checkTree(createTree(0, stretchDepth)));
        }
        trees(maxDepth);
    }
    
    public static void trees(int maxDepth) {
        TreeNode longLastingNode = createTree(0, maxDepth);
        int depth = 4;

        do {
            int iterations = 16 << (maxDepth - depth);

            loops(iterations, depth);
            depth += 2;
        } while (depth <= maxDepth);
        System.out.println("long lived tree of depth " + maxDepth
		 + "\t check: " + checkTree(longLastingNode));
    }
    
    public static void loops(int iterations, int depth) {
        int check = 0;
        int item = 0;

        do {
            check += checkTree(createTree(item, depth)) +
		 checkTree(createTree(-item, depth));
            item++;
        } while (item < iterations);
        System.out.println((iterations << 1) + "\t trees of depth " +
		depth + "\t check: " + check);
    }
    
    public static TreeNode createTree(int item, int depth) {
        TreeNode node = new TreeNode();

        node.item = item;
        if (depth > 0) {
            item = item + item;
            depth--;
            node.left = createTree(item - 1, depth);
            node.right = createTree(item, depth);
        }
        return node;
    }
    
    public static int checkTree(TreeNode node) {
        if (node.left == null) {
            return node.item;
        }
        return checkTree(node.left) - checkTree(node.right) + node.item;
    }

    public static class TreeNode {

        private int item;
        private TreeNode left, right;
    }
}

 make, command-line, and program output logs

Wed, 19 Mar 2014 03:05:01 GMT

MAKE:
mv binarytrees.java-3.java binarytrees.java
/usr/local/src/jdk1.8.0/bin/javac binarytrees.java
0.80s to complete and log all make actions

COMMAND LINE:
/usr/local/src/jdk1.8.0/bin/java  -server -XX:+TieredCompilation -XX:+AggressiveOpts binarytrees 20

PROGRAM OUTPUT:
stretch tree of depth 21	 check: -1
2097152	 trees of depth 4	 check: -2097152
524288	 trees of depth 6	 check: -524288
131072	 trees of depth 8	 check: -131072
32768	 trees of depth 10	 check: -32768
8192	 trees of depth 12	 check: -8192
2048	 trees of depth 14	 check: -2048
512	 trees of depth 16	 check: -512
128	 trees of depth 18	 check: -128
32	 trees of depth 20	 check: -32
long lived tree of depth 20	 check: -1

Revised BSD license

  Home   Conclusions   License   Play