2
2
# BenchmarkGroup #
3
3
# #################
4
4
5
+ const KeyTypes = Union{String,Int,Float64}
6
+ makekey (v:: KeyTypes ) = v
7
+ makekey (v:: Real ) = (v2 = Float64 (v); v2 == v ? v2 : string (v))
8
+ makekey (v:: Integer ) = typemin (Int) <= v <= typemax (Int) ? Int (v) : string (v)
9
+ makekey (v:: Tuple ) = (Any[i isa Tuple ? string (i) : makekey (i) for i in v]. .. ,):: Tuple{Vararg{KeyTypes}}
10
+ makekey (v:: Any ) = string (v):: String
11
+
5
12
struct BenchmarkGroup
6
13
tags:: Vector{Any}
7
14
data:: Dict{Any,Any}
8
15
end
9
16
10
- BenchmarkGroup (tags:: Vector , args:: Pair... ) = BenchmarkGroup (tags, Dict ( args... ))
17
+ BenchmarkGroup (tags:: Vector , args:: Pair... ) = BenchmarkGroup (tags, Dict {Any,Any} (( makekey (k) => v for (k, v) in args) ))
11
18
BenchmarkGroup (args:: Pair... ) = BenchmarkGroup ([], args... )
12
19
13
20
function addgroup! (suite:: BenchmarkGroup , id, args... )
@@ -24,10 +31,14 @@ Base.copy(group::BenchmarkGroup) = BenchmarkGroup(copy(group.tags), copy(group.d
24
31
Base. similar (group:: BenchmarkGroup ) = BenchmarkGroup (copy (group. tags), empty (group. data))
25
32
Base. isempty (group:: BenchmarkGroup ) = isempty (group. data)
26
33
Base. length (group:: BenchmarkGroup ) = length (group. data)
27
- Base. getindex (group:: BenchmarkGroup , i... ) = getindex (group. data, i... )
28
- Base. setindex! (group:: BenchmarkGroup , i... ) = setindex! (group. data, i... )
29
- Base. delete! (group:: BenchmarkGroup , k... ) = delete! (group. data, k... )
30
- Base. haskey (group:: BenchmarkGroup , k) = haskey (group. data, k)
34
+ Base. getindex (group:: BenchmarkGroup , k) = getindex (group. data, makekey (k))
35
+ Base. getindex (group:: BenchmarkGroup , k... ) = getindex (group. data, makekey (k))
36
+ Base. setindex! (group:: BenchmarkGroup , v, k) = setindex! (group. data, v, makekey (k))
37
+ Base. setindex! (group:: BenchmarkGroup , v, k... ) = setindex! (group. data, v, makekey (k))
38
+ Base. delete! (group:: BenchmarkGroup , k) = delete! (group. data, makekey (k))
39
+ Base. delete! (group:: BenchmarkGroup , k... ) = delete! (group. data, makekey (k))
40
+ Base. haskey (group:: BenchmarkGroup , k) = haskey (group. data, makekey (k))
41
+ Base. haskey (group:: BenchmarkGroup , k... ) = haskey (group. data, makekey (k))
31
42
Base. keys (group:: BenchmarkGroup ) = keys (group. data)
32
43
Base. values (group:: BenchmarkGroup ) = values (group. data)
33
44
Base. iterate (group:: BenchmarkGroup , i= 1 ) = iterate (group. data, i)
@@ -119,11 +130,11 @@ end
119
130
# leaf iteration/indexing #
120
131
# -------------------------#
121
132
122
- leaves (group:: BenchmarkGroup ) = leaves! (Any [], Any [], group)
133
+ leaves (group:: BenchmarkGroup ) = leaves! ([], [], group)
123
134
124
135
function leaves! (results, parents, group:: BenchmarkGroup )
125
136
for (k, v) in group
126
- keys = vcat ( parents, k)
137
+ keys = Base . typed_vcat (Any, parents, k)
127
138
if isa (v, BenchmarkGroup)
128
139
leaves! (results, keys, v)
129
140
else
@@ -155,44 +166,44 @@ end
155
166
# tagging #
156
167
# ---------#
157
168
158
- struct TagFilter{P}
159
- predicate:: P
169
+ struct TagFilter
170
+ predicate
160
171
end
161
172
162
173
macro tagged (expr)
163
- return esc ( :(BenchmarkTools. TagFilter (tags -> $ (tagpredicate! (expr) ))))
174
+ return :(BenchmarkTools. TagFilter (tags -> $ (tagpredicate! (expr))))
164
175
end
165
176
166
- tagpredicate! (tag) = :(in ($ tag, tags))
177
+ tagpredicate! (@nospecialize tag) = :(in (makekey ( $ ( esc ( tag))) , tags))
167
178
168
179
function tagpredicate! (sym:: Symbol )
169
- sym == :! && return sym
170
180
sym == :ALL && return true
171
- return :(in ($ sym, tags))
181
+ return :(in (makekey ( $ ( esc ( sym))) , tags))
172
182
end
173
183
174
184
# build the body of the tag predicate in place
175
185
function tagpredicate! (expr:: Expr )
176
- expr. head == :quote && return :(in ($ expr, tags))
177
- for i in eachindex (expr. args)
178
- expr. args[i] = tagpredicate! (expr. args[i])
186
+ expr. head == :quote && return :(in (makekey ($ (esc (expr))), tags))
187
+ for i in 1 : length (expr. args)
188
+ f = (i == 1 && expr. head === :call ? esc : tagpredicate!)
189
+ expr. args[i] = f (expr. args[i])
179
190
end
180
191
return expr
181
192
end
182
193
183
194
function Base. getindex (src:: BenchmarkGroup , f:: TagFilter )
184
195
dest = similar (src)
185
- loadtagged! (f, dest, src, src, Any [], src. tags)
196
+ loadtagged! (f, dest, src, src, [], src. tags)
186
197
return dest
187
198
end
188
199
189
200
# normal union doesn't have the behavior we want
190
201
# (e.g. union(["1"], "2") === ["1", '2'])
191
- keyunion (args... ) = unique (vcat ( args... ))
202
+ keyunion (args... ) = unique (Base . typed_vcat (Any, args... ))
192
203
193
204
function tagunion (args... )
194
205
unflattened = keyunion (args... )
195
- result = Any []
206
+ result = []
196
207
for i in unflattened
197
208
if isa (i, Tuple)
198
209
for j in i
0 commit comments