diff --git a/bases/criterium/src/criterium/collect_plan/impl.clj b/bases/criterium/src/criterium/collect_plan/impl.clj index 1be3f36..aacd48f 100644 --- a/bases/criterium/src/criterium/collect_plan/impl.clj +++ b/bases/criterium/src/criterium/collect_plan/impl.clj @@ -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))])) diff --git a/bases/criterium/src/criterium/util/format.clj b/bases/criterium/src/criterium/util/format.clj index 5c5c7c2..bb003b9 100644 --- a/bases/criterium/src/criterium/util/format.clj +++ b/bases/criterium/src/criterium/util/format.clj @@ -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." @@ -51,12 +51,12 @@ (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]} @@ -64,7 +64,7 @@ (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}]] diff --git a/bases/criterium/src/criterium/util/helpers.clj b/bases/criterium/src/criterium/util/helpers.clj index b716760..9de08d6 100644 --- a/bases/criterium/src/criterium/util/helpers.clj +++ b/bases/criterium/src/criterium/util/helpers.clj @@ -1,4 +1,5 @@ (ns criterium.util.helpers + (:refer-clojure :exclude [update-vals]) (:require [clojure.set :as set] [criterium.util.invariant :refer [have?]] diff --git a/bases/criterium/src/criterium/viewer/common.clj b/bases/criterium/src/criterium/viewer/common.clj index 682d15b..17213b3 100644 --- a/bases/criterium/src/criterium/viewer/common.clj +++ b/bases/criterium/src/criterium/viewer/common.clj @@ -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] @@ -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)) @@ -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])))) [] @@ -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 @@ -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)))) [] @@ -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] diff --git a/bases/criterium/src/criterium/viewer/portal.clj b/bases/criterium/src/criterium/viewer/portal.clj index d452596..26778b2 100644 --- a/bases/criterium/src/criterium/viewer/portal.clj +++ b/bases/criterium/src/criterium/viewer/portal.clj @@ -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] @@ -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] @@ -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 @@ -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 @@ -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) diff --git a/bases/criterium/src/criterium/viewer/pprint.clj b/bases/criterium/src/criterium/viewer/pprint.clj index 9a0f9fe..64de40d 100644 --- a/bases/criterium/src/criterium/viewer/pprint.clj +++ b/bases/criterium/src/criterium/viewer/pprint.clj @@ -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)]