I have implemented three functions to calculate the Fibonacci numbers like the following:
function fib(n::Integer)::BigInt
if n <= 1
n
else
fib(n-1) + fib(n-2)
end
end
**
fib2(n::Integer)::BigInt =round(BigInt,((1+sqrt(BigFloat(5)))/2)^n / sqrt(BigFloat(5)))
**
global cache = Dict{BigInt, BigInt}(0 => 0, 1 => 1)
function fib3(n::Integer)
global cache
if haskey(cache, n)
cache[n]
else
cache[n] = fib3(n-1) + fib3(n-2)
end
end
**
How can I use the macro @timed to plot the time and memory consumption of the
various functions to calculate Fibonacci numbers? I will be appreciated if someone can give me an example according to my code.
Updates :
I tried to do something like this
x=[1:3]
fib=[fib(5),fib2(5),fib3(5)]
y= [@timed fib[i] for i = 1:3]
using Plots
plot(x,y)
but it dosen’t work and i think the problem is how to handel ( plot ) in my case