Skip to content

Instantly share code, notes, and snippets.

@ikitommi
Last active February 18, 2018 13:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ikitommi/f89a400e4670409c98358f425971ed63 to your computer and use it in GitHub Desktop.
Save ikitommi/f89a400e4670409c98358f425971ed63 to your computer and use it in GitHub Desktop.
Overhead of ring api-defaults, 3µs per request?
;; start repl in perf mode (e.g. -server)
(require '[ring.middleware.defaults]) ; [ring/ring-defaults "0.3.1"]
(require '[criterium.core :as cc]) ; [criterium "0.4.4"]
(defn handler [request]
{:status 200
:body "Hello World"
:headers {"Content-Type" "text/html"}})
(def app
(-> handler
(ring.middleware.defaults/wrap-defaults
ring.middleware.defaults/api-defaults)))
(handler {:request-method :get, :uri "/ping"})
; {:status 200
; :body "Hello World"
; :headers {"Content-Type" "text/html"}}
(app {:request-method :get, :uri "/ping"})
; {:status 200
; :body "Hello World"
; :headers {"Content-Type" "text/html; charset=utf-8"}}
;; 315ns
(cc/quick-bench
(dotimes [_ 1000]
(handler {:request-method :get, :uri "/ping"})))
;; 3.2ms (!!!!!)
(cc/quick-bench
(dotimes [_ 1000]
(app {:request-method :get, :uri "/ping"})))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment