# @timed to plot the time and memory consumption

**URL:** <https://discourse.julialang.org/t/timed-to-plot-the-time-and-memory-consumption/37477>\
**Category:** General Usage\
**Tags:** question, plotting\
**Created:** [April 13, 2020, 12:23am UTC](https://discourse.julialang.org/t/timed-to-plot-the-time-and-memory-consumption/37477 "2020-04-13T00:23:13Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![A.U.M](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@A.U.M](https://discourse.julialang.org/u/A.U.M)\
**Post date:** [April 13, 2020, 12:23am UTC](https://discourse.julialang.org/t/timed-to-plot-the-time-and-memory-consumption/37477/1 "2020-04-13T00:23:13Z")

</div>

Hello,  
I am new to Julia. I have implemented different type of functions ( Fib 1 , Fib2, … etc ) to calculate Fibonacci numbers in different ways. How can I Use the macro @timed to plot the time and memory consumption of the various functions?

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [April 13, 2020, 4:58am UTC](https://discourse.julialang.org/t/timed-to-plot-the-time-and-memory-consumption/37477/2 "2020-04-13T04:58:35Z")

</div>

Welcome to the Julia Discourse forum!

See the docstring of the macro (`?@timed`), which has an example.

Also, please quote your code, and provide an MWE if you need further help.

> [@Please read: make it easier to help you](https://discourse.julialang.org/t/psa-make-it-easier-to-help-you/14757/):
>
> Welcome to the Julia Discourse! We are enthusiastic about helping Julia programmers, both beginner and experienced. This public service announcement (PSA) outlines best practices when asking for help. Following these points makes it easier for us to help you and more likely you’ll get a prompt, useful answer. Keywords are highlighted to make it easier to refer to specific points. Choose a descriptive title that captures the key part of your question, eg “plots with multiple axes” instead of …

---

<div class="post-metadata">

**Author:** ![johnh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/johnh/32/3615_2.png) [@johnh](https://discourse.julialang.org/u/johnh)\
**Post date:** [April 13, 2020, 8:24am UTC](https://discourse.julialang.org/t/timed-to-plot-the-time-and-memory-consumption/37477/3 "2020-04-13T08:24:06Z")

</div>

Hello @A.U.M and welcome.  
Tamas is saying that Julia has a built in help system.

There are three modes in the Julia REPL.  
the normal julia\> mode where you can type in and execute code  
The pkg\> mode where you can add and view package information

Press the ? character and you go into the help?\> mode  
You can then type @timed to get some help in the timed macro. Or you can get help on functions.  
Give it a try!

---

<div class="post-metadata">

**Author:** ![Iagoba\_Apellaniz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/iagoba_apellaniz/32/34406_2.png) [@Iagoba\_Apellaniz](https://discourse.julialang.org/u/Iagoba_Apellaniz)\
**Post date:** [April 13, 2020, 9:40am UTC](https://discourse.julialang.org/t/timed-to-plot-the-time-and-memory-consumption/37477/4 "2020-04-13T09:40:49Z")

</div>

Hey Amrusama! Welcome!

You can find this thread useful for getting the time [How to save @time output in a file or variable?](https://discourse.julialang.org/t/how-to-save-time-output-in-a-file-or-variable/11218) I’ll try to find something for the memory consumption. Maybe some hack over `@time`??

UPDATE: I guess that the second value of `@timed` is for the time and the third is for the memory. Since the first is for the result, you can collect all three in a row. NOT working example, this is only to explain myself,

```julia
julia> for i in 1:100
           rows[i] = (@timed i^2)[1:3]
       end

julia> plot(1:100, [rows[i][1] for i in 1:100]) # for the result of ^2

julia> plot(1:100, [rows[i][2] for i in 1:100]) # for the timing

julia> plot(1:100, [rows[i][3] for i in 1:100]) # for the memory

```

I guess that there are better options to do this.

---

<div class="post-metadata">

**Author:** ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Post date:** [April 13, 2020, 6:46pm UTC](https://discourse.julialang.org/t/timed-to-plot-the-time-and-memory-consumption/37477/5 "2020-04-13T18:46:42Z")

</div>

Note that if you want to do any serious measuring you should consider using [BenchmarkTools.jl](https://github.com/JuliaCI/BenchmarkTools.jl/blob/master/doc/manual.md), or at very least call every method you want to test a single time before measuring the time, to avoid counting the compilation time.

---

<div class="post-metadata">

**Author:** ![A.U.M](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@A.U.M](https://discourse.julialang.org/u/A.U.M)\
**Post date:** [April 14, 2020, 2:54pm UTC](https://discourse.julialang.org/t/timed-to-plot-the-time-and-memory-consumption/37477/6 "2020-04-14T14:54:25Z")

</div>

For example, these two functions  
fib1(n::Integer)::BigInt = round(BigInt, ((1+sqrt(5))/2)^n / sqrt(5))

function fib2(n::Integer)::BigInt  
if n \<= 1  
n  
else  
fib2(n-1) + fib2(n-2)  
end  
end

how can i plot the time and memory consumption of these two functions using micro @timed ?

---

<div class="post-metadata">

**Author:** ![A.U.M](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@A.U.M](https://discourse.julialang.org/u/A.U.M)\
**Post date:** [April 14, 2020, 2:58pm UTC](https://discourse.julialang.org/t/timed-to-plot-the-time-and-memory-consumption/37477/7 "2020-04-14T14:58:37Z")

</div>

For example, these two functions

fib1(n::Integer)::BigInt = round(BigInt, ((1+sqrt(5))/2)^n / sqrt(5))

function fib2(n::Integer)::BigInt  
if n \<= 1  
n  
else  
fib2(n-1) + fib2(n-2)  
end  
end

how can i plot the time and memory consumption of these two functions using micro @timed ?
