Gab*_*abi 8 performance julia data-science
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
Run Code Online (Sandbox Code Playgroud)
更新:建议解决方案的代码
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
Run Code Online (Sandbox Code Playgroud)
tho*_*oly 10
至少有两种可能性:
我会把我的赌注押在前者身上.使用ProfileView.jl以图形方式轻松检测运行时分派.如果您在配置文件时看到很多红色条形图rungame,那么您就知道已找到问题的根源.除了与CSV的交互之外,消除那些红条可能会给您带来巨大的性能提升.