[英]How can I measure the RAM consumption and the time of computing in Julia?
I'm developing different discretization schemes and in order to find out wich is the most effiecient one I would like to determine the maximun RAM comsuption and the time that takes to do an specifyc task, such as solving a system of equations, overwritting a matrix or writting the data to a file.我正在开发不同的离散化方案,为了找出最有效的离散化方案,我想确定最大 RAM 消耗和执行指定任务所需的时间,例如求解方程组、覆盖矩阵或将数据写入文件。
Is there any kind of code or something for doing what I need?有什么代码或东西可以做我需要的吗? I'm using Julia in Ubuntu by the way, but I could do it in Windows as well.
顺便说一下,我在 Ubuntu 中使用 Julia,但我也可以在 Windows 中使用它。
Thanks a lot非常感谢
I love using the built-in @time
for this kind of thing.我喜欢使用内置的
@time
来处理这种事情。 See "Measure performance with @time and pay attention to memory allocation" .请参阅“使用@time 衡量性能并注意内存分配” 。 Example:
示例:
julia> @time myAwesomeFunction(tmp);
1.293542 seconds (22.08 M allocations: 893.866 MiB, 6.62% gc time)
This prints out time, the number of memory allocations, the size of memory allocations, and the percent time spent garbage collecting ("gc").这会打印出时间、内存分配的数量、内存分配的大小以及垃圾收集(“gc”)所花费的时间百分比。 Always run this at least twice —the first run will be dominated by compile times!
始终至少运行两次——第一次运行将取决于编译时间!
Also consider BenchmarkTools.jl .还要考虑BenchmarkTools.jl 。 This will run the code multiple times, with some cool variable interpolation tricks, and give you better runtime/memory estimates:
这将多次运行代码,并使用一些很酷的变量插值技巧,并为您提供更好的运行时间/内存估计:
julia> using BenchmarkTools, Compat
julia> @btime myAwesomeFunction($tmp);
1.311 s (22080097 allocations: 893.87 MiB)
(My other favorite performance-related thing is the @code_*
family of functions like @code_warntype
.) (我最喜欢的另一个与性能相关的东西是
@code_*
函数系列,比如@code_warntype
。)
I think that BenchmarkTools.jl
measures total memory use, not peak.我认为
BenchmarkTools.jl
衡量的是总内存使用量,而不是峰值。 I haven't found pure Julia code to measure this, but perhaps this thread is relevant.我还没有找到纯 Julia 代码来衡量这一点,但也许这个线程是相关的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.