mw & interceptor perf tests with 10 items

This commit is contained in:
Tommi Reiman 2018-05-27 13:22:33 +03:00
parent 68282a3dc7
commit d433005df6

View file

@ -31,7 +31,7 @@
(defrecord RequestOrContext [values queue stack]) (defrecord RequestOrContext [values queue stack])
(def +items+ 100) (def +items+ 10)
(defn expected! [x] (defn expected! [x]
(assert (= (range +items+) (:values x)))) (assert (= (range +items+) (:values x))))
@ -47,18 +47,19 @@
map-request {} map-request {}
record-request (map->RequestOrContext map-request)] record-request (map->RequestOrContext map-request)]
;; 10.8 µs ;; 1000ns
(title "middleware - map") (title "middleware - map")
(expected! (app map-request)) (expected! (app map-request))
(cc/quick-bench (cc/quick-bench
(app map-request)) (app map-request))
;; 4.7 µs ;; 365ns
(title "middleware - record") (title "middleware - record")
(expected! (app record-request)) (expected! (app record-request))
(cc/quick-bench (cc/quick-bench
(app record-request)) (app record-request))
;; 6900ns
(title "middleware - dynamic") (title "middleware - dynamic")
(expected! ((middleware/chain mw identity) record-request)) (expected! ((middleware/chain mw identity) record-request))
(cc/quick-bench (cc/quick-bench
@ -110,12 +111,12 @@
{:enter (interceptor value)}) (range +items+))) {:enter (interceptor value)}) (range +items+)))
ctx (io.pedestal.interceptor.chain/enqueue nil is)] ctx (io.pedestal.interceptor.chain/enqueue nil is)]
;; 78 µs ;; 8400ns
(title "pedestal") (title "pedestal")
(cc/quick-bench (cc/quick-bench
(io.pedestal.interceptor.chain/execute ctx)))) (io.pedestal.interceptor.chain/execute ctx))))
(defn pedestal-tuned-chain-text [] #_(defn pedestal-tuned-chain-text []
(let [is (map io.pedestal.interceptor/interceptor (let [is (map io.pedestal.interceptor/interceptor
(map (fn [value] (map (fn [value]
{:enter (interceptor value)}) (range +items+))) {:enter (interceptor value)}) (range +items+)))
@ -140,17 +141,17 @@
(defn interceptor-test [] (defn interceptor-test []
(let [interceptors (map (fn [value] [interceptor value]) (range +items+)) (let [interceptors (map (fn [value] [interceptor value]) (range +items+))
app (executor-reduce (interceptor/chain interceptors identity)) app (executor-reduce (interceptor/chain interceptors identity {}))
map-request {} map-request {}
record-request (map->RequestOrContext map-request)] record-request (map->RequestOrContext map-request)]
;; 13.5 µs (Map) ;; 1900ns
(title "interceptors - map") (title "interceptors - map")
(expected! (app map-request)) (expected! (app map-request))
(cc/quick-bench (cc/quick-bench
(app map-request)) (app map-request))
;; 7.2 µs (Record) ;; 1300ns
(title "interceptors - record") (title "interceptors - record")
(expected! (app record-request)) (expected! (app record-request))
(cc/quick-bench (cc/quick-bench
@ -212,24 +213,24 @@
(defn interceptor-chain-test [] (defn interceptor-chain-test []
(let [interceptors (map (fn [value] [interceptor value]) (range +items+)) (let [interceptors (map (fn [value] [interceptor value]) (range +items+))
app-reduce (executor-reduce (interceptor/chain interceptors identity)) app-reduce (executor-reduce (interceptor/chain interceptors identity {}))
app-queue (executor-queue (interceptor/chain interceptors identity)) app-queue (executor-queue (interceptor/chain interceptors identity {}))
app-ctx-queue (executor-ctx-queue (interceptor/chain interceptors identity)) app-ctx-queue (executor-ctx-queue (interceptor/chain interceptors identity {}))
request {}] request {}]
;; 14.2 µs ;; 2000ns
(title "interceptors - reduce") (title "interceptors - reduce")
(expected! (app-reduce request)) (expected! (app-reduce request))
(cc/quick-bench (cc/quick-bench
(app-reduce request)) (app-reduce request))
;; 19.4 µs ;; 2500ns
(title "interceptors - queue") (title "interceptors - queue")
(expected! (app-queue request)) (expected! (app-queue request))
(cc/quick-bench (cc/quick-bench
(app-queue request)) (app-queue request))
;; 30.9 µs ;; 3200ns
(title "interceptors - ctx-queue") (title "interceptors - ctx-queue")
(expected! (app-ctx-queue request)) (expected! (app-ctx-queue request))
(cc/quick-bench (cc/quick-bench