From 807cb40e0f5f1d7efec1a1d7f1299755f57f538b Mon Sep 17 00:00:00 2001 From: Peter Taoussanis Date: Sat, 20 Jul 2013 00:29:08 +0700 Subject: [PATCH] Housekeeping: profiling & freqs --- src/taoensso/timbre/frequencies.clj | 5 ++--- src/taoensso/timbre/profiling.clj | 29 +++++++++++++++-------------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/taoensso/timbre/frequencies.clj b/src/taoensso/timbre/frequencies.clj index d161db4..6014a2f 100644 --- a/src/taoensso/timbre/frequencies.clj +++ b/src/taoensso/timbre/frequencies.clj @@ -69,9 +69,8 @@ sorted-fvs (sorted-fvals form-stats)] (str fname " " (str/join " " - ;; TODO mapv Clojure 1.4+ - (vec (map (fn [v] (vector v (get form-stats v 0))) - sorted-fvs))))))))) + (mapv (fn [v] (vector v (get form-stats v 0))) + sorted-fvs)))))))) (comment (format-fdata {:name1 {:a 10 :b 4 :c 20} :name2 {33 8 12 2 false 6}})) diff --git a/src/taoensso/timbre/profiling.clj b/src/taoensso/timbre/profiling.clj index 1c1f475..66cbf78 100644 --- a/src/taoensso/timbre/profiling.clj +++ b/src/taoensso/timbre/profiling.clj @@ -66,20 +66,21 @@ For performance, stats are calculated once only after all data have been collected." [pdata] - (reduce (fn [m [pname times]] ; TODO reduce-kv for Clojure 1.4+ - (let [count (count times) - time (reduce + times) - mean (long (/ time count)) - mad (long (/ (reduce + (map #(Math/abs (long (- % mean))) - times)) ; Mean absolute deviation - count))] - (assoc m pname {:count count - :min (apply min times) - :max (apply max times) - :mean mean - :mad mad - :time time}))) - {} pdata)) + (reduce-kv + (fn [m pname times] + (let [count (max 1 (count times)) + time (reduce + times) + mean (long (/ time count)) + mad (long (/ (reduce + (map #(Math/abs (long (- % mean))) + times)) ; Mean absolute deviation + count))] + (assoc m pname {:count count + :min (apply min times) + :max (apply max times) + :mean mean + :mad mad + :time time}))) + {} (or pdata {}))) (defn format-pdata [stats & [sort-field]]