Last active
October 23, 2019 04:58
-
-
Save ikitommi/d3382348ac50639ae7914ffc0f19bb0f to your computer and use it in GitHub Desktop.
Grumpy routing test with reitit + best-effort auto-ordering (original: https://tonsky.me/blog/pedestal/)
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
(require '[reitit.core :as r]) | |
(require '[reitit.impl]) | |
(require '[criterium.core :as cc]) | |
(def router | |
(-> [["/robots.txt" {:get ::get:.robots.txt}] | |
["/after/:post-id" {:get ::get:.after.:post-id}] | |
["/static/*path" {:get ::get:.static.*path}] | |
["/post/:post-id" {:get ::get:.post.:post-id}] | |
["/sitemap.xml" {:get ::get:.sitemap.xml}] | |
["/" {:get ::get:.}] | |
["/feed.xml" {:get ::get:.feed.xml}] | |
["/post/:post-id/:img" {:get ::get:.post.:post-id.:img}] | |
["/forbidden" {:get ::grumpy.auth.handle-forbidden}] | |
["/authenticate" {:get ::grumpy.auth.handle-authenticate}] | |
["/logout" {:get ::get:.logout}] | |
["/send-email" {:post ::grumpy.auth.handle-send-email}] | |
["/email-sent" {:get ::grumpy.auth.handle-email-sent}] | |
["/post/:post-id/upload" {:post ::post:.post.:post-id.upload}] | |
["/post/:post-id/publish" {:post ::post:.post.:post-id.publish}] | |
["/new" {:get ::get:.new}] | |
["/post/:post-id/delete" {:get ::get:.post.:post-id.delete}] | |
["/draft/:post-id/:img" {:get ::get:.draft.:post-id.:img}] | |
["/draft/:post-id/delete" {:post ::post:.draft.:post-id.delete}] | |
["/post/:post-id/edit" {:get ::get:.post.:post-id.edit}] | |
["/post/:post-id/edit" {:post ::post:.post.:post-id.edit}] | |
["/post/:post-id/save" {:post ::post:.post.:post-id.save}]] | |
(->> (sort-by (juxt (comp count :path-parts #(reitit.impl/parse % nil) first) first))) | |
(r/router {:conflicts nil}))) | |
(r/router-name router) | |
; :quarantine-router | |
(r/routes router) | |
;[["/" {:get ::get:.}] | |
; ["/authenticate" {:get ::grumpy.auth.handle-authenticate}] | |
; ["/email-sent" {:get ::grumpy.auth.handle-email-sent}] | |
; ["/feed.xml" {:get ::get:.feed.xml}] | |
; ["/forbidden" {:get ::grumpy.auth.handle-forbidden}] | |
; ["/logout" {:get ::get:.logout}] | |
; ["/new" {:get ::get:.new}] | |
; ["/robots.txt" {:get ::get:.robots.txt}] | |
; ["/send-email" {:post ::grumpy.auth.handle-send-email}] | |
; ["/sitemap.xml" {:get ::get:.sitemap.xml}] | |
; ["/after/:post-id" {:get ::get:.after.:post-id}] | |
; ["/post/:post-id" {:get ::get:.post.:post-id}] | |
; ["/static/*path" {:get ::get:.static.*path}] | |
; ["/draft/:post-id/delete" {:post ::post:.draft.:post-id.delete}] | |
; ["/post/:post-id/delete" {:get ::get:.post.:post-id.delete}] | |
; ["/post/:post-id/edit" {:get ::get:.post.:post-id.edit}] | |
; ["/post/:post-id/edit" {:post ::post:.post.:post-id.edit}] | |
; ["/post/:post-id/publish" {:post ::post:.post.:post-id.publish}] | |
; ["/post/:post-id/save" {:post ::post:.post.:post-id.save}] | |
; ["/post/:post-id/upload" {:post ::post:.post.:post-id.upload}] | |
; ["/draft/:post-id/:img" {:get ::get:.draft.:post-id.:img}] | |
; ["/post/:post-id/:img" {:get ::get:.post.:post-id.:img}]] | |
(doseq [[path] (r/routes router)] | |
(println | |
(-> (cc/quick-benchmark (r/match-by-path router path) {}) | |
:mean | |
(first) | |
(* 1000000000) | |
(int) | |
(str "ns")) | |
(pr-str path))) | |
;;; served via lookup-router | |
;10ns "/" | |
;12ns "/authenticate" | |
;10ns "/email-sent" | |
;10ns "/feed.xml" | |
;10ns "/forbidden" | |
;11ns "/logout" | |
;10ns "/new" | |
;10ns "/robots.txt" | |
;10ns "/send-email" | |
;14ns "/sitemap.xml" | |
;;; served via trie-router | |
;87ns "/after/:post-id" | |
;95ns "/post/:post-id" | |
;107ns "/static/*path" | |
;;; served via linear-router | |
;135ns "/draft/:post-id/delete" | |
;159ns "/post/:post-id/delete" | |
;164ns "/post/:post-id/edit" | |
;164ns "/post/:post-id/edit" | |
;195ns "/post/:post-id/publish" | |
;207ns "/post/:post-id/save" | |
;225ns "/post/:post-id/upload" | |
;197ns "/draft/:post-id/:img" | |
;284ns "/post/:post-id/:img" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment