Reduce vs splat with intersect() function performance

You may look at the implementation of intersect here:

https://github.com/JuliaLang/julia/blob/788b2c77c10c2160f4794a4d4b6b81a95a90940c/base/abstractset.jl#L120

reduce(∩, [a, b, c, d]) == ∩(a, ∩(b, ∩(c, d)))

And the 2-argument intersect allocates a new destination each time, whereas the arbitrary elements intersect reuses the destination of 1 intersect call and then calls intersect! on that.

3 Likes