Julia Beginner (from Python): Numba outperforms Julia in rewrite. Any tips to improve performance?

This is probalby a MWE for the critical loop, in Julia:

using BenchmarkTools
using LoopVectorization

function get_gains!(x, y, idxs, gains)
    @tturbo for i in eachindex(idxs)
        s = 0.0
        for j in eachindex(y)
            s += sqrt(y[j] + x[j, idxs[i]])
        end
        gains[i] = s
    end
end;

d = 54
n = 581012
x = rand(54, 581012)*100;
y = zeros(Float64, d)
idxs = collect(1:n);
gains = zeros(Float64, n);

@benchmark get_gains!($x, $y, $idxs, $gains)

Do you agree this is the bottleneck? But I’m too unfamiliar with Python and Numba to be sure to write something comparable there.

If we can really localize and quantify the performance difference, than we can post an issue, somewhere so someone can take a look at it.

ps: what is the Python time for the naive greedy algorithm in this case?

1 Like