Skip to content

Commit

Permalink
chore: clean up boxed warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
hugoduncan committed Dec 30, 2024
1 parent 737448a commit e4f0a04
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 37 deletions.
4 changes: 2 additions & 2 deletions bases/criterium/src/criterium/collect_plan/impl.clj
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
(println " or consider benchmarks at a lower level.")
[(max 10 (long (* (long num-warmup-samples) frac)))
(max 10 (long (* (long num-measure-samples) frac)))])
[(max 1 num-warmup-samples)
(max 1 num-measure-samples)]))
[(max 1 (long num-warmup-samples))
(max 1 (long num-measure-samples))]))
34 changes: 17 additions & 17 deletions bases/criterium/src/criterium/util/format.clj
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,29 @@
(defmethod scale :time ; seconds
[_ value]
(cond
(> value 60) [(/ 60) "min"]
(< value 1e-6) [1e9 "ns"]
(< value 1e-3) [1e6 "µs"]
(< value 1) [1e3 "ms"]
:else [1 "s"]))
(> (long value) 60) [(/ 60) "min"]
(< (long value) 1e-6) [1e9 "ns"]
(< (long value) 1e-3) [1e6 "µs"]
(< (long value) 1) [1e3 "ms"]
:else [1 "s"]))

(def ONE-KB 1024)
(def ONE-MB (* 1024 1024))
(def ONE-GB (* 1024 1024 1024))
(def ^:const ONE-KB 1024)
(def ^:const ONE-MB (* 1024 1024))
(def ^:const ONE-GB (* 1024 1024 1024))

(defmethod scale :memory
[_ value]
(cond
(< value ONE-KB) [1 "bytes"]
(< value ONE-MB) [(/ ONE-KB) "Kb"]
(< value ONE-GB) [(/ ONE-MB) "Mb"]
:else [(/ ONE-GB) "Gb"]))
(< (long value) ONE-KB) [1 "bytes"]
(< (long value) ONE-MB) [(/ ONE-KB) "Kb"]
(< (long value) ONE-GB) [(/ ONE-MB) "Mb"]
:else [(/ ONE-GB) "Gb"]))

(defn format-scaled
([value scale]
(format "%3.3g" (double (* scale value))))
(format "%3.3g" (double (* (double scale) (double value)))))
([value scale unit]
(format "%3.3g %s" (double (* scale value)) unit)))
(format "%3.3g %s" (double (* (double scale) (double value))) unit)))

(defmulti format-value
"Format value to 3 significant figures in an appropriate unit for the scale."
Expand All @@ -51,20 +51,20 @@
(defmethod format-value :time
[dimension value]
(let [[scale unit] (scale dimension value)]
(format "%3.3g %s" (double (* scale value)) unit)))
(format "%3.3g %s" (double (* (double scale) (double value))) unit)))

(defmethod format-value :memory
[dimension value]
(let [[scale unit] (scale dimension value)]
(format "%3.3f %s" (double (* scale value)) unit)))
(format "%3.3f %s" (double (* (double scale) (double value))) unit)))

(defmulti format-metric
#_{:clj-kondo/ignore [:unused-binding]}
(fn [metric val] metric))

(defmethod format-metric :elapsed-time
[_ val]
(let [v (/ val 1e9)]
(let [v (/ (double val) 1e9)]
(format "%32s: %s\n" "Elapsed time" (format-value :time v))))

(defn- format-count-time [[k {c :count t :time}]]
Expand Down
1 change: 1 addition & 0 deletions bases/criterium/src/criterium/util/helpers.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
(ns criterium.util.helpers
(:refer-clojure :exclude [update-vals])
(:require
[clojure.set :as set]
[criterium.util.invariant :refer [have?]]
Expand Down
21 changes: 10 additions & 11 deletions bases/criterium/src/criterium/viewer/common.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
[clojure.string :as str]
[criterium.metric :as metric]
[criterium.util.format :as format]
[criterium.util.invariant :refer [have?]]
[criterium.util.helpers :as util]))
[criterium.util.invariant :refer [have?]]))

