|
52 | 52 |
|
53 | 53 | (defn bench []
|
54 | 54 |
|
| 55 | + ; 27µs |
| 56 | + ; 27µs (-0%) |
| 57 | + ; 25µs (1.0.0) |
55 | 58 | (let [app (api
|
56 | 59 | (GET "/30" []
|
57 | 60 | (ok {:result 30})))
|
58 | 61 | call #(h/get* app "/30")]
|
59 | 62 |
|
60 | 63 | (title "GET JSON")
|
61 |
| - |
62 | 64 | (assert (= {:result 30} (second (call))))
|
63 | 65 | (cc/bench (call)))
|
64 | 66 |
|
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) |
67 | 70 | (let [app (api
|
68 | 71 | (POST "/plus" []
|
69 | 72 | :return {:result s/Int}
|
|
73 | 76 | call #(post* app "/plus" data)]
|
74 | 77 |
|
75 | 78 | (title "JSON POST with 2-way coercion")
|
76 |
| - |
77 | 79 | (assert (= {:result 30} (parse (call))))
|
78 | 80 | (cc/bench (call)))
|
79 | 81 |
|
80 |
| - ;; 73µs => 53µs (-27%) => 50µs |
81 |
| - |
| 82 | + ;; 85µs |
| 83 | + ;; 67µs (-21%) |
| 84 | + ;; 66µs (1.0.0) |
82 | 85 | (let [app (api
|
83 | 86 | (context "/a" []
|
84 | 87 | (context "/b" []
|
|
91 | 94 | call #(post* app "/a/b/c/plus" data)]
|
92 | 95 |
|
93 | 96 | (title "JSON POST with 2-way coercion + contexts")
|
94 |
| - |
95 | 97 | (assert (= {:result 30} (parse (call))))
|
96 | 98 | (cc/bench (call)))
|
97 | 99 |
|
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) |
100 | 103 | (let [app (api
|
101 | 104 | (POST "/echo" []
|
102 | 105 | :return Order
|
|
116 | 119 | call #(post* app "/echo" data)]
|
117 | 120 |
|
118 | 121 | (title "JSON POST with nested data")
|
119 |
| - |
120 | 122 | (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)))) |
126 | 124 |
|
127 | 125 | (defn resource-bench []
|
128 | 126 |
|
|
131 | 129 | :handler (fn [{{:keys [x y]} :body-params}]
|
132 | 130 | (ok {:result (+ x y)}))}}]
|
133 | 131 |
|
| 132 | + ;; 62µs |
134 | 133 | (let [my-resource (resource resource-map)
|
135 | 134 | app (api
|
136 | 135 | (context "/plus" []
|
|
139 | 138 | call #(post* app "/plus" data)]
|
140 | 139 |
|
141 | 140 | (title "JSON POST to pre-defined resource with 2-way coercion")
|
142 |
| - |
143 | 141 | (assert (= {:result 30} (parse (call))))
|
144 | 142 | (cc/bench (call)))
|
145 | 143 |
|
146 |
| - ;; 62µs |
147 |
| - |
| 144 | + ;; 68µs |
148 | 145 | (let [app (api
|
149 | 146 | (context "/plus" []
|
150 | 147 | (resource resource-map)))
|
151 | 148 | data (h/json {:x 10, :y 20})
|
152 | 149 | call #(post* app "/plus" data)]
|
153 | 150 |
|
154 | 151 | (title "JSON POST to inlined resource with 2-way coercion")
|
155 |
| - |
156 | 152 | (assert (= {:result 30} (parse (call))))
|
157 | 153 | (cc/bench (call)))
|
158 | 154 |
|
159 |
| - ;; 68µs |
160 |
| - |
| 155 | + ;; 26µs |
161 | 156 | (let [my-resource (resource resource-map)
|
162 | 157 | app my-resource
|
163 | 158 | data {:x 10, :y 20}
|
164 | 159 | call #(app {:request-method :post :uri "/irrelevant" :body-params data})]
|
165 | 160 |
|
166 | 161 | (title "direct POST to pre-defined resource with 2-way coercion")
|
167 |
| - |
168 | 162 | (assert (= {:result 30} (:body (call))))
|
169 | 163 | (cc/bench (call)))
|
170 | 164 |
|
171 |
| - ;; 26µs |
172 |
| - |
| 165 | + ;; 30µs |
173 | 166 | (let [my-resource (resource resource-map)
|
174 | 167 | app (context "/plus" []
|
175 | 168 | my-resource)
|
176 | 169 | data {:x 10, :y 20}
|
177 | 170 | call #(app {:request-method :post :uri "/plus" :body-params data})]
|
178 | 171 |
|
179 | 172 | (title "POST to pre-defined resource with 2-way coercion")
|
180 |
| - |
181 | 173 | (assert (= {:result 30} (:body (call))))
|
182 | 174 | (cc/bench (call)))
|
183 | 175 |
|
184 |
| - ;; 30µs |
185 |
| - |
| 176 | + ;; 40µs |
186 | 177 | (let [app (context "/plus" []
|
187 | 178 | (resource resource-map))
|
188 | 179 | data {:x 10, :y 20}
|
189 | 180 | call #(app {:request-method :post :uri "/plus" :body-params data})]
|
190 | 181 |
|
191 | 182 | (title "POST to inlined resource with 2-way coercion")
|
192 |
| - |
193 | 183 | (assert (= {:result 30} (:body (call))))
|
194 |
| - (cc/bench (call))) |
195 |
| - |
196 |
| - ;; 40µs |
197 |
| - )) |
| 184 | + (cc/bench (call))))) |
198 | 185 |
|
199 | 186 | (comment
|
200 | 187 | (bench)
|
|
0 commit comments