mirror of
https://github.com/metosin/reitit.git
synced 2025-12-16 16:01:11 +00:00
testing ring-cors
This commit is contained in:
parent
3351bca1fd
commit
e9af3ab619
3 changed files with 58 additions and 0 deletions
43
perf-test/clj/reitit/cors_perf_test.clj
Normal file
43
perf-test/clj/reitit/cors_perf_test.clj
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
(ns reitit.cors-perf-test
|
||||
(:require [reitit.perf-utils :refer :all]
|
||||
[ring.middleware.cors :as cors]))
|
||||
|
||||
;;
|
||||
;; start repl with `lein perf repl`
|
||||
;; perf measured with the following setup:
|
||||
;;
|
||||
;; Model Name: MacBook Pro
|
||||
;; Model Identifier: MacBookPro113
|
||||
;; Processor Name: Intel Core i7
|
||||
;; Processor Speed: 2,5 GHz
|
||||
;; Number of Processors: 1
|
||||
;; Total Number of Cores: 4
|
||||
;; L2 Cache (per Core): 256 KB
|
||||
;; L3 Cache: 6 MB
|
||||
;; Memory: 16 GB
|
||||
;;
|
||||
|
||||
(def app
|
||||
(cors/wrap-cors
|
||||
(fn [_] {:status 200, :body "ok"})
|
||||
:access-control-allow-origin #"http://example.com"
|
||||
:access-control-allow-headers #{:accept :content-type}
|
||||
:access-control-allow-methods #{:get :put :post}))
|
||||
|
||||
(def cors-request
|
||||
{:request-method :options
|
||||
:uri "/"
|
||||
:headers {"origin" "http://example.com"
|
||||
"access-control-request-method" "POST"
|
||||
"access-control-request-headers" "Accept, Content-Type"}})
|
||||
|
||||
(defn cors-perf-test []
|
||||
|
||||
;; 0.04µs
|
||||
(b! "ring-cors: pass" (app {}))
|
||||
|
||||
;; 15.85µs
|
||||
(b! "ring-cors: preflight" (app cors-request)))
|
||||
|
||||
(comment
|
||||
(cors-perf-test))
|
||||
|
|
@ -54,6 +54,20 @@
|
|||
(println ~@body)
|
||||
(cc/quick-bench ~@body)))
|
||||
|
||||
(defmacro b! [name & body]
|
||||
`(do
|
||||
(title ~name)
|
||||
(println)
|
||||
(println "\u001B[33m" ~@body "\u001B[0m")
|
||||
(let [{[lower#] :lower-q :as res#} (cc/quick-benchmark (do ~@body) nil)
|
||||
µs# (* 1000000 lower#)
|
||||
ns# (* 1000 µs#)]
|
||||
(println "\u001B[32m\n" (format "%1$10.2fns" ns#) "\u001B[0m")
|
||||
(println "\u001B[32m" (format "%1$10.2fµs" µs#) "\u001B[0m")
|
||||
(println)
|
||||
(cc/report-result res#))
|
||||
(println)))
|
||||
|
||||
(defn valid-urls [router]
|
||||
(->>
|
||||
(for [name (reitit/route-names router)
|
||||
|
|
|
|||
|
|
@ -104,6 +104,7 @@
|
|||
[funcool/promesa "2.0.1"]
|
||||
|
||||
[com.clojure-goes-fast/clj-async-profiler "0.3.1"]
|
||||
[ring-cors "0.1.12"]
|
||||
|
||||
[com.bhauman/rebel-readline "0.1.4"]]}
|
||||
:1.9 {:dependencies [[org.clojure/clojure "1.9.0"]]}
|
||||
|
|
|
|||
Loading…
Reference in a new issue