Julia:从代码中访问@time计时和内存分配值

pet*_*r-b 2 profiling julia

我正在分析我的Julia应用程序,特别是函数调用的执行时间和内存分配.我想自动将这些信息存储到数据库中,以便它可以在没有监督的情况下运行.

我想要存储的信息是由@time以下形式返回的:

@time some_function()
 86.278909 seconds (6.94 M allocations: 383.520 MB, 0.08% gc time)
Run Code Online (Sandbox Code Playgroud)

是否可以从代码本身访问此信息,而不是仅仅打印出来?

我知道我可以使用tic()和访问时间组件toq(),但是内存分配怎么样?

Ste*_*ski 6

有一个@timed宏可以为您提供所有这些信息:

julia> @timed sleep(1)
(nothing,1.00417,624,0.0,Base.GC_Diff(624,0,0,13,0,0,0,0,0))

help?> @timed
  @timed

  A macro to execute an expression, and return the value of the expression, elapsed
  time, total bytes allocated, garbage collection time, and an object with various
  memory allocation counters.
Run Code Online (Sandbox Code Playgroud)