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
|
(ns taoensso.timbre.profiling
|
||||||
"Simple all-Clojure profiling adapted from clojure.contrib.profile."
|
"Simple all-Clojure profiling adapted from clojure.contrib.profile."
|
||||||
{:author "Peter Taoussanis"}
|
{: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)
|
(def ^:dynamic *plog* "{::pname [time1 time2 ...] ...}" nil)
|
||||||
|
|
||||||
|
@ -67,11 +68,11 @@
|
||||||
ft (fn [nanosecs]
|
ft (fn [nanosecs]
|
||||||
(let [pow #(Math/pow 10 %)
|
(let [pow #(Math/pow 10 %)
|
||||||
ok-pow? #(>= nanosecs (pow %))
|
ok-pow? #(>= nanosecs (pow %))
|
||||||
to-pow #(long (/ nanosecs (pow %)))]
|
to-pow #(utils/round-to (/ nanosecs (pow %1)) %2)]
|
||||||
(cond (ok-pow? 9) (str (to-pow 9) "s")
|
(cond (ok-pow? 9) (str (to-pow 9 1) "s")
|
||||||
(ok-pow? 6) (str (to-pow 6) "ms")
|
(ok-pow? 6) (str (to-pow 6 0) "ms")
|
||||||
(ok-pow? 3) (str (to-pow 3) "μs")
|
(ok-pow? 3) (str (to-pow 3 0) "μs")
|
||||||
:else (str (long nanosecs) "ns"))))]
|
:else (str nanosecs "ns"))))]
|
||||||
|
|
||||||
(with-out-str
|
(with-out-str
|
||||||
(printf s-pattern "Name" "Calls" "Min" "Max" "MAD" "Mean" "Time%" "Time")
|
(printf s-pattern "Name" "Calls" "Min" "Max" "MAD" "Mean" "Time%" "Time")
|
||||||
|
|
|
@ -34,4 +34,15 @@
|
||||||
(defn deep-merge
|
(defn deep-merge
|
||||||
"Partial of `deep-merge-with`."
|
"Partial of `deep-merge-with`."
|
||||||
[& maps]
|
[& maps]
|
||||||
(apply deep-merge-with (fn [x y] y) 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