/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.228081007  0% 9% 0% 95%
160.880.89100,7521007  0% 1% 1% 100%
2023.6823.72471,3121007  1% 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)

Compare to "Warmed" JVM timings using System.nanoTime() - see Help: What about Java?

 binary-trees Java program source code

/* 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;
   }
}

 make, command-line, and program output logs

Wed, 19 Mar 2014 03:07:25 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.8.0/bin/javac binarytrees.java
0.85s 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