9

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 and toc() at the end?

I tried @elapsed, but no results.

2 Answers 2

25

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.

Sign up to request clarification or add additional context in comments.

3 Comments

The easiest version of this is probably using BenchmarkTools; @btime begin...
If you do that, you have to remember to interpolate the variables though.
Especially if the variables are in global scope :joy:
5

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.