Le vendredi 13 mai 2016 à 14:54 -0700, Brandon Taylor a écrit : > I was wondering why the following code is so slow: > > @time broadcast( (x...) -> +(x...), [1:1000], [1001:2000] ) > > In comparison to > > @time broadcast(+, [1:1000], [1001:2000] ) > > and what would be a faster way to define an anonymous function with a > variable number of arguments? Note, I can't use zip because I can't > guarantee that the things being broadcast over are going to be the > same size. Splatting on a (strongly) variable number of arguments is generally not a good idea, as Julia needs to compile specific methods for each combination of arguments. But that's not the problem you're seeing here, since you only have two arguments.
Judging from your use of [1:1000] instead of collect(1:1000), I guess you're on Julia 0.4, where anonymous functions are slow. In 0.5, and when wrapping the code in a function, I don't see any clear difference. Regards
