mirror of
https://github.com/metosin/reitit.git
synced 2025-12-18 00:41:12 +00:00
Enable quick creation of routers
This commit is contained in:
parent
c93b42cd6f
commit
faaaedaa29
2 changed files with 47 additions and 6 deletions
|
|
@ -364,10 +364,10 @@
|
|||
([raw-routes]
|
||||
(router raw-routes {}))
|
||||
([raw-routes opts]
|
||||
(let [{:keys [router] :as opts} (merge (default-router-options) opts)]
|
||||
(let [{:keys [router conflicts] :as opts} (merge (default-router-options) opts)]
|
||||
(try
|
||||
(let [routes (impl/resolve-routes raw-routes opts)
|
||||
path-conflicting (impl/path-conflicting-routes routes opts)
|
||||
path-conflicting (if-not (and router (not conflicts)) (impl/path-conflicting-routes routes opts))
|
||||
name-conflicting (impl/name-conflicting-routes routes)
|
||||
compiled-routes (impl/compile-routes routes opts)
|
||||
wilds? (boolean (some (impl/->wild-route? opts) compiled-routes))
|
||||
|
|
@ -380,10 +380,8 @@
|
|||
all-wilds? trie-router
|
||||
:else mixed-router)]
|
||||
|
||||
(when-let [conflicts (:conflicts opts)]
|
||||
(when-let [conflict-report (impl/unresolved-conflicts
|
||||
path-conflicting)]
|
||||
(conflicts conflict-report)))
|
||||
(when-let [conflict-report (and conflicts (impl/unresolved-conflicts path-conflicting))]
|
||||
(conflicts conflict-report))
|
||||
|
||||
(when name-conflicting
|
||||
(exception/fail! :name-conflicts name-conflicting))
|
||||
|
|
|
|||
43
perf-test/clj/reitit/router_creation_perf_test.clj
Normal file
43
perf-test/clj/reitit/router_creation_perf_test.clj
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
(ns reitit.router-creation-perf-test
|
||||
(:require [reitit.perf-utils :refer [bench!]]
|
||||
[reitit.core :as r]
|
||||
[clojure.string :as str])
|
||||
(:import (java.util Random)))
|
||||
|
||||
;;
|
||||
;; 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
|
||||
;;
|
||||
|
||||
(defn random [^long seed]
|
||||
(Random. seed))
|
||||
|
||||
(defn rand-str [^Random rnd len]
|
||||
(apply str (take len (repeatedly #(char (+ (.nextInt rnd 26) 97))))))
|
||||
|
||||
(defn route [rnd]
|
||||
(str/join "/" (repeatedly (+ 2 (.nextInt rnd 8)) (fn [] (rand-str rnd (.nextInt rnd 10))))))
|
||||
|
||||
(def hundred-routes
|
||||
(let [rnd (random 1)]
|
||||
(mapv (fn [n] [(route rnd) (keyword (str "route" n))]) (range 100))))
|
||||
|
||||
(defn bench-routers []
|
||||
;; 104ms
|
||||
(bench! "default" (r/router hundred-routes))
|
||||
|
||||
;; 7ms
|
||||
(bench! "linear" (r/router hundred-routes {:router r/linear-router, :conflicts nil})))
|
||||
|
||||
(comment
|
||||
(bench-routers))
|
||||
Loading…
Reference in a new issue