Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
[compat]
Aqua = "0.8"
Compat = "4.11"
JSON = "0.18, 0.19, 0.20, 0.21"
JSON = "0.18, 0.19, 0.20, 0.21, 1"
Logging = "<0.0.1, 1"
Printf = "<0.0.1, 1"
Profile = "<0.0.1, 1"
Expand Down
10 changes: 5 additions & 5 deletions src/serialization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function JSON.lower(x::Union{values(SUPPORTED_TYPES)...})
field = getfield(x, i)
ft = typeof(field)
value = ft <: get(SUPPORTED_TYPES, nameof(ft), Union{}) ? JSON.lower(field) : field
d[name] = value
d[name] = value isa Float64 && !isfinite(value) ? nothing : value
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a surprise to me; I didn't realize JSON pre-1.0 allowed writing Inf out by default (which is against JSON spec) as null. I tried to think about other ways we could try and compat this, but I think this is simplest.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Python does

>>> import json, math
>>> json.dumps(math.inf)
'Infinity'

end
return [string(nameof(typeof(x))), d]
end
Expand All @@ -41,7 +41,7 @@ end
function recover(x::Vector)
length(x) == 2 || throw(ArgumentError("Expecting a vector of length 2"))
typename = x[1]::String
fields = x[2]::Dict
fields = x[2]::AbstractDict
startswith(typename, "BenchmarkTools.") &&
(typename = typename[(sizeof("BenchmarkTools.") + 1):end])
T = SUPPORTED_TYPES[Symbol(typename)]
Expand All @@ -64,7 +64,7 @@ function recover(x::Vector)
convert(ft, fields[fn])
end
end
if T == BenchmarkGroup && xsi isa Dict
if T == BenchmarkGroup && xsi isa AbstractDict
for (k, v) in copy(xsi)
k = k::String
if startswith(k, "(") || startswith(k, ":")
Expand Down Expand Up @@ -154,11 +154,11 @@ function load(io::IO, args...)
parsed = JSON.parse(io)
if !isa(parsed, Vector) ||
length(parsed) != 2 ||
!isa(parsed[1], Dict) ||
!isa(parsed[1], AbstractDict) ||
!isa(parsed[2], Vector)
error("Unexpected JSON format. Was this file originally written by BenchmarkTools?")
end
versions = parsed[1]::Dict
versions = parsed[1]::AbstractDict
values = parsed[2]::Vector
return map!(recover, values, values)
end
51 changes: 37 additions & 14 deletions test/GroupsTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -361,28 +361,51 @@ g1["a"] = t1a
g1["b"] = t1b
g1["c"] = tc

@test sprint(show, g1) == """
# Test full output (order-independent)
output_full = sprint(show, g1)
@test startswith(
output_full,
"""
3-element BenchmarkTools.BenchmarkGroup:
tags: ["1", "2"]
"c" => TrialEstimate(1.000 ns)
"b" => TrialEstimate(4.123 μs)
"a" => TrialEstimate(32.000 ns)"""
@test sprint(show, g1; context=:boundto => 1) == """
""",
)
@test occursin(" \"a\" => TrialEstimate(32.000 ns)", output_full)
@test occursin(" \"b\" => TrialEstimate(4.123 μs)", output_full)
@test occursin(" \"c\" => TrialEstimate(1.000 ns)", output_full)

# Test boundto context output
output_boundto = sprint(show, g1; context=:boundto => 1)
@test startswith(
output_boundto,
"""
3-element BenchmarkTools.BenchmarkGroup:
tags: ["1", "2"]
"c" => TrialEstimate(1.000 ns)
⋮"""
@test sprint(show, g1; context=:limit => false) == """
""",
)

# Test limit => false output (order-independent)
output_no_limit = sprint(show, g1; context=:limit => false)
@test startswith(
output_no_limit,
"""
3-element BenchmarkTools.BenchmarkGroup:
tags: ["1", "2"]
"c" => TrialEstimate(1.000 ns)
"b" => TrialEstimate(4.123 μs)
"a" => TrialEstimate(32.000 ns)"""
@test @test_deprecated(sprint(show, g1; context=:limit => 1)) == """
""",
)
@test occursin(" \"a\" => TrialEstimate(32.000 ns)", output_no_limit)
@test occursin(" \"b\" => TrialEstimate(4.123 μs)", output_no_limit)
@test occursin(" \"c\" => TrialEstimate(1.000 ns)", output_no_limit)

# Test deprecated limit context output
output_limit_deprecated = @test_deprecated(sprint(show, g1; context=:limit => 1))
@test startswith(
output_limit_deprecated,
"""
3-element BenchmarkTools.BenchmarkGroup:
tags: ["1", "2"]
"c" => TrialEstimate(1.000 ns)
⋮"""
""",
)

# EasyConfig-style benchmark groups #
#-----------------------------------#
Expand Down
Loading