一、包的介绍
它可以展示一个火焰图,让你能够看到代码瓶颈在哪里,以便后期展开优化
【This package contains tools for visualizing profiling data collected with Julia's built-in sampling profiler. It can be helpful for getting a big-picture overview of the major bottlenecks in your code, and optionally highlights lines that trigger garbage collection as potential candidates for optimization.
This type of plot is known as a flame graph. The main logic is handled by the FlameGraphs package; this package is just a visualization front-end.
】
二、包的地址
https://github.com/timholy/ProfileView.jl
三、包的安装
using Pkg
Pkg.add("ProfileView")
四、包的用法
function profile_test(n)
for i = 1:n
A = randn(100,100,20)
m = maximum(A)
Am = mapslices(sum, A; dims=2)
B = A[:,:,5]
Bsort = mapslices(sort, B; dims=1)
b = rand(100)
C = B.*b
end
end
using ProfileView
@profview profile_test(1) # run once to trigger compilation (ignore this one)
@profview profile_test(10)
五、火焰图说明
整体的图
x轴——时间
y轴——调用的嵌套数
用鼠标悬停查看,各部分图对应的源码是那些,以便改进。下图最费时的地方经查询是一个groupby操作。
image.png六、改进groupby的部分
……
……
待补
网友评论