From 29a54a3262fdadac5cab4d7af3b5220faf2c3d8d Mon Sep 17 00:00:00 2001 From: Tommi Reiman Date: Sat, 9 Feb 2019 15:29:37 +0200 Subject: [PATCH] Perf-utils --- perf-test/clj/reitit/perf_utils.clj | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/perf-test/clj/reitit/perf_utils.clj b/perf-test/clj/reitit/perf_utils.clj index 0f8481be..d2427903 100644 --- a/perf-test/clj/reitit/perf_utils.clj +++ b/perf-test/clj/reitit/perf_utils.clj @@ -34,9 +34,11 @@ (mapv (fn [path] (let [request (map->Request (req path)) - time (int (* (first (:sample-mean (cc/quick-benchmark (dotimes [_ 1000] (f request)) {}))) 1e6))] - (println path "=>" time "ns") - [path time])) + results (cc/quick-benchmark (dotimes [_ 1000] (f request)) {}) + mean (int (* (first (:sample-mean results)) 1e6)) + lower (int (* (first (:lower-q results)) 1e6))] + (println path "=>" lower "/" mean "ns") + [path [mean lower]])) urls))) (defn bench [routes req no-paths?] @@ -45,8 +47,8 @@ [(str/replace path #"\:" "") name] [path name])) routes) router (reitit/router routes)] - (doseq [[path time] (bench-routes routes req #(reitit/match-by-path router %))] - (println path "\t" time)))) + (doseq [[path [mean lower]] (bench-routes routes req #(reitit/match-by-path router %))] + (println path "\t" mean lower)))) ;; ;; Perf tests @@ -58,8 +60,10 @@ (println) (suite name) (println) - (let [times (for [[path time] (bench-routes routes req f)] + (let [times (for [[path [mean lower]] (bench-routes routes req f)] (do - (when verbose? (println (format "%7s" time) "\t" path)) - time))] - (title (str "average: " (int (/ (reduce + times) (count times))))))) + (when verbose? (println (format "%7s %7s" mean lower) "\t" path)) + [mean lower]))] + (title (str "average, lower/mean: " + (int (/ (reduce + (map second times)) (count times))) "/" + (int (/ (reduce + (map first times)) (count times)))))))