How to measure time of julia program?
15,522
Solution 1
The basic way is to use
@time begin
#code
end
But note that you never should benchmark in the global scope.
A package that can help you benchmark your code is BenchmarkTools.jl which you should check out as well.
Solution 2
You could do something like this (I guess that g is input parameter):
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()
I propose to call @time not in global scope if you like to get proper allocation info from time macro.
Author by
Lucas G Leite F Pollito
Updated on June 17, 2022Comments
-
Lucas G Leite F Pollito almost 2 years
If I want to calculate for things in Julia
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)
How can I count the time? How many seconds do i have to wait for the four things up be done? Do I put
tic()
at the beginning andtoc()
at the end?I tried
@elapsed
, but no results.