-
Notifications
You must be signed in to change notification settings - Fork 11
/
benchmark.clj
150 lines (114 loc) · 3.56 KB
/
benchmark.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
(ns benchmark
(:require
[pyramid.core :as p]
[criterium.core :as c]
[clj-async-profiler.core :as prof]))
(prof/serve-files 8080)
(prof/profile (dotimes [i 10000]
(p/db [{:person/id 123
:person/name "Will"
:contact {:phone "000-000-0001"}
:best-friend
{:person/id 456
:person/name "Jose"
:account/email "asdf@jkl"}
:friends
[{:person/id 9001
:person/name "Georgia"}
{:person/id 456
:person/name "Jose"}
{:person/id 789
:person/name "Frank"}
{:person/id 1000
:person/name "Robert"}]}
{:person/id 456
:best-friend {:person/id 123}}])))
(c/quick-bench
(p/db [{:person/id 123
:person/name "Will"
:contact {:phone "000-000-0001"}
:best-friend
{:person/id 456
:person/name "Jose"
:account/email "asdf@jkl"}
:friends
[{:person/id 9001
:person/name "Georgia"}
{:person/id 456
:person/name "Jose"}
{:person/id 789
:person/name "Frank"}
{:person/id 1000
:person/name "Robert"}]}
{:person/id 456
:best-friend {:person/id 123}}]))
(def big-data
[{:foo/data
(vec
(for [i (range 1000)]
{:foo/id (str "id" i)
:foo/name (str "bar" i)
:foo/metadata {:some ["dumb" "data"]}})) } ])
(c/quick-bench (p/db big-data))
(prof/profile
(dotimes [i 1000]
(p/db big-data)))
;; this throws w/ StackOverflow on my computer when running p/db
;; numbers 10000 and up throw when generating the tree
(def limit 7946)
(def nested-data
(letfn [(create [i]
(if (zero? i)
nil
{:id i
:child (create (dec i))}))]
{:foo (create limit) }))
(do (p/db [nested-data])
nil)
(c/quick-bench (p/db [nested-data]))
;; testing out different trampoline strategies
(defn create [k i]
(if (zero? i)
(k)
(fn []
(create
(fn []
{:id i
:child (k)})
(dec i)))))
(def really-nested-data
{:foo (trampoline create (constantly {:id 0}) 50000) })
(do (p/db [really-nested-data])
nil)
(c/quick-bench (p/db [really-nested-data]))
(prof/profile (dotimes [i 1000]
(p/db [really-nested-data])))
(def ppl-db
(p/db [{:person/id 123
:person/name "Will"
:contact {:phone "000-000-0001"}
:best-friend
{:person/id 456
:person/name "Jose"
:account/email "asdf@jkl"}
:friends
[{:person/id 9001
:person/name "Georgia"}
{:person/id 456
:person/name "Jose"}
{:person/id 789
:person/name "Frank"}
{:person/id 1000
:person/name "Robert"}]}
{:person/id 456
:best-friend {:person/id 123}}]))
(p/pull ppl-db [{[:person/id 123] [:person/id
:person/name
{:friends [:person/id :person/name]}]}])
(def query [{[:person/id 123] [:person/id
:person/name
{:friends [:person/id :person/name]}]}])
(c/quick-bench
(p/pull ppl-db query))
(prof/profile (dotimes [i 5000]
(p/pull ppl-db query)))