Skip to content

Commit a484434

Browse files
committed
Cleanup
1 parent 5de270c commit a484434

File tree

1 file changed

+19
-32
lines changed

1 file changed

+19
-32
lines changed

test/compojure/api/perf_test.clj

Lines changed: 19 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,21 @@
5252

5353
(defn bench []
5454

55+
; 27µs
56+
; 27µs (-0%)
57+
; 25µs (1.0.0)
5558
(let [app (api
5659
(GET "/30" []
5760
(ok {:result 30})))
5861
call #(h/get* app "/30")]
5962

6063
(title "GET JSON")
61-
6264
(assert (= {:result 30} (second (call))))
6365
(cc/bench (call)))
6466

65-
; 27µs => 27µs (-0%) => 25µs (1.0.0)
66-
67+
;; 73µs
68+
;; 53µs (-27%)
69+
;; 50µs (1.0.0)
6770
(let [app (api
6871
(POST "/plus" []
6972
:return {:result s/Int}
@@ -73,12 +76,12 @@
7376
call #(post* app "/plus" data)]
7477

7578
(title "JSON POST with 2-way coercion")
76-
7779
(assert (= {:result 30} (parse (call))))
7880
(cc/bench (call)))
7981

80-
;; 73µs => 53µs (-27%) => 50µs
81-
82+
;; 85µs
83+
;; 67µs (-21%)
84+
;; 66µs (1.0.0)
8285
(let [app (api
8386
(context "/a" []
8487
(context "/b" []
@@ -91,12 +94,12 @@
9194
call #(post* app "/a/b/c/plus" data)]
9295

9396
(title "JSON POST with 2-way coercion + contexts")
94-
9597
(assert (= {:result 30} (parse (call))))
9698
(cc/bench (call)))
9799

98-
;; 85µs => 67µs (-21%) => 66µs (1.0.0)
99-
100+
;; 266µs
101+
;; 156µs (-41%)
102+
;; 146µs (1.0.0)
100103
(let [app (api
101104
(POST "/echo" []
102105
:return Order
@@ -116,13 +119,8 @@
116119
call #(post* app "/echo" data)]
117120

118121
(title "JSON POST with nested data")
119-
120122
(s/validate Order (parse (call)))
121-
(cc/bench (call)))
122-
123-
;; 266µs => 156µs (-41%) => 146µs (1.0.0)
124-
125-
)
123+
(cc/bench (call))))
126124

127125
(defn resource-bench []
128126

@@ -131,6 +129,7 @@
131129
:handler (fn [{{:keys [x y]} :body-params}]
132130
(ok {:result (+ x y)}))}}]
133131

132+
;; 62µs
134133
(let [my-resource (resource resource-map)
135134
app (api
136135
(context "/plus" []
@@ -139,62 +138,50 @@
139138
call #(post* app "/plus" data)]
140139

141140
(title "JSON POST to pre-defined resource with 2-way coercion")
142-
143141
(assert (= {:result 30} (parse (call))))
144142
(cc/bench (call)))
145143

146-
;; 62µs
147-
144+
;; 68µs
148145
(let [app (api
149146
(context "/plus" []
150147
(resource resource-map)))
151148
data (h/json {:x 10, :y 20})
152149
call #(post* app "/plus" data)]
153150

154151
(title "JSON POST to inlined resource with 2-way coercion")
155-
156152
(assert (= {:result 30} (parse (call))))
157153
(cc/bench (call)))
158154

159-
;; 68µs
160-
155+
;; 26µs
161156
(let [my-resource (resource resource-map)
162157
app my-resource
163158
data {:x 10, :y 20}
164159
call #(app {:request-method :post :uri "/irrelevant" :body-params data})]
165160

166161
(title "direct POST to pre-defined resource with 2-way coercion")
167-
168162
(assert (= {:result 30} (:body (call))))
169163
(cc/bench (call)))
170164

171-
;; 26µs
172-
165+
;; 30µs
173166
(let [my-resource (resource resource-map)
174167
app (context "/plus" []
175168
my-resource)
176169
data {:x 10, :y 20}
177170
call #(app {:request-method :post :uri "/plus" :body-params data})]
178171

179172
(title "POST to pre-defined resource with 2-way coercion")
180-
181173
(assert (= {:result 30} (:body (call))))
182174
(cc/bench (call)))
183175

184-
;; 30µs
185-
176+
;; 40µs
186177
(let [app (context "/plus" []
187178
(resource resource-map))
188179
data {:x 10, :y 20}
189180
call #(app {:request-method :post :uri "/plus" :body-params data})]
190181

191182
(title "POST to inlined resource with 2-way coercion")
192-
193183
(assert (= {:result 30} (:body (call))))
194-
(cc/bench (call)))
195-
196-
;; 40µs
197-
))
184+
(cc/bench (call)))))
198185

199186
(comment
200187
(bench)

0 commit comments

Comments
 (0)