(defn metrics-map
[sample metrics]
Expand All @@ -14,8 +13,8 @@
{:metric (:label metric)
:value (format/format-value
(:dimension metric)
(* (first (sample (:path metric)))
(:scale metric)))}))
(* (double (first (sample (:path metric))))
(double (:scale metric))))}))
[]
metrics))

Expand All @@ -30,8 +29,8 @@
(assoc res k
(format/format-value
(:dimension metric)
(* (get stat k)
(:scale metric)))))
(* (double (get stat k))
(double (:scale metric))))))
{:metric (:label metric)}
[:mean :min-val :mean-minus-3sigma :mean-plus-3sigma :max-val]))))
[]
Expand All @@ -45,15 +44,15 @@
{:post [(have? (some-fn nil? map?) %)]}
(let [sample-count-path (conj (pop (:path (first ms))) :sample-count)
sample-count (event-stats sample-count-path)]
(when (and sample-count (pos? sample-count))
(when (and sample-count (pos? (long sample-count)))
(reduce
(fn [res m]
(assoc res
(composite-key (rest (:path m)))
(format/format-value
(:dimension m)
(* (get event-stats (:path m))
(:scale m)))))
(* (double (get event-stats (:path m)))
(double (:scale m))))))
{:metric (:label metric)}
(into [{:path sample-count-path
:dimension :count
Expand Down Expand Up @@ -87,7 +86,7 @@
q
(format/format-value
(:dimension metric-config)
(* v (:scale metric-config)))))
(* (double v) (double (:scale metric-config))))))
{:metric (:label metric-config)}
quantiles))))
[]
Expand All @@ -110,7 +109,7 @@
(assoc
(select-keys sampled [:batch-size :num-samples])
:num-evals
(* (:num-samples sampled) (:batch-size sampled)))))
(* (long (:num-samples sampled)) (long (:batch-size sampled))))))

(defn collect-plan-data
[bench-map]
Expand Down
17 changes: 11 additions & 6 deletions bases/criterium/src/criterium/viewer/portal.clj
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
(ns criterium.viewer.portal
"A viewer that outputs to portal using tap>."
(:refer-clojure :exclude [flush])
(:require
[criterium.metric :as metric]
[criterium.util.helpers :as util]
Expand Down Expand Up @@ -192,7 +193,7 @@
(let [sigma (Math/sqrt variance)
#_#_min-val (* min-val 0.9)
#_#_sigma (Math/abs sigma)
delta (/ (- max-val min-val) 120)
delta (/ (- (double max-val) (double min-val)) 120)
pdf (probability/normal-pdf mean sigma)]
(mapv
(fn [z]
Expand Down Expand Up @@ -236,7 +237,7 @@
(fn [res metric-config]
(let [path (:path metric-config)
v (get (get events path) index)]
(if (pos? v)
(if (pos? (long v))
(assoc res (viewer-common/composite-key path) v :index index)
res)))
nil
Expand Down Expand Up @@ -371,10 +372,12 @@
n (count vs)
max-val (Math/log10 (double n))
xs (mapv
#(/ (- max-val (Math/log10 (- n %))) max-val)
#(/ (- max-val (Math/log10 (- n (double %)))) max-val)
(range 0 n))
delta (/ 100.0 (dec n))
percentiles (take n (iterate #(+ delta %) 0))
percentiles (take n
(iterate
#(+ delta (double %)) 0))
data (mapv
#(hash-map k %1 :p %2 :x %3)
vs
Expand Down Expand Up @@ -436,8 +439,10 @@
vs (->> (get samples path)
sort
vec)
min-v (first vs)
diffs (-> (mapv #(- % min-v) vs)
min-v (double (first vs))
diffs (-> (mapv
#(- (double %) min-v)
vs)
sort
distinct
vec)
Expand Down
2 changes: 1 addition & 1 deletion bases/criterium/src/criterium/viewer/pprint.clj
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
(reduce
(fn [res metric-config]
(let [v (get (get sample (:path metric-config)) index)]
(if (pos? v)
(if (pos? (long v))
(assoc res
(viewer-common/composite-key
[(if-let [group (:group metric-config)]
Expand Down

0 comments on commit e4f0a04

Please sign in to comment.