/mobile Handheld Friendly website
x64 Ubuntu : Intel® Q6600® one core |
Each table row shows performance measurements for this Java 7 program with a particular command-line input value N.
| N | CPU secs | Elapsed secs | Memory KB | Code B | ≈ CPU Load |
|---|---|---|---|---|---|
| 12 | 0.13 | 0.13 | ? | 1007 | 0% 0% 8% 100% |
| 16 | 0.80 | 0.82 | 142,924 | 1007 | 0% 1% 0% 100% |
| 20 | 20.06 | 20.11 | 545,544 | 1007 | 0% 0% 0% 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.
java version "1.7.0_11"
Java(TM) SE Runtime Environment (build 1.7.0_11-b21)
Java HotSpot(TM) 64-Bit Server VM (build 23.6-b04, mixed mode)
Compare to "Warmed" JVM timings using System.nanoTime() - see Help: What about Java?
/* The Computer Language Benchmarks Game http://benchmarksgame.alioth.debian.org/ contributed by Leonhard Holz based on contribution by Jarkko Miettinen */ public class binarytrees { private final static int minDepth = 4; private final static int threadCount = Runtime.getRuntime().availableProcessors() > 1 ? 2 : 1; private final static TreeGenerator[] threads = new TreeGenerator[threadCount + 1]; public static void main(String[] args) { int n = 0; if (args.length > 0) n = Integer.parseInt(args[0]); int maxDepth = (minDepth + 2 > n) ? minDepth + 2 : n; for (int i = 0; i < threadCount + 1; i++) { threads[i] = new TreeGenerator(); threads[i].start(); } TreeGenerator lastThread = threads[threadCount]; lastThread.depth = maxDepth + 1; lastThread.run = true; try { synchronized(lastThread) { lastThread.notify(); lastThread.wait(); } } catch (InterruptedException e) {} System.out.println("stretch tree of depth " + lastThread.depth + "\t check: " + lastThread.result); lastThread.depth = maxDepth; lastThread.run = true; try { synchronized(lastThread) { lastThread.notify(); lastThread.wait(); } } catch (InterruptedException e) {} for (int depth = minDepth; depth <= maxDepth; depth+=2 ) { int check = 0; int iterations = 1 << (maxDepth - depth + minDepth); int length = iterations / threadCount; for (int i = 0; i < threadCount; i++) synchronized(threads[i]) { threads[i].depth = depth; threads[i].start = i * length; threads[i].end = (i + 1) * length; threads[i].run = true; threads[i].notify(); } for (int i = 0; i < threadCount; i++) try { synchronized(threads[i]) { if (threads[i].run) threads[i].wait(); } check += threads[i].result; } catch (InterruptedException e) {} System.out.println((iterations * 2) + "\t trees of depth " + depth + "\t check: " + check); } System.out.println("long lived tree of depth " + maxDepth + "\t check: "+ lastThread.result); for (int i = 0; i < threadCount + 1; i++) { threads[i].terminate = true; synchronized(threads[i]) { threads[i].notify(); } } } private static class TreeGenerator extends Thread { private boolean run = false; private boolean terminate = false; private int start = 0; private int end = 0; private int result = 0; private int depth; private static TreeNode bottomUpTree(int item, int depth) { TreeNode node = new TreeNode(); node.item = item; if (depth > 0) { node.left = bottomUpTree(2 * item - 1, depth - 1); node.right = bottomUpTree(2 * item, depth - 1); } else { node.left = null; } return node; } private static int checkItems(TreeNode node) { if (node.left == null) { return node.item; } else { return node.item + checkItems(node.left) - checkItems(node.right); } } public synchronized void run() { while (!terminate) { if (run) { result = 0; if (start == end) { result += checkItems(bottomUpTree(start, depth)); } else for (int i = start; i < end; i++) { result += checkItems(bottomUpTree(i, depth)) + checkItems(bottomUpTree(-i, depth)); } run = false; notify(); } try { wait(); } catch (InterruptedException e) {} } } } private static class TreeNode { private int item; private TreeNode left, right; } }
Sun, 20 Jan 2013 16:47:14 GMT MAKE: mv binarytrees.java binarytrees.java mv: `binarytrees.java' and `binarytrees.java' are the same file make: [binarytrees.java_run] Error 1 (ignored) /usr/local/src/jdk1.7.0_11/bin/javac binarytrees.java 0.74s to complete and log all make actions COMMAND LINE: /usr/local/src/jdk1.7.0_11/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