我如何测量我的朱莉娅程序的时间?
问题描述:
如果我想在朱莉娅我如何测量我的朱莉娅程序的时间?
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
但请注意,您never should benchmark in the global scope 。
一个可以帮助您测试代码基准的软件包是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()
我建议,如果你从时间宏观喜欢to get proper allocation info调用@time不是在全局范围内。
最简单的版本可能是'使用BenchmarkTools; @btime begin ...' –
如果你这样做了,你必须记住插入变量。 –
特别是如果变量在全局范围内:joy: –