I suspect foldl
’s guaranteed associativity means that it has to allocate a new matrix for the result of hcat
for every single column. That’s unnecessary and wasteful, but it’s required by the guarantee that foldl makes. Since reduce
makes no such guarantee, it is free to take a faster path and avoid the extra copies.
Edit: see Problem with cat() - #9 by nalimilan