/mobile Handheld Friendly website

 performance measurements

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

 N  CPU secs Elapsed secs Memory KB Code B ≈ CPU Load
1212.354.80117,160709  92% 42% 74% 53%
1614.215.30128,292709  72% 73% 48% 77%
20127.4652.57230,304709  67% 54% 57% 66%

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

Read binary-trees-redux 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) Server VM (build 25.0-b70, mixed mode)

Clojure 1.6.0

 binary-trees-redux Clojure #6 program source code

;; The Computer Language Benchmarks Game

;; http://benchmarksgame.alioth.debian.org/

;

;; Adapted from the Java -server version

;

;; contributed by Marko Kocic

;; modified by Kenneth Jonsson, restructured to allow usage of 'pmap'

;; modified by Andy Fingerhut to use faster primitive math ops, and

;; deftype instead of defrecord for smaller tree nodes.

;; modified by Mike Anderson to avoid boxing overheads


(ns binarytreesredux
  (:gen-class))

(set! *warn-on-reflection* true)

;; These TreeNode's take up noticeably less memory than a similar one

;; implemented using defrecord.


(deftype TreeNode [left right ^int item])

(defn ^:static bottom-up-tree [^long item ^long depth]
  (let [int-item (int item)
        int-depth (int depth)]
    (if (<= depth 0)
      (TreeNode. nil nil int-item)
      (TreeNode.
       (bottom-up-tree (unchecked-dec (unchecked-multiply (int 2) int-item))
                       (unchecked-dec int-depth))
       (bottom-up-tree (unchecked-multiply (int 2) int-item)
                       (unchecked-dec int-depth))
       int-item))))

(defn ^:static item-check ^long [^TreeNode node]
  (let [item (int (.item node))]
	  (if-not (.left node)
	    item
	    (unchecked-add 
         (unchecked-add 
           item 
           (unchecked-int (item-check (.left node))))
	       (unchecked-negate 
           (unchecked-int (item-check (.right node))))))))

    
(defn ^:static check-trees [^long i ^long acc ^long d]    
  (if (<= i 0)
    acc
    (let [value (unchecked-add 
                  (unchecked-int (item-check (bottom-up-tree i d)))
                  (unchecked-int (item-check (bottom-up-tree (- i) d))))]
      (recur (dec i) (+ acc value) d))))

(defn iterate-trees 
  ([mx mn d]
    (let [iterations (bit-shift-left 1 (int (+ mx mn (- d))))]
      (format "%d\t trees of depth %d\t check: %d" (* 2 iterations) d (check-trees iterations 0 d)))))

(def min-depth 4)

(defn main [max-depth]
  (let [stretch-depth (long (inc max-depth))]
    (let [tree (bottom-up-tree 0 stretch-depth)
          check (item-check tree)]
      (println (format "stretch tree of depth %d\t check: %d" stretch-depth check)))
    (let [long-lived-tree (bottom-up-tree 0 max-depth) ]
      ;; The following line is where Kenneth Jonsson used pmap.  On a

      ;; 1-core machine, I have found significantly less user+system

      ;; CPU time used when it is map, and slightly less elapsed time

      ;; (at the cost of more user+system CPU time) when it is pmap.

      (doseq [trees-nfo (map (fn [d]
                                (iterate-trees max-depth min-depth d))
			      (range min-depth stretch-depth 2)) ]
        (println trees-nfo))
      (println (format "long lived tree of depth %d\t check: %d" max-depth (item-check long-lived-tree))))))

(defn -main [& args]
  (let [n (if (first args) (Integer/parseInt (first args)) 0)
        max-depth (if (> (+ min-depth 2) n) (+ min-depth 2) n)]
    (main max-depth)
    (shutdown-agents)))

 make, command-line, and program output logs

Wed, 26 Mar 2014 03:38:28 GMT

MAKE:
mv binarytreesredux.clojure-6.clojure binarytreesredux.clj
/usr/local/src/jdk1.8.0/bin/java -Dclojure.compile.path=. -cp .:/usr/local/src/clojure/clojure-1.6.0-slim.jar clojure.lang.Compile binarytreesredux
Compiling binarytreesredux to .
4.34s to complete and log all make actions

COMMAND LINE:
/usr/local/src/jdk1.8.0/bin/java -server -XX:+TieredCompilation -XX:+AggressiveOpts -Xms176m -Xmx176m -cp .:/usr/local/src/clojure/clojure-1.6.0-slim.jar binarytreesredux 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