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
- tags:: Vector{String }
7
- data:: Dict{String ,Any}
13
+ tags:: Vector{Any }
14
+ data:: Dict{Any ,Any}
8
15
end
9
16
10
- BenchmarkGroup (tags:: Vector{String} , args:: Pair{String} ...) = BenchmarkGroup (tags, Dict {String,Any} (args))
11
- BenchmarkGroup (tags:: Vector , args:: Pair... ) = BenchmarkGroup (tags, Dict {String,Any} ((string (k) => v for (k, v) in args)))
12
- BenchmarkGroup (args:: Pair... ) = BenchmarkGroup (String[], args... )
17
+ BenchmarkGroup (tags:: Vector , args:: Pair... ) = BenchmarkGroup (tags, Dict {Any,Any} ((makekey (k) => v for (k, v) in args)))
18
+ BenchmarkGroup (args:: Pair... ) = BenchmarkGroup ([], args... )
13
19
14
20
function addgroup! (suite:: BenchmarkGroup , id, args... )
15
21
g = BenchmarkGroup (args... )
@@ -25,18 +31,14 @@ Base.copy(group::BenchmarkGroup) = BenchmarkGroup(copy(group.tags), copy(group.d
25
31
Base. similar (group:: BenchmarkGroup ) = BenchmarkGroup (copy (group. tags), empty (group. data))
26
32
Base. isempty (group:: BenchmarkGroup ) = isempty (group. data)
27
33
Base. length (group:: BenchmarkGroup ) = length (group. data)
28
- Base. getindex (group:: BenchmarkGroup , k:: String ) = getindex (group. data, k)
29
- Base. getindex (group:: BenchmarkGroup , k) = getindex (group. data, string (k))
30
- Base. getindex (group:: BenchmarkGroup , k... ) = getindex (group. data, string (k))
31
- Base. setindex! (group:: BenchmarkGroup , v, k:: String ) = setindex! (group. data, v, k)
32
- Base. setindex! (group:: BenchmarkGroup , v, k) = setindex! (group. data, v, string (k))
33
- Base. setindex! (group:: BenchmarkGroup , v, k... ) = setindex! (group. data, v, string (k))
34
- Base. delete! (group:: BenchmarkGroup , k:: String ) = delete! (group. data, k)
35
- Base. delete! (group:: BenchmarkGroup , k) = delete! (group. data, string (k))
36
- Base. delete! (group:: BenchmarkGroup , k... ) = delete! (group. data, string (k))
37
- Base. haskey (group:: BenchmarkGroup , k:: String ) = haskey (group. data, k)
38
- Base. haskey (group:: BenchmarkGroup , k) = haskey (group. data, string (k))
39
- Base. haskey (group:: BenchmarkGroup , k... ) = haskey (group. data, string (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))
40
42
Base. keys (group:: BenchmarkGroup ) = keys (group. data)
41
43
Base. values (group:: BenchmarkGroup ) = values (group. data)
42
44
Base. iterate (group:: BenchmarkGroup , i= 1 ) = iterate (group. data, i)
@@ -128,11 +130,11 @@ end
128
130
# leaf iteration/indexing #
129
131
# -------------------------#
130
132
131
- leaves (group:: BenchmarkGroup ) = leaves! (Any [], String [], group)
133
+ leaves (group:: BenchmarkGroup ) = leaves! ([], [], group)
132
134
133
135
function leaves! (results, parents, group:: BenchmarkGroup )
134
136
for (k, v) in group
135
- keys = vcat ( parents, k)
137
+ keys = Base . typed_vcat (Any, parents, k)
136
138
if isa (v, BenchmarkGroup)
137
139
leaves! (results, keys, v)
138
140
else
@@ -172,16 +174,16 @@ macro tagged(expr)
172
174
return :(BenchmarkTools. TagFilter (tags -> $ (tagpredicate! (expr))))
173
175
end
174
176
175
- tagpredicate! (@nospecialize tag) = :(in (string ($ (esc (tag))), tags))
177
+ tagpredicate! (@nospecialize tag) = :(in (makekey ($ (esc (tag))), tags))
176
178
177
179
function tagpredicate! (sym:: Symbol )
178
180
sym == :ALL && return true
179
- return :(in (string ($ (esc (sym))), tags))
181
+ return :(in (makekey ($ (esc (sym))), tags))
180
182
end
181
183
182
184
# build the body of the tag predicate in place
183
185
function tagpredicate! (expr:: Expr )
184
- expr. head == :quote && return :(in (string ($ (esc (expr))), tags))
186
+ expr. head == :quote && return :(in (makekey ($ (esc (expr))), tags))
185
187
for i in 1 : length (expr. args)
186
188
f = (i == 1 && expr. head === :call ? esc : tagpredicate!)
187
189
expr. args[i] = f (expr. args[i])
@@ -191,17 +193,17 @@ end
191
193
192
194
function Base. getindex (src:: BenchmarkGroup , f:: TagFilter )
193
195
dest = similar (src)
194
- loadtagged! (f, dest, src, src, String [], src. tags)
196
+ loadtagged! (f, dest, src, src, [], src. tags)
195
197
return dest
196
198
end
197
199
198
200
# normal union doesn't have the behavior we want
199
201
# (e.g. union(["1"], "2") === ["1", '2'])
200
- keyunion (args... ) = unique (vcat ( args... ))
202
+ keyunion (args... ) = unique (Base . typed_vcat (Any, args... ))
201
203
202
204
function tagunion (args... )
203
205
unflattened = keyunion (args... )
204
- result = String []
206
+ result = []
205
207
for i in unflattened
206
208
if isa (i, Tuple)
207
209
for j in i
@@ -215,7 +217,7 @@ function tagunion(args...)
215
217
end
216
218
217
219
function loadtagged! (f:: TagFilter , dest:: BenchmarkGroup , src:: BenchmarkGroup ,
218
- group:: BenchmarkGroup , keys:: Vector{String} , tags:: Vector{String} )
220
+ group:: BenchmarkGroup , keys:: Vector , tags:: Vector )
219
221
if f. predicate (tags)
220
222
child_dest = createchild! (dest, src, keys)
221
223
for (k, v) in group
0 commit comments