# \`map\` vs \`broadcast\`: should one prefer \`map\` if these are equivalent?

**URL:** <https://discourse.julialang.org/t/map-vs-broadcast-should-one-prefer-map-if-these-are-equivalent/86118>\
**Category:** Performance\
**Tags:** package, broadcast, map\
**Created:** [August 22, 2022, 5:12am UTC](https://discourse.julialang.org/t/map-vs-broadcast-should-one-prefer-map-if-these-are-equivalent/86118 "2022-08-22T05:12:29Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![nsajko](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nsajko/32/221187_2.png) [@nsajko](https://discourse.julialang.org/u/nsajko)\
**Post date:** [August 22, 2022, 6:12pm UTC](https://discourse.julialang.org/t/map-vs-broadcast-should-one-prefer-map-if-these-are-equivalent/86118/2 "2022-08-22T18:12:20Z")

</div>

Earlier thread on same topic:

> [@When to use broadcasting with . vs map](https://discourse.julialang.org/t/when-to-use-brodcasting-with-vs-map/58078):
>
> If I want to apply a function across say a Vector in julia, there are two ways I could do it: map(f, seq) f.(seq) Is any way “better” than the other? In fact, is there any difference in the implementation between using map and broadcasting with . ?

> I wonder if this is an intrinsic limitation because broadcast is a more complicated operation, in which case developers should be encouraged to prefer map if that’s an option?

That’s the way I understand it, at least.

The Julia Manual actually even says that `.` isn’t required for performance, but that it’s convenient:  
[https://docs.julialang.org/en/v1/manual/functions/#man-vectorized](https://docs.julialang.org/en/v1/manual/functions/#man-vectorized)

> In Julia, vectorized functions are _not_ required for performance, and indeed it is often beneficial to write your own loops (see Performance Tips), but they can still be convenient.

Also to note: there are subtle performance considerations to keep in mind when using broadcasting:  
[https://docs.julialang.org/en/v1/manual/performance-tips/#More-dots:-Fuse-vectorized-operations](https://docs.julialang.org/en/v1/manual/performance-tips/#More-dots:-Fuse-vectorized-operations)

---

_[View the full topic](https://discourse.julialang.org/t/map-vs-broadcast-should-one-prefer-map-if-these-are-equivalent/86118)._
