# Loops vs Vectorization? When to use?

**URL:** <https://discourse.julialang.org/t/loops-vs-vectorization-when-to-use/94724>\
**Category:** New to Julia\
**Tags:** performance\
**Created:** [February 16, 2023, 2:10pm UTC](https://discourse.julialang.org/t/loops-vs-vectorization-when-to-use/94724 "2023-02-16T14:10:43Z")\
**Posts on this page:** 1\
**Showing post:** 19

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [February 17, 2023, 9:29pm UTC](https://discourse.julialang.org/t/loops-vs-vectorization-when-to-use/94724/19 "2023-02-17T21:29:27Z")

</div>

@Eben60, see @bkamins multiple posts and courses on this matter, including [here](https://github.com/bkamins/Julia-DataFrames-Tutorial/blob/master/11_performance.ipynb), and his [latest book](https://discourse.julialang.org/t/julia-for-data-analysis-book/78090/11) that covers this issue nicely.

Basically, the columns of a DataFrame are AbstractVectors (for maximal user flexibility) and the compiler does not know the actual memory layout. However, inside the function barrier, everything becomes type stable for the compiler and faster code can be generated.

---

_[View the full topic](https://discourse.julialang.org/t/loops-vs-vectorization-when-to-use/94724)._
