mirror of
https://github.com/metosin/reitit.git
synced 2026-01-31 10:00:33 +00:00
Polish perf tests
This commit is contained in:
parent
4e22fd2f53
commit
86acee9098
3 changed files with 57 additions and 40 deletions
|
|
@ -1,5 +1,7 @@
|
||||||
(ns reitit.opensensors-routing-test
|
(ns reitit.opensensors-routing-test
|
||||||
(:require [clojure.test :refer [deftest testing is]]
|
(:require [clojure.test :refer [deftest testing is]]
|
||||||
|
[criterium.core :as cc]
|
||||||
|
[reitit.perf-utils :refer :all]
|
||||||
[cheshire.core :as json]
|
[cheshire.core :as json]
|
||||||
[clojure.string :as str]
|
[clojure.string :as str]
|
||||||
[reitit.core :as reitit]
|
[reitit.core :as reitit]
|
||||||
|
|
@ -16,13 +18,20 @@
|
||||||
[io.pedestal.http.route.router :as pedestal]
|
[io.pedestal.http.route.router :as pedestal]
|
||||||
[io.pedestal.http.route :as route]))
|
[io.pedestal.http.route :as route]))
|
||||||
|
|
||||||
(defn raw-title [color s]
|
;;
|
||||||
(println (str color (apply str (repeat (count s) "#")) "\u001B[0m"))
|
;; start repl with `lein perf repl`
|
||||||
(println (str color s "\u001B[0m"))
|
;; perf measured with the following setup:
|
||||||
(println (str color (apply str (repeat (count s) "#")) "\u001B[0m")))
|
;;
|
||||||
|
;; Model Name: MacBook Pro
|
||||||
(def title (partial raw-title "\u001B[35m"))
|
;; Model Identifier: MacBookPro11,3
|
||||||
(def suite (partial raw-title "\u001B[32m"))
|
;; 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
|
||||||
|
;;
|
||||||
|
|
||||||
;;
|
;;
|
||||||
;; extract sample routes
|
;; extract sample routes
|
||||||
|
|
@ -77,15 +86,6 @@
|
||||||
avg (int (/ (reduce + times) (count times)))]
|
avg (int (/ (reduce + times) (count times)))]
|
||||||
[% avg]) urls)))
|
[% avg]) urls)))
|
||||||
|
|
||||||
(defn bench [routes no-paths?]
|
|
||||||
(let [routes (mapv (fn [[path name]]
|
|
||||||
(if no-paths?
|
|
||||||
[(str/replace path #"\:" "") name]
|
|
||||||
[path name])) routes)
|
|
||||||
router (reitit/router routes)]
|
|
||||||
(doseq [[path time] (bench-routes routes #(reitit/match-by-path router %))]
|
|
||||||
(println path "\t" time))))
|
|
||||||
|
|
||||||
(defn bench [routes no-paths?]
|
(defn bench [routes no-paths?]
|
||||||
(let [routes (mapv (fn [[path name]]
|
(let [routes (mapv (fn [[path name]]
|
||||||
(if no-paths?
|
(if no-paths?
|
||||||
|
|
@ -471,7 +471,7 @@
|
||||||
(if-not match
|
(if-not match
|
||||||
(println route)))))
|
(println route)))))
|
||||||
|
|
||||||
(defn bench! [routes verbose? name f]
|
(defn bench!! [routes verbose? name f]
|
||||||
(System/gc)
|
(System/gc)
|
||||||
(println)
|
(println)
|
||||||
(suite name)
|
(suite name)
|
||||||
|
|
@ -493,14 +493,23 @@
|
||||||
compojure-api-f #(opensensors-compojure-api-routes {:uri % :request-method :get})
|
compojure-api-f #(opensensors-compojure-api-routes {:uri % :request-method :get})
|
||||||
pedestal-f #(pedestal/find-route opensensors-pedestal-routes {:path-info % :request-method :get})]
|
pedestal-f #(pedestal/find-route opensensors-pedestal-routes {:path-info % :request-method :get})]
|
||||||
|
|
||||||
(bench! routes true "reitit" reitit-f) ;; 2538ns -> 2028ns
|
;; 2538ns -> 2028ns
|
||||||
(bench! routes true "reitit-ring" reitit-ring-f) ;; 2845ns -> 2299ns
|
(bench!! routes true "reitit" reitit-f)
|
||||||
(bench! routes true "pedestal" pedestal-f) ;; 2737ns
|
|
||||||
(bench! routes true "compojure-api" compojure-api-f) ;; 9823ns
|
|
||||||
(bench! routes true "bidi" bidi-f) ;; 16716ns
|
|
||||||
(bench! routes true "ataraxy" ataraxy-f) ;; 24467ns
|
|
||||||
|
|
||||||
))
|
;; 2845ns -> 2299ns
|
||||||
|
(bench!! routes true "reitit-ring" reitit-ring-f)
|
||||||
|
|
||||||
|
;; 2737ns
|
||||||
|
(bench!! routes true "pedestal" pedestal-f)
|
||||||
|
|
||||||
|
;; 9823ns
|
||||||
|
(bench!! routes true "compojure-api" compojure-api-f)
|
||||||
|
|
||||||
|
;; 16716ns
|
||||||
|
(bench!! routes true "bidi" bidi-f)
|
||||||
|
|
||||||
|
;; 24467ns
|
||||||
|
(bench!! routes true "ataraxy" ataraxy-f)))
|
||||||
|
|
||||||
(comment
|
(comment
|
||||||
(bench-rest!))
|
(bench-rest!))
|
||||||
|
|
@ -548,16 +557,15 @@
|
||||||
|
|
||||||
;; 125ns
|
;; 125ns
|
||||||
;; 62ns (fast-map)
|
;; 62ns (fast-map)
|
||||||
(bench! routes false "reitit" reitit-f)
|
(bench!! routes false "reitit" reitit-f)
|
||||||
|
|
||||||
;; 272ns
|
;; 272ns
|
||||||
;; 219ns (fast-assoc)
|
;; 219ns (fast-assoc)
|
||||||
;; 171ns (fast-map)
|
;; 171ns (fast-map)
|
||||||
(bench! routes false "reitit-ring" reitit-ring-f)
|
(bench!! routes false "reitit-ring" reitit-ring-f)
|
||||||
|
|
||||||
;; 172ns
|
;; 172ns
|
||||||
(bench! routes false "pedestal" pedestal-f)))
|
(bench!! routes false "pedestal" pedestal-f)))
|
||||||
|
|
||||||
(comment
|
(comment
|
||||||
(bench-cqrs!))
|
(bench-cqrs!))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
(ns reitit.perf-test
|
(ns reitit.perf-test
|
||||||
(:require [criterium.core :as cc]
|
(:require [criterium.core :as cc]
|
||||||
[reitit.core :as reitit]
|
[reitit.core :as reitit]
|
||||||
|
[reitit.perf-utils :refer :all]
|
||||||
|
|
||||||
[bidi.bidi :as bidi]
|
[bidi.bidi :as bidi]
|
||||||
[compojure.api.sweet :refer [api routes GET]]
|
[compojure.api.sweet :refer [api routes GET]]
|
||||||
|
|
@ -27,14 +28,6 @@
|
||||||
;; Memory: 16 GB
|
;; Memory: 16 GB
|
||||||
;;
|
;;
|
||||||
|
|
||||||
(defn raw-title [color s]
|
|
||||||
(println (str color (apply str (repeat (count s) "#")) "\u001B[0m"))
|
|
||||||
(println (str color s "\u001B[0m"))
|
|
||||||
(println (str color (apply str (repeat (count s) "#")) "\u001B[0m")))
|
|
||||||
|
|
||||||
(def title (partial raw-title "\u001B[35m"))
|
|
||||||
(def suite (partial raw-title "\u001B[32m"))
|
|
||||||
|
|
||||||
(def bidi-routes
|
(def bidi-routes
|
||||||
["/" [["auth/login" :auth/login]
|
["/" [["auth/login" :auth/login]
|
||||||
[["auth/recovery/token/" :token] :auth/recovery]
|
[["auth/recovery/token/" :token] :auth/recovery]
|
||||||
|
|
@ -106,7 +99,7 @@
|
||||||
(call)))
|
(call)))
|
||||||
|
|
||||||
;; 1.0µs (-94%)
|
;; 1.0µs (-94%)
|
||||||
;; 770ns (-95%, -23%)
|
;; 690ns (-96%)
|
||||||
(title "reitit")
|
(title "reitit")
|
||||||
(let [call #(reitit/match-by-path reitit-routes "/workspace/1/1")]
|
(let [call #(reitit/match-by-path reitit-routes "/workspace/1/1")]
|
||||||
(assert (call))
|
(assert (call))
|
||||||
|
|
@ -117,7 +110,7 @@
|
||||||
|
|
||||||
(suite "reverse routing")
|
(suite "reverse routing")
|
||||||
|
|
||||||
;; 2.2µs (-56%)
|
;; 2.0µs (-59%)
|
||||||
(title "bidi")
|
(title "bidi")
|
||||||
(let [call #(bidi/path-for bidi-routes :workspace/page :project "1" :page "1")]
|
(let [call #(bidi/path-for bidi-routes :workspace/page :project "1" :page "1")]
|
||||||
(assert (= "/workspace/1/1" (call)))
|
(assert (= "/workspace/1/1" (call)))
|
||||||
|
|
@ -126,14 +119,14 @@
|
||||||
|
|
||||||
(title "ataraxy doesn't support reverse routing :(")
|
(title "ataraxy doesn't support reverse routing :(")
|
||||||
|
|
||||||
;; 3.8µs (-25%)
|
;; 3.8µs (-22%)
|
||||||
(title "pedestal - map-tree => prefix-tree")
|
(title "pedestal - map-tree => prefix-tree")
|
||||||
(let [call #(pedestal-url-for :workspace/page :path-params {:project "1" :page "1"})]
|
(let [call #(pedestal-url-for :workspace/page :path-params {:project "1" :page "1"})]
|
||||||
(assert (= "/workspace/1/1" (call)))
|
(assert (= "/workspace/1/1" (call)))
|
||||||
(cc/quick-bench
|
(cc/quick-bench
|
||||||
(call)))
|
(call)))
|
||||||
|
|
||||||
;; 5.1µs
|
;; 4.9µs
|
||||||
(title "compojure-api")
|
(title "compojure-api")
|
||||||
(let [call #(routes/path-for* :workspace/page compojure-api-request {:project "1", :page "1"})]
|
(let [call #(routes/path-for* :workspace/page compojure-api-request {:project "1", :page "1"})]
|
||||||
(assert (= "/workspace/1/1" (call)))
|
(assert (= "/workspace/1/1" (call)))
|
||||||
|
|
|
||||||
16
perf-test/clj/reitit/perf_utils.clj
Normal file
16
perf-test/clj/reitit/perf_utils.clj
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
(ns reitit.perf-utils
|
||||||
|
(:require [criterium.core :as cc]))
|
||||||
|
|
||||||
|
(defn raw-title [color s]
|
||||||
|
(println (str color (apply str (repeat (count s) "#")) "\u001B[0m"))
|
||||||
|
(println (str color s "\u001B[0m"))
|
||||||
|
(println (str color (apply str (repeat (count s) "#")) "\u001B[0m")))
|
||||||
|
|
||||||
|
(def title (partial raw-title "\u001B[35m"))
|
||||||
|
(def suite (partial raw-title "\u001B[32m"))
|
||||||
|
|
||||||
|
(defmacro bench! [name & body]
|
||||||
|
`(do
|
||||||
|
(title ~name)
|
||||||
|
(println ~@body)
|
||||||
|
(cc/quick-bench ~@body)))
|
||||||
Loading…
Reference in a new issue