mirror of
https://github.com/metosin/reitit.git
synced 2025-12-18 08:51:12 +00:00
Perf-utils
This commit is contained in:
parent
df38a0de05
commit
29a54a3262
1 changed files with 13 additions and 9 deletions
|
|
@ -34,9 +34,11 @@
|
||||||
(mapv
|
(mapv
|
||||||
(fn [path]
|
(fn [path]
|
||||||
(let [request (map->Request (req path))
|
(let [request (map->Request (req path))
|
||||||
time (int (* (first (:sample-mean (cc/quick-benchmark (dotimes [_ 1000] (f request)) {}))) 1e6))]
|
results (cc/quick-benchmark (dotimes [_ 1000] (f request)) {})
|
||||||
(println path "=>" time "ns")
|
mean (int (* (first (:sample-mean results)) 1e6))
|
||||||
[path time]))
|
lower (int (* (first (:lower-q results)) 1e6))]
|
||||||
|
(println path "=>" lower "/" mean "ns")
|
||||||
|
[path [mean lower]]))
|
||||||
urls)))
|
urls)))
|
||||||
|
|
||||||
(defn bench [routes req no-paths?]
|
(defn bench [routes req no-paths?]
|
||||||
|
|
@ -45,8 +47,8 @@
|
||||||
[(str/replace path #"\:" "") name]
|
[(str/replace path #"\:" "") name]
|
||||||
[path name])) routes)
|
[path name])) routes)
|
||||||
router (reitit/router routes)]
|
router (reitit/router routes)]
|
||||||
(doseq [[path time] (bench-routes routes req #(reitit/match-by-path router %))]
|
(doseq [[path [mean lower]] (bench-routes routes req #(reitit/match-by-path router %))]
|
||||||
(println path "\t" time))))
|
(println path "\t" mean lower))))
|
||||||
|
|
||||||
;;
|
;;
|
||||||
;; Perf tests
|
;; Perf tests
|
||||||
|
|
@ -58,8 +60,10 @@
|
||||||
(println)
|
(println)
|
||||||
(suite name)
|
(suite name)
|
||||||
(println)
|
(println)
|
||||||
(let [times (for [[path time] (bench-routes routes req f)]
|
(let [times (for [[path [mean lower]] (bench-routes routes req f)]
|
||||||
(do
|
(do
|
||||||
(when verbose? (println (format "%7s" time) "\t" path))
|
(when verbose? (println (format "%7s %7s" mean lower) "\t" path))
|
||||||
time))]
|
[mean lower]))]
|
||||||
(title (str "average: " (int (/ (reduce + times) (count times)))))))
|
(title (str "average, lower/mean: "
|
||||||
|
(int (/ (reduce + (map second times)) (count times))) "/"
|
||||||
|
(int (/ (reduce + (map first times)) (count times)))))))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue