Last active
February 18, 2018 13:10
-
-
Save ikitommi/f89a400e4670409c98358f425971ed63 to your computer and use it in GitHub Desktop.
Overhead of ring api-defaults, 3µs per request?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 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