【发布时间】:2016-07-15 15:07:27
【问题描述】:
我尝试在 julia 命令中运行以下函数,但是在对函数计时时,我看到太多的内存分配,我不知道为什么。
function pdpf(L::Int64, iters::Int64)
snr_dB = -10
snr = 10^(snr_dB/10)
Pf = 0.01:0.01:1
thresh = rand(100)
Pd = rand(100)
for m = 1:length(Pf)
i = 0
for k = 1:iters
n = randn(L)
s = sqrt(snr) * randn(L)
y = s + n
energy_fin = (y'*y) / L
@inbounds thresh[m] = erfcinv(2Pf[m]) * sqrt(2/L) + 1
if energy_fin[1] >= thresh[m]
i += 1
end
end
@inbounds Pd[m] = i/iters
end
#thresh = erfcinv(2Pf) * sqrt(2/L) + 1
#Pd_the = 0.5 * erfc(((thresh - (snr + 1)) * sqrt(L)) / (2*(snr + 1)))
end
在我笔记本电脑上的 julia 命令中运行该函数,我得到以下令人震惊的数字:
julia> @time pdpf(1000, 10000)
17.621551 seconds (9.00 M allocations: 30.294 GB, 7.10% gc time)
我的代码有什么问题?任何帮助表示赞赏。
【问题讨论】:
标签: performance julia