mirror of
https://github.com/metosin/reitit.git
synced 2025-12-18 08:51:12 +00:00
prefix-trie is faster now
This commit is contained in:
parent
e619234e84
commit
19213dcba7
1 changed files with 12 additions and 8 deletions
|
|
@ -2,7 +2,8 @@
|
||||||
(:require [clojure.test :refer :all]
|
(:require [clojure.test :refer :all]
|
||||||
[io.pedestal.http.route.prefix-tree :as p]
|
[io.pedestal.http.route.prefix-tree :as p]
|
||||||
[reitit.segment :as segment]
|
[reitit.segment :as segment]
|
||||||
[criterium.core :as cc]))
|
[criterium.core :as cc])
|
||||||
|
(:import (reitit Trie)))
|
||||||
|
|
||||||
;;
|
;;
|
||||||
;; testing
|
;; testing
|
||||||
|
|
@ -69,11 +70,13 @@
|
||||||
(p/insert acc p d))
|
(p/insert acc p d))
|
||||||
nil routes))
|
nil routes))
|
||||||
|
|
||||||
(def reitit-segment
|
(def matcher
|
||||||
(reduce
|
(.matcher
|
||||||
(fn [acc [p d]]
|
^Trie
|
||||||
(segment/insert acc p d))
|
(reduce
|
||||||
nil routes))
|
(fn [acc [p d]]
|
||||||
|
(segment/insert acc p d))
|
||||||
|
nil routes)))
|
||||||
|
|
||||||
(defn bench! []
|
(defn bench! []
|
||||||
|
|
||||||
|
|
@ -105,8 +108,9 @@
|
||||||
;; 1.0µs (Match records)
|
;; 1.0µs (Match records)
|
||||||
;; 0.63µs (Single sweep path paraµs)
|
;; 0.63µs (Single sweep path paraµs)
|
||||||
;; 0.51µs (Cleanup)
|
;; 0.51µs (Cleanup)
|
||||||
|
;; 0.33µs (Java)
|
||||||
(cc/quick-bench
|
(cc/quick-bench
|
||||||
(segment/lookup reitit-segment "/v1/orgs/1/topics")))
|
(segment/lookup matcher "/v1/orgs/1/topics")))
|
||||||
|
|
||||||
(comment
|
(comment
|
||||||
(bench!))
|
(bench!))
|
||||||
|
|
@ -114,4 +118,4 @@
|
||||||
(comment
|
(comment
|
||||||
(p/lookup pedestal-tree "/v1/orgs/1/topics")
|
(p/lookup pedestal-tree "/v1/orgs/1/topics")
|
||||||
#_(trie/lookup reitit-tree "/v1/orgs/1/topics" {})
|
#_(trie/lookup reitit-tree "/v1/orgs/1/topics" {})
|
||||||
(segment/lookup reitit-segment "/v1/orgs/1/topics"))
|
(segment/lookup matcher "/v1/orgs/1/topics"))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue