File tree Expand file tree Collapse file tree 1 file changed +47
-0
lines changed
src/test/clojure/clojure/test_clojure Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Original file line number Diff line number Diff line change
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
+ )
You can’t perform that action at this time.
0 commit comments