don't test compojure-api, it's compojure all over

This commit is contained in:
Tommi Reiman 2017-11-24 18:58:17 +02:00
parent e0786b73f0
commit 85c4a0a8c0
4 changed files with 98 additions and 185 deletions

View file

@ -4,9 +4,8 @@
[reitit.perf-utils :refer :all]
[bidi.bidi :as bidi]
[compojure.api.sweet :refer [api routes GET]]
[compojure.api.routes :as routes]
[ataraxy.core :as ataraxy]
[compojure.core :as compojure]
[io.pedestal.http.route.definition.table :as table]
[io.pedestal.http.route.map-tree :as map-tree]
@ -34,14 +33,11 @@
[["auth/recovery/token/" :token] :auth/recovery]
["workspace/" [[[:project "/" :page] :workspace/page]]]]])
(def compojure-api-routes
(routes
(GET "/auth/login" [] {:name :auth/login} (constantly ""))
(GET "/auth/recovery/token/:token" [] {:name :auth/recovery} (constantly ""))
(GET "/workspace/:project/:page" [] {:name :workspace/page} (constantly ""))))
(def compojure-api-request
{:compojure.api.request/lookup (routes/route-lookup-table (routes/get-routes (api compojure-api-routes)))})
(def compojure-routes
(compojure/routes
(compojure/GET "/auth/login" [] (constantly ""))
(compojure/GET "/auth/recovery/token/:token" [] (constantly ""))
(compojure/GET "/workspace/:project/:page" [] (constantly ""))))
(def ataraxy-routes
(ataraxy/compile
@ -94,13 +90,13 @@
(dotimes [_ 1000]
(pedestal/find-route pedestal-router {:path-info "/auth/login" :request-method :get}))))
;; 1500 µs
(title "compojure-api")
;; 1400 µs
(title "compojure")
(let [request {:uri "/auth/login", :request-method :get}]
(assert (compojure-api-routes request))
(assert (compojure-routes request))
(cc/quick-bench
(dotimes [_ 1000]
(compojure-api-routes request))))
(compojure-routes request))))
;; 3.2 µs (300-500x)
(title "reitit")
@ -136,16 +132,17 @@
(dotimes [_ 1000]
(pedestal/find-route pedestal-router request))))
;; 3500 µs
(title "compojure-api")
;; 3400 µs
(title "compojure")
(let [request {:uri "/workspace/1/1", :request-method :get}]
(assert (compojure-api-routes request))
(assert (compojure-routes request))
(cc/quick-bench
(dotimes [_ 1000]
(compojure-api-routes request))))
(compojure-routes request))))
;; 710 µs (3-18x)
;; 530 µs (4-24x) -25% prefix-tree-router
;; 710 µs (3-18x) segment-router
(title "reitit")
(assert (reitit/match-by-path reitit-routes "/workspace/1/1"))
(cc/quick-bench
@ -174,10 +171,6 @@
;; 4.9µs
(title "compojure-api")
(let [call #(routes/path-for* :workspace/page compojure-api-request {:project "1", :page "1"})]
(assert (= "/workspace/1/1" (call)))
(cc/quick-bench
(call)))
;; 850ns (-83%)
(title "reitit")

View file

@ -11,7 +11,6 @@
[ataraxy.core :as ataraxy]
[compojure.api.sweet :refer [api routes context ANY]]
[compojure.core :as compojure]
[io.pedestal.http.route.definition.table :as table]
@ -342,7 +341,7 @@
(def cqrs-routes-compojure
(apply routes (map (fn [command] (compojure/ANY (str "/command/" (name command)) [] handler)) commands)))
;; Method code too large
;; Method code too large!
#_(def cqrs-routes-ataraxy
(ataraxy/compile
(into {} (mapv (fn [command] [(str "/command/" (name command)) [command]]) commands))))

View file

@ -11,8 +11,7 @@
[ataraxy.core :as ataraxy]
[compojure.api.sweet :refer [api routes context ANY]]
[compojure.core :as compojure]
[compojure.core :refer [routes context ANY]]
[io.pedestal.http.route.definition.table :as table]
[io.pedestal.http.route.map-tree :as map-tree]
@ -230,157 +229,86 @@
["topics/" topic] [:test/route47 topic]
"topics" [:test/route50]}}))
(def opensensors-compojure-routes
(compojure/routes
(compojure/context "/v1" []
(compojure/context "/public" []
(compojure/ANY "/topics/:topic" [] {:name :test/route4} handler)
(compojure/ANY "/users/:user-id" [] {:name :test/route16} handler)
(compojure/ANY "/orgs/:org-id" [] {:name :test/route18} handler))
(compojure/context "/users/:user-id" []
(compojure/ANY "/orgs/:org-id" [] {:name :test/route5} handler)
(compojure/ANY "/invitations" [] {:name :test/route7} handler)
(compojure/ANY "/topics" [] {:name :test/route9} handler)
(compojure/ANY "/bookmarks/followers" [] {:name :test/route10} handler)
(compojure/context "/devices" []
(compojure/ANY "/" [] {:name :test/route15} handler)
#_(compojure/ANY "/bulk" [] {:name :test/route21} handler)
(compojure/ANY "/:client-id" [] {:name :test/route35} handler)
(compojure/ANY "/:client-id/reset-password" [] {:name :test/route49} handler))
(compojure/ANY "/device-errors" [] {:name :test/route22} handler)
(compojure/ANY "/usage-stats" [] {:name :test/route24} handler)
(compojure/ANY "/claim-device/:client-id" [] {:name :test/route26} handler)
(compojure/ANY "/owned-orgs" [] {:name :test/route31} handler)
(compojure/ANY "/bookmark/:topic" [] {:name :test/route33} handler)
(compojure/ANY "/" [] {:name :test/route36} handler)
(compojure/ANY "/orgs" [] {:name :test/route52} handler)
(compojure/ANY "/api-key" [] {:name :test/route43} handler)
(compojure/ANY "/bookmarks" [] {:name :test/route56} handler))
(compojure/ANY "/search/topics/:term" [] {:name :test/route6} handler)
(compojure/context "/orgs" []
(compojure/ANY "/" [] {:name :test/route55} handler)
(compojure/context "/:org-id" []
(compojure/context "/devices" []
(compojure/ANY "/" [] {:name :test/route37} handler)
(compojure/ANY "/:device-id" [] {:name :test/route13} handler)
#_(compojure/ANY "/:batch/:type" [] {:name :test/route8} handler))
(compojure/ANY "/usage-stats" [] {:name :test/route12} handler)
(compojure/ANY "/invitations" [] {:name :test/route19} handler)
(compojure/context "/members" []
(compojure/ANY "/:user-id" [] {:name :test/route34} handler)
(compojure/ANY "/" [] {:name :test/route38} handler)
#_(compojure/ANY "/invitation-data/:user-id" [] {:name :test/route39} handler))
(compojure/ANY "/errors" [] {:name :test/route17} handler)
(compojure/ANY "/" [] {:name :test/route42} handler)
(compojure/ANY "/confirm-membership/:token" [] {:name :test/route46} handler)
(compojure/ANY "/topics" [] {:name :test/route57} handler)))
(compojure/context "/messages" []
(compojure/ANY "/user/:user-id" [] {:name :test/route14} handler)
(compojure/ANY "/device/:client-id" [] {:name :test/route30} handler)
(compojure/ANY "/topic/:topic" [] {:name :test/route48} handler))
(compojure/context "/topics" []
(compojure/ANY "/:topic" [] {:name :test/route32} handler)
(compojure/ANY "/" [] {:name :test/route54} handler))
(compojure/ANY "/whoami" [] {:name :test/route41} handler)
(compojure/ANY "/login" [] {:name :test/route51} handler))
(compojure/context "/v2" []
(compojure/ANY "/whoami" [] {:name :test/route1} handler)
(compojure/context "/users/:user-id" []
(compojure/ANY "/datasets" [] {:name :test/route2} handler)
(compojure/ANY "/devices" [] {:name :test/route25} handler)
(compojure/context "/topics" []
(compojure/ANY "/bulk" [] {:name :test/route29} handler)
(compojure/ANY "/" [] {:name :test/route54} handler))
(compojure/ANY "/" [] {:name :test/route45} handler))
(compojure/context "/public" []
(compojure/context "/projects/:project-id" []
(compojure/ANY "/datasets" [] {:name :test/route3} handler)
(compojure/ANY "/" [] {:name :test/route27} handler))
#_(compojure/ANY "/messages/dataset/bulk" [] {:name :test/route20} handler)
(compojure/ANY "/datasets/:dataset-id" [] {:name :test/route28} handler)
(compojure/ANY "/messages/dataset/:dataset-id" [] {:name :test/route53} handler))
(compojure/ANY "/datasets/:dataset-id" [] {:name :test/route11} handler)
(compojure/ANY "/login" [] {:name :test/route23} handler)
(compojure/ANY "/orgs/:org-id/topics" [] {:name :test/route40} handler)
(compojure/ANY "/schemas" [] {:name :test/route44} handler)
(compojure/ANY "/topics/:topic" [] {:name :test/route47} handler)
(compojure/ANY "/topics" [] {:name :test/route50} handler))))
(comment
(declare routes)
(declare context)
(declare ANY))
(def opensensors-compojure-api-routes
(def opensensors-compojure-routes
(routes
(context "/v1" []
(context "/public" []
(ANY "/topics/:topic" [] {:name :test/route4} handler)
(ANY "/users/:user-id" [] {:name :test/route16} handler)
(ANY "/orgs/:org-id" [] {:name :test/route18} handler))
(context "/users/:user-id" []
(ANY "/orgs/:org-id" [] {:name :test/route5} handler)
(ANY "/invitations" [] {:name :test/route7} handler)
(ANY "/topics" [] {:name :test/route9} handler)
(ANY "/bookmarks/followers" [] {:name :test/route10} handler)
(context "/devices" []
(ANY "/" [] {:name :test/route15} handler)
#_(ANY "/bulk" [] {:name :test/route21} handler)
(ANY "/:client-id" [] {:name :test/route35} handler)
(ANY "/:client-id/reset-password" [] {:name :test/route49} handler))
(ANY "/device-errors" [] {:name :test/route22} handler)
(ANY "/usage-stats" [] {:name :test/route24} handler)
(ANY "/claim-device/:client-id" [] {:name :test/route26} handler)
(ANY "/owned-orgs" [] {:name :test/route31} handler)
(ANY "/bookmark/:topic" [] {:name :test/route33} handler)
(ANY "/" [] {:name :test/route36} handler)
(ANY "/orgs" [] {:name :test/route52} handler)
(ANY "/api-key" [] {:name :test/route43} handler)
(ANY "/bookmarks" [] {:name :test/route56} handler))
(ANY "/search/topics/:term" [] {:name :test/route6} handler)
(context "/orgs" []
(ANY "/" [] {:name :test/route55} handler)
(context "/:org-id" []
(context "/devices" []
(ANY "/" [] {:name :test/route37} handler)
(ANY "/:device-id" [] {:name :test/route13} handler)
#_(ANY "/:batch/:type" [] {:name :test/route8} handler))
(ANY "/usage-stats" [] {:name :test/route12} handler)
(ANY "/invitations" [] {:name :test/route19} handler)
(context "/members" []
(ANY "/:user-id" [] {:name :test/route34} handler)
(ANY "/" [] {:name :test/route38} handler)
#_(ANY "/invitation-data/:user-id" [] {:name :test/route39} handler))
(ANY "/errors" [] {:name :test/route17} handler)
(ANY "/" [] {:name :test/route42} handler)
(ANY "/confirm-membership/:token" [] {:name :test/route46} handler)
(ANY "/topics" [] {:name :test/route57} handler)))
(context "/messages" []
(ANY "/user/:user-id" [] {:name :test/route14} handler)
(ANY "/device/:client-id" [] {:name :test/route30} handler)
(ANY "/topic/:topic" [] {:name :test/route48} handler))
(context "/topics" []
(ANY "/:topic" [] {:name :test/route32} handler)
(ANY "/" [] {:name :test/route54} handler))
(ANY "/whoami" [] {:name :test/route41} handler)
(ANY "/login" [] {:name :test/route51} handler))
(context "/public" []
(ANY "/topics/:topic" [] {:name :test/route4} handler)
(ANY "/users/:user-id" [] {:name :test/route16} handler)
(ANY "/orgs/:org-id" [] {:name :test/route18} handler))
(context "/users/:user-id" []
(ANY "/orgs/:org-id" [] {:name :test/route5} handler)
(ANY "/invitations" [] {:name :test/route7} handler)
(ANY "/topics" [] {:name :test/route9} handler)
(ANY "/bookmarks/followers" [] {:name :test/route10} handler)
(context "/devices" []
(ANY "/" [] {:name :test/route15} handler)
#_(ANY "/bulk" [] {:name :test/route21} handler)
(ANY "/:client-id" [] {:name :test/route35} handler)
(ANY "/:client-id/reset-password" [] {:name :test/route49} handler))
(ANY "/device-errors" [] {:name :test/route22} handler)
(ANY "/usage-stats" [] {:name :test/route24} handler)
(ANY "/claim-device/:client-id" [] {:name :test/route26} handler)
(ANY "/owned-orgs" [] {:name :test/route31} handler)
(ANY "/bookmark/:topic" [] {:name :test/route33} handler)
(ANY "/" [] {:name :test/route36} handler)
(ANY "/orgs" [] {:name :test/route52} handler)
(ANY "/api-key" [] {:name :test/route43} handler)
(ANY "/bookmarks" [] {:name :test/route56} handler))
(ANY "/search/topics/:term" [] {:name :test/route6} handler)
(context "/orgs" []
(ANY "/" [] {:name :test/route55} handler)
(context "/:org-id" []
(context "/devices" []
(ANY "/" [] {:name :test/route37} handler)
(ANY "/:device-id" [] {:name :test/route13} handler)
#_(ANY "/:batch/:type" [] {:name :test/route8} handler))
(ANY "/usage-stats" [] {:name :test/route12} handler)
(ANY "/invitations" [] {:name :test/route19} handler)
(context "/members" []
(ANY "/:user-id" [] {:name :test/route34} handler)
(ANY "/" [] {:name :test/route38} handler)
#_(ANY "/invitation-data/:user-id" [] {:name :test/route39} handler))
(ANY "/errors" [] {:name :test/route17} handler)
(ANY "/" [] {:name :test/route42} handler)
(ANY "/confirm-membership/:token" [] {:name :test/route46} handler)
(ANY "/topics" [] {:name :test/route57} handler)))
(context "/messages" []
(ANY "/user/:user-id" [] {:name :test/route14} handler)
(ANY "/device/:client-id" [] {:name :test/route30} handler)
(ANY "/topic/:topic" [] {:name :test/route48} handler))
(context "/topics" []
(ANY "/:topic" [] {:name :test/route32} handler)
(ANY "/" [] {:name :test/route54} handler))
(ANY "/whoami" [] {:name :test/route41} handler)
(ANY "/login" [] {:name :test/route51} handler))
(context "/v2" []
(ANY "/whoami" [] {:name :test/route1} handler)
(context "/users/:user-id" []
(ANY "/datasets" [] {:name :test/route2} handler)
(ANY "/devices" [] {:name :test/route25} handler)
(context "/topics" []
(ANY "/bulk" [] {:name :test/route29} handler)
(ANY "/" [] {:name :test/route54} handler))
(ANY "/" [] {:name :test/route45} handler))
(context "/public" []
(context "/projects/:project-id" []
(ANY "/datasets" [] {:name :test/route3} handler)
(ANY "/" [] {:name :test/route27} handler))
#_(ANY "/messages/dataset/bulk" [] {:name :test/route20} handler)
(ANY "/datasets/:dataset-id" [] {:name :test/route28} handler)
(ANY "/messages/dataset/:dataset-id" [] {:name :test/route53} handler))
(ANY "/datasets/:dataset-id" [] {:name :test/route11} handler)
(ANY "/login" [] {:name :test/route23} handler)
(ANY "/orgs/:org-id/topics" [] {:name :test/route40} handler)
(ANY "/schemas" [] {:name :test/route44} handler)
(ANY "/topics/:topic" [] {:name :test/route47} handler)
(ANY "/topics" [] {:name :test/route50} handler))))
(ANY "/whoami" [] {:name :test/route1} handler)
(context "/users/:user-id" []
(ANY "/datasets" [] {:name :test/route2} handler)
(ANY "/devices" [] {:name :test/route25} handler)
(context "/topics" []
(ANY "/bulk" [] {:name :test/route29} handler)
(ANY "/" [] {:name :test/route54} handler))
(ANY "/" [] {:name :test/route45} handler))
(context "/public" []
(context "/projects/:project-id" []
(ANY "/datasets" [] {:name :test/route3} handler)
(ANY "/" [] {:name :test/route27} handler))
#_(ANY "/messages/dataset/bulk" [] {:name :test/route20} handler)
(ANY "/datasets/:dataset-id" [] {:name :test/route28} handler)
(ANY "/messages/dataset/:dataset-id" [] {:name :test/route53} handler))
(ANY "/datasets/:dataset-id" [] {:name :test/route11} handler)
(ANY "/login" [] {:name :test/route23} handler)
(ANY "/orgs/:org-id/topics" [] {:name :test/route40} handler)
(ANY "/schemas" [] {:name :test/route44} handler)
(ANY "/topics/:topic" [] {:name :test/route47} handler)
(ANY "/topics" [] {:name :test/route50} handler))))
(def opensensors-pedestal-routes
(map-tree/router
@ -489,11 +417,6 @@
(if-not match
(println route))))
(doseq [route (valid-urls (reitit/router opensensors-routes))]
(let [match (opensensors-compojure-api-routes {:uri route :request-method :get})]
(if-not match
(println route))))
(doseq [route (valid-urls (reitit/router opensensors-routes))]
(let [match (pedestal/find-route opensensors-pedestal-routes {:path-info route :request-method :get})]
(if-not match
@ -507,27 +430,25 @@
bidi-f #(bidi/match-route opensensors-bidi-routes (:uri %))
ataraxy-f (partial ataraxy/matches opensensors-ataraxy-routes)
compojure-f opensensors-compojure-routes
compojure-api-f opensensors-compojure-api-routes
pedestal-f (partial pedestal/find-route opensensors-pedestal-routes)
b! (partial bench!! routes (fn [path] {:request-method :get, :uri path, :path-info path}) true)]
;; 2538ns
;; 2065ns
;; 662ns (prefix-tree-router)
;; 567ns (segment-router)
(b! "reitit" reitit-f)
;; 2845ns
;; 2316ns
;; 819ns (prefix-tree-router)
;; 723ns (segment-router)
(b! "reitit-ring" reitit-ring-f)
;; 2540ns
;; 2821ns
(b! "pedestal" pedestal-f)
;; 10300ns
(b! "compojure-api" compojure-api-f)
;; 10800ns
;; 11615ns
(b! "compojure" compojure-f)
;; 15034ns

View file

@ -49,7 +49,7 @@
"-Xmx4096m"
"-Dclojure.compiler.direct-linking=true"]
:test-paths ["perf-test/clj"]
:dependencies [[metosin/compojure-api "2.0.0-alpha12"]
:dependencies [[compojure "1.6.0"]
[io.pedestal/pedestal.route "0.5.3"]
[org.clojure/core.async "0.3.443"]
[ataraxy "0.4.0"]