Julia is usually very fast in nested loops, so if they work correctly for you, you should control the performance, maybe just stick to it.
Another option would be to use repmat (this is slightly faster than using repeat):
[repmat(x,1,length(y))'[:] repmat(y,length(x),1)[:]]
Was there a quick test of both methods:
x=rand(1000) y=rand(1000) function withrepeat(x,y) [repeat(x, inner=[size(y,1)]) repeat(y, outer=[size(x,1)])] end function withrepmat(x,y) [repmat(x,1,length(y))'[:] repmat(y,length(x),1)[:]] end withrepeat(x,y) elapsed time: 0.21556302 seconds (95986112 bytes allocated) with repmat(x,y) elapsed time: 0.075604488 seconds (56000560 bytes allocated)
Not sure why there is so much difference, and I think there is still room for improvement. They did not try to use the product function inside the Iterators.jl package.
Also a bit more info here: https://groups.google.com/forum/#!topic/julia-users/dtl--SyFgwY
Hope this helps.
Tried a couple of nested loops and really faster:
function withloops (x,y) leny=length(y) lenx=length(x) m=leny*lenx OUT = zeros(Float64, m,2) c=1 for i = 1:lenx for j = 1:leny OUT[c,1] = x[i] OUT[c,2] = y[j] c+=1 end end return OUT end
And for the same rand(1000) for x and y .
withloops(x,y) elapsed time: 0.011350679 seconds (16000128 bytes allocated)