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
122.371.2473,560661  30% 32% 34% 98%
163.772.07128,260661  31% 66% 57% 32%
20106.3539.29245,344661  69% 84% 60% 60%

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.


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

Clojure 1.6

 binary-trees-redux Clojure program source code

;; The Computer Language Benchmarks Game



;; 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 Rich Hickey for Clojure 1.3

(ns binarytreesredux

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

(definterface ITreeNode
  (^long item [])
  (left [])
  (right []))

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

;; implemented using defrecord.

(deftype TreeNode [left right ^long item]
  (item [this] item)
  (left [this] left)
  (right [this] right))

(defn bottom-up-tree [^long item ^long depth]
  (if (zero? depth)
    (TreeNode. nil nil item)
     (bottom-up-tree (dec (* 2 item))
                     (dec depth))
     (bottom-up-tree (* 2 item)
                     (dec depth))

(defn item-check ^long [^TreeNode node]
  (if (nil? (.left node))
    (.item node)
    (+ (+ (.item node)
          (item-check (.left node)))
       (- (item-check (.right node))))))

(defn iterate-trees [^long mx ^long mn ^long d]
  (let [iterations (bit-shift-left 1 (- (+ mx mn) d))]
    (format "%d\t trees of depth %d\t check: %d" (* 2 iterations) d
            (reduce + (map (fn [i]
                             (+ (item-check (bottom-up-tree i d))
                                (item-check (bottom-up-tree (- i) d))))
                           (range 1 (inc iterations)))))))

(def min-depth 4)

(defn main [max-depth]
  (let [stretch-depth (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) ]
      (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)

 make, command-line, and program output logs

Wed, 19 Nov 2014 17:56:42 GMT

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

/usr/local/src/jdk1.8.0_25/bin/java -server -XX:+TieredCompilation -XX:+AggressiveOpts -Xms176m -Xmx176m -cp .:/usr/local/src/clojure/clojure-1.6.0.jar binarytreesredux 20

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