Hi
this gets execution time down to 0.9 on my machine:
function sub(val, num, tot, res, pos, allres)
if val==tot && num==0
push!(allres, res)
elseif tot<val && num>0 && !isempty(pos)
sub(val, num-1, tot+pos[1], push!(copy(res),pos[1]), pos[2:end],
sub(val, num, tot, res, pos[2:end], allres))
else
allres
end
end
function decompose(val, num)
sub(val, num, 0, Int16[], 1:(max(num, 10))-1, Array[])
end
Regards,
-Patrick
On Monday, October 19, 2015 at 10:13:44 AM UTC+2, Jonathan Malmaud wrote:
>
> Additionally, using closures/nested functions can often negatively impact
> performance due to an implementation detail of Julia that is actively being
> resolved.
>
> Try moving "sub" to the top level and having it take "val" as an explicit
> parameter - I'd be curious how that, plus the switch to push!, ultimately
> impacts running time. If you could post the final optimized program for
> posterity's sake, that would be great!
>