导入不相关的软件包deepcopy
后,CSV
的性能会受到影响。我该如何解决?
import BenchmarkTools
mutable struct GameState
gameScore::Vector{Int64}
setScore::Vector{Int64}
matchScore::Vector{Int64}
serve::Int64
end
BenchmarkTools.@benchmark deepcopy(GameState([0,0],[0,0],[0,0],-1))
BenchmarkTools.Trial:
memory estimate: 1.02 KiB
allocs estimate: 10
--------------
minimum time: 1.585 μs (0.00% GC)
median time: 1.678 μs (0.00% GC)
mean time: 2.519 μs (27.10% GC)
maximum time: 5.206 ms (99.88% GC)
--------------
samples: 10000
evals/sample: 10
import CSV
BenchmarkTools.@benchmark deepcopy(GameState([0,0],[0,0],[0,0],-1))
BenchmarkTools.Trial:
memory estimate: 1.02 KiB
allocs estimate: 10
--------------
minimum time: 6.709 μs (0.00% GC)
median time: 7.264 μs (0.00% GC)
mean time: 9.122 μs (18.00% GC)
maximum time: 13.289 ms (99.87% GC)
--------------
samples: 10000
evals/sample: 5
更新:建议解决方案的代码
import Base:deepcopy
function deepcopy(x::GameState)
return GameState([x.gameScore[1], x.gameScore[2]], [x.setScore[1], x.setScore[2]], [x.matchScore[1], x.matchScore[2]],x.serve)
end
BenchmarkTools.@benchmark deepcopy(GameState([0,0],[0,0],[0,0],-1))
BenchmarkTools.Trial:
memory estimate: 672 bytes
allocs estimate: 8
--------------
minimum time: 184.436 ns (0.00% GC)
median time: 199.305 ns (0.00% GC)
mean time: 256.366 ns (21.29% GC)
maximum time: 102.345 μs (99.52% GC)
--------------
samples: 10000
evals/sample: 656
答案 0 :(得分:10)
至少有两种可能性:
我将赌注押在前者上。使用ProfileView.jl以图形方式轻松检测运行时调度。如果您在剖析rungame
时在顶部看到很多红色条,则说明您已找到问题的根源。除了与CSV交互之外,消除这些红色条可能会给您带来巨大的性能提升。