如果我想计算朱莉娅的事情
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)
我该如何计算时间?我需要等待多少秒才能完成这四件事?我是否把tic()
放在开头,toc()
放在最后?
我试了@elapsed
,但没有结果。
基本方法是使用
@time begin
#code
end
但请注意,您永远不应该在全球范围内进行基准测试。
一个可以帮助你对代码进行基准测试的包是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()
如果您想从时间宏中获取适当的分配信息,我建议调用@time不在全局范围内。