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
5003.301.6251,232762  45% 42% 44% 77%
3,00015.524.7453,352762  85% 80% 86% 78%
5,50044.9412.1653,128762  91% 91% 91% 98%

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

Read spectral-norm benchmark to see what this program should do.


java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) Server VM (build 25.45-b02, mixed mode)

Clojure 1.7.0

 spectral-norm Clojure #7 program source code

;; The Computer Language Benchmarks Game
;; contributed by Jim Kannampuzha
;; inspired by Jesse Rosenstock

(ns spectralnorm

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

(defmacro eval-a [i j]
  `(let [n# (unchecked-add ~i ~j)
         nn+1# (unchecked-multiply n# (unchecked-inc n#))]
     (/ (double 1.0) (unchecked-add (bit-shift-right nn+1# 1)
				    (unchecked-inc ~i)))))

(defn multiply-a-v [agent ^doubles v ^doubles av range]
  (let [end (int (second range))]
    (loop [i (int (first range))]
      (if (= i end)
	  (aset av i (double (areduce v j sum (double 0)
				      (+ sum (* (eval-a i j) (aget v j))))))
	  (recur (unchecked-inc i)))))))

(defn multiply-at-v [agent ^doubles v ^doubles atv range]
  (let [end (int (second range))]
    (loop [i (int (first range))]
      (if (= i end) 
	  (aset atv i (double (areduce v j sum (double 0)
				       (+ sum (* (eval-a j i) (aget v j))))))
	  (recur (unchecked-inc i)))))))

(defn multiply-at-a-v [^doubles v ^doubles tmp ^doubles at-av workers ranges]
  (apply await (map #(send %1 multiply-a-v v tmp %2) workers ranges))
  (apply await (map #(send %1 multiply-at-v tmp at-av %2) workers ranges)))

(defmacro dot-product [^doubles u ^doubles v]
  `(areduce ~u i# sum# (double 0) (+ sum# (* (aget ~u i#) (aget ~v i#)))))

(defn run-game [size]
  (let [num-threads (.availableProcessors (Runtime/getRuntime))
        workers (vec (repeatedly num-threads #(agent ())))
        chunk-size (int (Math/ceil (/ size num-threads)))
        ranges  (vec (partition 2 1 (take (inc num-threads)
                                          (iterate #(+ chunk-size %) 0))))
        u (double-array size 1.0)
        tmp (double-array size 0.0)
        v (double-array size 0.0)]
    (dotimes [_ 10]
      (multiply-at-a-v u tmp v workers ranges)
      (multiply-at-a-v v tmp u workers ranges))
    (Math/sqrt (/ (dot-product u v) (dot-product v v)))))

(defn -main [& args]
  (let [n (if (empty? args)
            (Integer/valueOf ^String (first args)))]
    (println (format "%.9f" (run-game n)))

 make, command-line, and program output logs

Tue, 30 Jun 2015 23:29:17 GMT

mv spectralnorm.clojure-7.clojure spectralnorm.clj
/usr/local/src/jdk1.8.0_45/bin/java -Dclojure.compile.path=. -cp .:/usr/local/src/clojure/clojure-1.7.0.jar clojure.lang.Compile spectralnorm
Picked up JAVA_TOOL_OPTIONS: -javaagent:/usr/share/java/jayatanaag.jar 
Compiling spectralnorm to .
2.01s to complete and log all make actions

/usr/local/src/jdk1.8.0_45/bin/java -server -XX:+TieredCompilation -XX:+AggressiveOpts -Xmx8m -cp .:/usr/local/src/clojure/clojure-1.7.0.jar spectralnorm 5500


Picked up JAVA_TOOL_OPTIONS: -javaagent:/usr/share/java/jayatanaag.jar 

Revised BSD license

  Home   Conclusions   License   Play