# Storing comparisons

**URL:** <https://discourse.julialang.org/t/storing-comparisons/110513>\
**Category:** Performance\
**Tags:** array, loops, cache\
**Created:** [February 21, 2024, 1:53pm UTC](https://discourse.julialang.org/t/storing-comparisons/110513 "2024-02-21T13:53:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Enlil50](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/enlil50/32/206539_2.png) [@Enlil50](https://discourse.julialang.org/u/Enlil50)\
**Post date:** [February 21, 2024, 1:53pm UTC](https://discourse.julialang.org/t/storing-comparisons/110513/1 "2024-02-21T13:53:10Z")

</div>

I have a program which computes a number, stores it and uses it for many times.  
Then it proceeds to the next iteration (it’s a loop), generates another number, stores it and uses it as well for many times.

Considering I have to store a lot of values, i will store them in an array called value\_holder

Is it the same thing, computationally, doing:

```julia
for i = 1:x
    value_holder[i] = function()
    stuff that uses: value_holder[i]
end

```

and:

```julia
for i = 1:x
    value_name = function()
    value_holder[i] = value_name
    stuff that uses: value_name
end

```

---

<div class="post-metadata">

**Author:** ![abraemer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/abraemer/32/51403_2.png) [@abraemer](https://discourse.julialang.org/u/abraemer)\
**Post date:** [February 21, 2024, 1:58pm UTC](https://discourse.julialang.org/t/storing-comparisons/110513/2 "2024-02-21T13:58:54Z")

</div>

No I think the former will likely read from memory every time you access `value_holder[i]`. That read likely is quite cheap as the value will be cached so it won’t make a huge difference.

There will be a big difference if you had multiple threads writing to `value_holder` even if they don’t directly overwrite results due to [“false sharing”](https://en.wikipedia.org/wiki/False_sharing#:~:text=In%20computer%20science%2C%20false%20sharing,managed%20by%20the%20caching%20mechanism).
