Skip to content

Commit 030c568

Browse files
authored
Deserialize Inf correctly in some cases (#354)
* Deserialize Inf correctly in some cases Probably would be better to write Inf, -Inf, NaNs etc as strings so they can always be deserialized correctly. * Update Test name * Support Julia 1.0
1 parent f5a7494 commit 030c568

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/serialization.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ function recover(x::Vector)
5555
else
5656
xsi = if fn == "evals_set" && !haskey(fields, fn)
5757
false
58+
elseif fn in ("seconds", "overhead", "time_tolerance", "memory_tolerance") &&
59+
fields[fn] === nothing
60+
# JSON spec doesn't support Inf
61+
# These fields should all be >= 0, so we can ignore -Inf case
62+
typemax(ft)
5863
else
5964
convert(ft, fields[fn])
6065
end

test/SerializationTests.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,15 @@ end
113113
[BenchmarkTools.Parameters(5.0, 10000, 1, true, 0.0, true, false, 0.05, 0.01)]
114114
end
115115

116+
@testset "Inf in Paramters struct" begin
117+
params = BenchmarkTools.Parameters(Inf, 10000, 1, false, Inf, true, false, Inf, Inf)
118+
119+
io = IOBuffer()
120+
BenchmarkTools.save(io, params)
121+
json_string = String(take!(io))
122+
json_io = IOBuffer(json_string)
123+
124+
@test BenchmarkTools.load(json_io) == [params]
125+
end
126+
116127
end # module

0 commit comments

Comments
 (0)