mirror of
https://github.com/metosin/reitit.git
synced 2025-12-16 16:01:11 +00:00
test perf with different json
This commit is contained in:
parent
60f10cdc01
commit
167de4d7a2
6 changed files with 91 additions and 0 deletions
1
dev-resources/json/json100b.json
Normal file
1
dev-resources/json/json100b.json
Normal file
|
|
@ -0,0 +1 @@
|
|||
{"number":100,"boolean":true,"list":[{"kikka":"kukka"}],"nested":{"map":"this is value","secret":1}}
|
||||
1
dev-resources/json/json100k.json
Normal file
1
dev-resources/json/json100k.json
Normal file
File diff suppressed because one or more lines are too long
1
dev-resources/json/json10b.json
Normal file
1
dev-resources/json/json10b.json
Normal file
|
|
@ -0,0 +1 @@
|
|||
{"imu":42}
|
||||
1
dev-resources/json/json10k.json
Normal file
1
dev-resources/json/json10k.json
Normal file
File diff suppressed because one or more lines are too long
1
dev-resources/json/json1k.json
Normal file
1
dev-resources/json/json1k.json
Normal file
|
|
@ -0,0 +1 @@
|
|||
{"results":[{"gender":"male","name":{"title":"mr","first":"morris","last":"lambert"},"location":{"street":"7239 hillcrest rd","city":"nowra","state":"australian capital territory","postcode":7541},"email":"morris.lambert@example.com","login":{"username":"smallbird414","password":"carole","salt":"yO9OBSsk","md5":"658323a603522238fb32a86b82eafd55","sha1":"289f6e9a8ccd42b539e0c43283e788aeb8cd0f6e","sha256":"57bca99b2b4e78aa2171eda4db3f35e7631ca3b30f157bdc7ea089a855c66668"},"dob":"1950-07-13 09:18:34","registered":"2012-04-07 00:05:32","phone":"08-2274-7839","cell":"0452-558-702","id":{"name":"TFN","value":"740213762"},"picture":{"large":"https://randomuser.me/api/portraits/men/95.jpg","medium":"https://randomuser.me/api/portraits/med/men/95.jpg","thumbnail":"https://randomuser.me/api/portraits/thumb/men/95.jpg"},"nat":"AU"}],"info":{"seed":"fb0c2b3c7cedc7af","results":1,"page":1,"version":"1.1"}}
|
||||
86
perf-test/clj/reitit/json_size_perf.cljc
Normal file
86
perf-test/clj/reitit/json_size_perf.cljc
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
(ns reitit.json-size-perf
|
||||
(:require [criterium.core :as cc]
|
||||
[reitit.perf-utils :refer :all]
|
||||
[reitit.ring :as ring]
|
||||
[muuntaja.middleware :as mm]
|
||||
[reitit.coercion.spec]
|
||||
[reitit.ring.coercion]
|
||||
[jsonista.core :as j]))
|
||||
|
||||
;;
|
||||
;; 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 test! []
|
||||
(let [json-request (fn [data]
|
||||
{:uri "/echo"
|
||||
:request-method :post
|
||||
:headers {"content-type" "application/json"
|
||||
"accept" "application/json"}
|
||||
:body (j/write-value-as-string data)})
|
||||
request-stream (fn [request]
|
||||
(let [b (.getBytes ^String (:body request))]
|
||||
(fn []
|
||||
(assoc request :body (java.io.ByteArrayInputStream. b)))))
|
||||
app (ring/ring-handler
|
||||
(ring/router
|
||||
["/echo"
|
||||
{:post {:parameters {:body any?}
|
||||
:coercion reitit.coercion.spec/coercion
|
||||
:handler (fn [request]
|
||||
(let [body (-> request :parameters :body)]
|
||||
{:status 200
|
||||
:body body}))}}]
|
||||
{:data {:middleware [mm/wrap-format
|
||||
reitit.ring.coercion/coerce-request-middleware]}}))]
|
||||
(doseq [file ["dev-resources/json/json10b.json"
|
||||
"dev-resources/json/json100b.json"
|
||||
"dev-resources/json/json1k.json"
|
||||
"dev-resources/json/json10k.json"
|
||||
"dev-resources/json/json100k.json"]
|
||||
:let [data (j/read-value (slurp file))
|
||||
request (json-request data)
|
||||
request! (request-stream request)]]
|
||||
|
||||
"10b"
|
||||
;; 38µs (c-api 1.x)
|
||||
;; 14µs (c-api 2.0.0-alpha21)
|
||||
;; 6µs
|
||||
|
||||
"100b"
|
||||
;; 74µs (c-api 1.x)
|
||||
;; 16µs (c-api 2.0.0-alpha21)
|
||||
;; 8µs
|
||||
|
||||
"1k"
|
||||
;; 322µs (c-api 1.x)
|
||||
;; 24µs (c-api 2.0.0-alpha21)
|
||||
;; 16µs
|
||||
|
||||
"10k"
|
||||
;; 3300µs (c-api 1.x)
|
||||
;; 120µs (c-api 2.0.0-alpha21)
|
||||
;; 110µs
|
||||
|
||||
"100k"
|
||||
;; 10600µs (c-api 1.x)
|
||||
;; 1100µs (c-api 2.0.0-alpha21)
|
||||
;; 1100µs
|
||||
|
||||
(title file)
|
||||
#_(println (-> (request!) app :body slurp))
|
||||
(cc/quick-bench (app (request!))))))
|
||||
|
||||
(comment
|
||||
(test!))
|
||||
Loading…
Reference in a new issue