81 lines
1.5 KiB
Julia
81 lines
1.5 KiB
Julia
using MsgPack
|
|
|
|
struct Timing
|
|
label::String
|
|
time::Float64
|
|
end
|
|
MsgPack.msgpack_type(::Type{Timing}) = MsgPack.StructType()
|
|
|
|
const timings = Buffer(1_000_000, "timings.msgpack", Timing)
|
|
|
|
struct X
|
|
el::Bool
|
|
N::Int
|
|
c::String
|
|
end
|
|
MsgPack.msgpack_type(::Type{X}) = MsgPack.StructType()
|
|
|
|
mkpath("results")
|
|
|
|
function microtest(t, ns)
|
|
label = "$(t)_$(ns)"
|
|
buf = Buffer(t, "results/$(label).msgpack", X, ns)
|
|
res = @timed begin
|
|
for i in 1:10000
|
|
push!(buf, X(1,i,string("c is: ", i)))
|
|
end
|
|
flush(buf)
|
|
end
|
|
close(buf)
|
|
(label, res[2])
|
|
end
|
|
|
|
function test(range)
|
|
for ns in range
|
|
for t in 1:1000
|
|
push!(timings,
|
|
Timing(microtest(t, ns)...))
|
|
end
|
|
end
|
|
end
|
|
|
|
test(1:5)
|
|
test(6:15:31)
|
|
test(10_000_000:10_000_000)
|
|
|
|
close(timing)
|
|
|
|
# Compare with the dumbest Array implementation
|
|
|
|
const dumbtimings = Buffer(1_000_000, "dumbtimings.msgpack", Timing)
|
|
|
|
function dumb(t, ns)
|
|
label = "dumb_$(t)_$(ns)"
|
|
name = "results/$(label).msgpack"
|
|
res = open(name, "a+") do out
|
|
buf = X[]
|
|
@timed begin
|
|
for i in 1:10000
|
|
push!(buf, X(1,i,string("c is: ", i)))
|
|
end
|
|
write.(Ref(out), pack.(buf))
|
|
empty!(buf)
|
|
end
|
|
end
|
|
(label, res[2])
|
|
end
|
|
|
|
|
|
function test_dumb(range)
|
|
for ns in range
|
|
for t in 1:1000
|
|
push!(dumbtimings,
|
|
Timing(dumb(t, ns)...))
|
|
end
|
|
end
|
|
end
|
|
|
|
test_dumb(1:5)
|
|
test_dumb(6:15:31)
|
|
test_dumb(10_000_000:10_000_000)
|