performance measurements

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

 N  CPU secs Elapsed secs Memory KB Code B ≈ CPU Load
120.250.25236549  0% 20% 0% 100%
161.011.0196,704549  1% 2% 0% 100%
2016.3116.33391,860549  1% 1% 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.

 notes

java version "1.8.0_25"
Java(TM) SE Runtime Environment (build 1.8.0_25-b17)
Java HotSpot(TM) Server VM (build 25.25-b02, mixed mode)

Scala compiler version 2.11.4 -- Copyright 2002-2013, LAMP/EPFL

NOT ACCEPTED: Leaf is different from other Nodes - doesn't allocate space.

 binary-trees Scala program source code

/* The Computer Language Benchmarks Game
   http://benchmarksgame.alioth.debian.org/

   contributed by Kannan Goundan
   modified by Isaac Gouy
   optimized by David Pollak
   updated to 2.8 by Rex Kerr
   modified by Piotr Tarsa
*/

sealed abstract class Node(i: Int, left: Node, right: Node) {
  def isum: Int
}
case class NonLeaf(i: Int, left: Node, right: Node) extends Node(i, left, right) {
  def isum: Int = i + left.isum - right.isum
}
case class Leaf(i: Int) extends Node(i, NullNode, NullNode) {
  def isum: Int = i
}
case object NullNode extends Node(0, new Leaf(0), new Leaf(0)) {
  def isum: Int = 0
}

object Tree {
  def apply(i: Int, depth: Int): Node = {
    if (depth > 0) NonLeaf(i, Tree(i * 2 - 1, depth - 1), Tree(i * 2, depth - 1))
    else Leaf(i)
  }
}

object binarytrees {
  def main(args: Array[String]) = {
    val n = try{ args(0).toInt } catch { case _ => 1 }
    val minDepth = 4
    val maxDepth = n max (minDepth + 2)

    def print(name: String, depth: Int, check: Int) =
      println(name + " of depth " + depth + "\t check: " + check)

    print("stretch tree", maxDepth + 1, Tree(0, maxDepth + 1).isum)
    val longLivedTree = Tree(0, maxDepth)
    minDepth to maxDepth by 2 foreach {
      depth =>
      val iterations = 1 << (maxDepth - depth + minDepth)
      var i, sum = 0
      while (i < iterations) {
        i += 1
        sum += Tree(i, depth).isum + Tree(-i, depth).isum
      }
      print(iterations *2  + "\t trees", depth, sum)
    }
    print("long lived tree", maxDepth, longLivedTree.isum)
  }
}

 make, command-line, and program output logs

Wed, 19 Nov 2014 05:47:18 GMT

MAKE:
mv binarytrees.scala binarytrees.scala
mv: ‘binarytrees.scala’ and ‘binarytrees.scala’ are the same file
make: [binarytrees.scala_run] Error 1 (ignored)
/usr/local/src/scala-2.11.4/bin/scalac -optimise -target:jvm-1.8 binarytrees.scala
binarytrees.scala:33: warning: This catches all Throwables. If this is really intended, use `case _ : Throwable` to clear this warning.
    val n = try{ args(0).toInt } catch { case _ => 1 }
                                              ^
one warning found
4.80s to complete and log all make actions

COMMAND LINE:
 /usr/local/src/jdk1.8.0_25/bin/java -server -XX:+TieredCompilation -XX:+AggressiveOpts  -Xbootclasspath/a:/usr/local/src/scala-2.11.4/lib/scala-library.jar:/usr/local/src/scala-2.11.4/lib/akka-actors.jar:/usr/local/src/scala-2.11.4/lib/typesafe-config.jar 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