mirror of https://github.com/status-im/timbre.git
Print seconds to 1 decimal place
This commit is contained in:
parent
b07c044004
commit
b6b447ca9a
|
@ -1,7 +1,8 @@
|
|||
(ns taoensso.timbre.profiling
|
||||
"Simple all-Clojure profiling adapted from clojure.contrib.profile."
|
||||
{:author "Peter Taoussanis"}
|
||||
(:require [taoensso.timbre :as timbre]))
|
||||
(:require [taoensso.timbre :as timbre]
|
||||
[taoensso.timbre.utils :as utils]))
|
||||
|
||||
(def ^:dynamic *plog* "{::pname [time1 time2 ...] ...}" nil)
|
||||
|
||||
|
@ -67,11 +68,11 @@
|
|||
ft (fn [nanosecs]
|
||||
(let [pow #(Math/pow 10 %)
|
||||
ok-pow? #(>= nanosecs (pow %))
|
||||
to-pow #(long (/ nanosecs (pow %)))]
|
||||
(cond (ok-pow? 9) (str (to-pow 9) "s")
|
||||
(ok-pow? 6) (str (to-pow 6) "ms")
|
||||
(ok-pow? 3) (str (to-pow 3) "μs")
|
||||
:else (str (long nanosecs) "ns"))))]
|
||||
to-pow #(utils/round-to (/ nanosecs (pow %1)) %2)]
|
||||
(cond (ok-pow? 9) (str (to-pow 9 1) "s")
|
||||
(ok-pow? 6) (str (to-pow 6 0) "ms")
|
||||
(ok-pow? 3) (str (to-pow 3 0) "μs")
|
||||
:else (str nanosecs "ns"))))]
|
||||
|
||||
(with-out-str
|
||||
(printf s-pattern "Name" "Calls" "Min" "Max" "MAD" "Mean" "Time%" "Time")
|
||||
|
|
|
@ -35,3 +35,14 @@
|
|||
"Partial of `deep-merge-with`."
|
||||
[& maps]
|
||||
(apply deep-merge-with (fn [x y] y) maps))
|
||||
|
||||
(defn round-to
|
||||
"Rounds argument to given number of decimal places."
|
||||
[x places]
|
||||
(if (zero? places)
|
||||
(Math/round (double x))
|
||||
(let [modifier (Math/pow 10.0 places)]
|
||||
(/ (Math/round (* x modifier)) modifier))))
|
||||
|
||||
(comment (round-to 10 0)
|
||||
(round-to 10.123 2))
|
Loading…
Reference in New Issue