Hi,
Intrigued
by https://github.com/jesusfv/Comparison-Programming-Languages-Economics, I
did a little exercise
function valuefnc(x, V)
n=length(x)
a=0.1;
b=0.9;
out=zeros(n);
for(i=1:n)
out[i]=maximum(log((1 + x[i]^a) .- x) .+ b*V[i]);
end
out
end
And for the grid x=[1:10000]/10000, a single round of calculation takes
around 3 secs on my notebook. I thought it would be instantaneous.
n=length(x)
V0=zeros(n)
V1=valuefnc(x, V0)
@elapsed V2=valuefnc(x, V1)
Similar implementation in R takes about 2.5 secs.
sapply(1:length(x), function(i){max(log(1+x[i]^a - x) + b*V[i])})
What am I doing wrong here? I expected Julia would be faster by several
factors, but I am completely blind to code optimization in Julia.
Thanks