# Optimize function with complex square root

**URL:** <https://discourse.julialang.org/t/optimize-function-with-complex-square-root/56058>\
**Category:** Performance\
**Created:** [February 26, 2021, 12:41am UTC](https://discourse.julialang.org/t/optimize-function-with-complex-square-root/56058 "2021-02-26T00:41:49Z")\
**Posts on this page:** 1\
**Showing post:** 11

<div class="post-metadata">

**Author:** ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Post date:** [February 27, 2021, 1:57pm UTC](https://discourse.julialang.org/t/optimize-function-with-complex-square-root/56058/11 "2021-02-27T13:57:12Z")

</div>

`eachindex` is more generic, `enumerate` does not give indexes, it gives `1` with the first element, `2` with the second, and so on; if your Array has more than one dimension, or custom indexes (start at 0 for example) then your code will break. `eachindex` will always give valid indexes, and for N-dimensional arrays, it will give the indexes in the most efficient order for linear access. If you want something that both give you valid indexes and the value then look at `pairs` documentation and use it instead of `enumerate`.

I talk a little more about this [in my answer of mine](https://discourse.julialang.org/t/any-shortcut-to-1-length-myvector/52816/27).

---

_[View the full topic](https://discourse.julialang.org/t/optimize-function-with-complex-square-root/56058)._
