mylog(x::Float64) = ccall((:log, "libm"), Float64, (Float64,),
x) made quite a bit of difference for me, from 1.92 to around 1.55. If I also add @inbounds, I go down to 1.45, making Julia only twice as sslow as C++. Numba still beats Julia, which kind of bothers me a bit
Thanks for the suggestions.
vGridCapital = 0.5*capitalSteadyState:0.00001:1.5*capitalSteadyState
vGridCapital = [0.5*capitalSteadyState:0.00001:1.5*capitalSteadyState]
using Winston
numba_times = readdlm("numba_times.dat")[10:end];
plot(numba_times)
julia_times = readdlm("julia_times.dat")[10:end];
plot(julia_times)
println((median(numba_times), mean(numba_times), var(numba_times)))
println((median(julia_times), mean(julia_times), var(julia_times)))
maxDifference = maximum(abs(mValueFunctionNew-mValueFunction))
mValueFunction = mValueFunctionNew
mValueFunctionNew = zeros(nGridCapital,nGridProductivity)
maxDifference = maximum(abs!(subtract!(mValueFunction, mValueFunctionNew)))
(mValueFunction, mValueFunctionNew) = (mValueFunctionNew, mValueFunction)
fill!(mValueFunctionNew, 0.0)
using NumericExtensions
@inbounds begin
...
end
maxDifference = 0.0
for k = 1:length(mValueFunction)
maxDifference = max(maxDifference, abs(mValueFunction[k]- mValueFunctionNew[k]))
end
I submitted three pull requests to the original repo that get rid of three different array allocations in loops and that make things a fair bit faster altogether:
https://github.com/jesusfv/Comparison-Programming-Languages-Economics/pulls
I think it would also make sense to run these benchmarks on julia 0.3.0 instead of 0.2.1, given that there have been a fair number of performance imrpovements.
Another interesting result from the paper is how much faster Visual C++ 2010 generated code is than gcc, on Windows. For their example, the gcc runtime is 2.29 the runtime of the MS compiled version. The difference might be even larger with Visual C++ 2013 because that is when MS added an auto-vectorizer that is on by default.
I vaguely remember a discussion about compiling julia itself with the MS compiler on Windows, is that working and is that making a performance difference?
I was more thinking that this might make a difference for some of the dependencies, like openblas? But I’m not even sure that can be compiled at all using MS compilers…
I just ran several of these benchmarks using the code and compilation flags available at https://github.com/jesusfv/Comparison-Programming-Languages-Economics . On my computer Julia is faster than C, C++, and Fortran, which I find surprising, unless some really dramatic optimization happened since 0.2.