# Performance of Comprehensions versus For Loops

**URL:** https://discourse.julialang.org/t/performance-of-comprehensions-versus-for-loops/30066
**Category:** New to Julia
**Created:** [October 18, 2019, 10:03pm UTC](https://discourse.julialang.org/t/performance-of-comprehensions-versus-for-loops/30066 "2019-10-18T22:03:20Z")
**Posts on this page:** 1
**Showing post:** 6

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [October 20, 2019, 5:08am UTC](https://discourse.julialang.org/t/performance-of-comprehensions-versus-for-loops/30066/6 "2019-10-20T05:08:54Z")

</div>

I am aware of it, but many extra ingredients are needed to replicate what eg `map` or `collect` does. Eg recursively calling on widening:

> [@Functional implementation of collect](https://discourse.julialang.org/t/functional-implementation-of-collect/15177):
>
> I am working on something that is in a sense a generalization of collect (except it would pick named tuples apart into vectors, apply some simple RLE compression, etc), and I wanted to understand the type widening part better. For my problem, I do not know the element type or the size ex ante, so the following type is defined to make results comparable (all the code is available in a [gist](https://gist.github.com/tpapp/f0cfb7fceaee5823c1afc0a1f4019ca9) for quick copy&paste): # define an iterator with unknown type and length struct MyItr N::Int end Base.Itera…

using size hints for preallocating, etc. It is all feasible (since it is done in `Base` 😉), but you essentially end up reimplementing `Base` functionality, which is very involved.

---

_[View the full topic](https://discourse.julialang.org/t/performance-of-comprehensions-versus-for-loops/30066)._
