Housekeeping: profiling & freqs

This commit is contained in:
Peter Taoussanis 2013-07-20 00:29:08 +07:00
parent ce9ea0ac76
commit 807cb40e0f
2 changed files with 17 additions and 17 deletions

View File

@ -69,9 +69,8 @@
sorted-fvs (sorted-fvals form-stats)] sorted-fvs (sorted-fvals form-stats)]
(str fname " " (str fname " "
(str/join " " (str/join " "
;; TODO mapv Clojure 1.4+ (mapv (fn [v] (vector v (get form-stats v 0)))
(vec (map (fn [v] (vector v (get form-stats v 0))) sorted-fvs))))))))
sorted-fvs)))))))))
(comment (format-fdata {:name1 {:a 10 :b 4 :c 20} (comment (format-fdata {:name1 {:a 10 :b 4 :c 20}
:name2 {33 8 12 2 false 6}})) :name2 {33 8 12 2 false 6}}))

View File

@ -66,20 +66,21 @@
For performance, stats are calculated once only after all data have been For performance, stats are calculated once only after all data have been
collected." collected."
[pdata] [pdata]
(reduce (fn [m [pname times]] ; TODO reduce-kv for Clojure 1.4+ (reduce-kv
(let [count (count times) (fn [m pname times]
time (reduce + times) (let [count (max 1 (count times))
mean (long (/ time count)) time (reduce + times)
mad (long (/ (reduce + (map #(Math/abs (long (- % mean))) mean (long (/ time count))
times)) ; Mean absolute deviation mad (long (/ (reduce + (map #(Math/abs (long (- % mean)))
count))] times)) ; Mean absolute deviation
(assoc m pname {:count count count))]
:min (apply min times) (assoc m pname {:count count
:max (apply max times) :min (apply min times)
:mean mean :max (apply max times)
:mad mad :mean mean
:time time}))) :mad mad
{} pdata)) :time time})))
{} (or pdata {})))
(defn format-pdata (defn format-pdata
[stats & [sort-field]] [stats & [sort-field]]