Skip to content

Commit 89f44ab

Browse files
committed
add select perf code
1 parent 0acf9d3 commit 89f44ab

File tree

1 file changed

+47
-0
lines changed
  • src/test/clojure/clojure/test_clojure

1 file changed

+47
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
(ns clojure.test-clojure.perf
2+
(:require
3+
[clojure.string :as str]
4+
[clojure.alpha.spec :as s]
5+
[clojure.alpha.spec.gen :as gen]))
6+
7+
(s/def ::a int?)
8+
(s/def ::b keyword?)
9+
(s/def ::attribute (s/schema {:a ::a
10+
:b ::b}))
11+
12+
(defn id? [s] (str/starts-with? s "I"))
13+
(s/def ::id (s/with-gen (s/and string? id?)
14+
(fn [] (gen/fmap #(str "I" %) (s/gen (s/spec int?))))))
15+
(s/def ::first string?)
16+
(s/def ::last string?)
17+
(s/def ::user (s/schema {:first ::first
18+
:last ::last
19+
:id ::id
20+
:attributes (s/coll-of ::attribute)}))
21+
22+
(s/def ::user1
23+
(s/select ::user
24+
[:attributes {:attributes [:a :b]}
25+
:first
26+
:last]))
27+
28+
;; make 100x100 samples - restarting to avoid getting too complex
29+
(def samples
30+
(mapcat
31+
(fn [_] (gen/sample (s/gen ::user1) 100))
32+
(range 100)))
33+
34+
;; perf test
35+
(defn perf
36+
[reps f]
37+
(dotimes [_ reps]
38+
(time
39+
(run! #(f ::user1 %) samples))))
40+
41+
(comment
42+
(take 10 samples)
43+
44+
(perf 5 s/valid?)
45+
(perf 5 s/explain-data)
46+
47+
)

0 commit comments

Comments
 (0)