subset(xs,k) vs subset(xs) vs combinations(xs,k)
Closed this issue · 1 comments
christophfeinauer commented
Hi,
is there a reason why there is an extra implementation for subset(xs)? chain([subsets(xs,n) for n=0:length(xs)]...)
seems to do the same thing and is faster for me:
allsubsets(xs) = chain([subsets(xs,n) for n=0:length(xs)]...)
function test1()
n = 20
set = rand(n)
for s = subsets(set)
rand()
end
end
function test2()
n = 20
set = rand(n)
for s = allsubsets(set)
rand()
end
end
julia> test1(); test2(); @time test1(); @time test2();
3.905233 seconds (40.63 M allocations: 1.261 GB, 4.52% gc time)
1.446248 seconds (8.39 M allocations: 356.006 MB, 2.36% gc time)
Also, doesn't Base.combinations(xs,k) do the same thing as subsets(xs,k)?