如果我想计算朱莉娅的东西
invQa = ChebyExp(g->1/Q(g),0,1,5)
a1Inf = ChebyExp(g->Q(g),1,10,5)
invQb = ChebyExp(g->1/Qd(g),0,1,5)
Qb1Inf = ChebyExp(g->Qd(g),1,10,5)
Run Code Online (Sandbox Code Playgroud)
我怎么能算上时间?我需要等多少秒才能完成这四件事?我tic()是在开头还是toc()结尾?
我试过了@elapsed,但没有结果.
基本的方法是使用
@time begin
#code
end
Run Code Online (Sandbox Code Playgroud)
但请注意,您永远不应该在全球范围内进行基准测试.
一个可以帮助您对代码进行基准测试的软件包是BenchmarkTools.jl,您也应该查看它.
你可以这样做(我猜 g 是输入参数):
function cheby_test(g::Your_Type)
invQa = ChebyExp(g->1/Q(g),0,1,5)
a1Inf = ChebyExp(g->Q(g),1,10,5)
invQb = ChebyExp(g->1/Qd(g),0,1,5)
Qb1Inf = ChebyExp(g->Qd(g),1,10,5)
end
function test()
g::Your_Type = small_quick #
cheby_test(g) #= function is compiled here and
you like to exclude compile time from test =#
g = real_data()
@time cheby_test(g) # here you measure time for real data
end
test()
Run Code Online (Sandbox Code Playgroud)
如果您想从时间宏获取正确的分配信息,我建议不在全局范围内调用@time 。