# Code runtime constantly increasing with time

**URL:** <https://discourse.julialang.org/t/code-runtime-constantly-increasing-with-time/60437>\
**Category:** Performance\
**Tags:** question\
**Created:** [May 2, 2021, 9:49pm UTC](https://discourse.julialang.org/t/code-runtime-constantly-increasing-with-time/60437 "2021-05-02T21:49:24Z")\
**Posts on this page:** 1\
**Showing post:** 18

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [May 6, 2021, 5:00pm UTC](https://discourse.julialang.org/t/code-runtime-constantly-increasing-with-time/60437/18 "2021-05-06T17:00:56Z")

</div>

Another alternative to using `Setfield` is to use one-element vectors, for example:

```julia
julia> struct A
         x::Vector{Int}
       end

julia> function upA(a,n)
         for i in 1:n
           a.x[1] += 1
         end
         return a
       end
upA (generic function with 1 method)

julia> @btime upA(a,100_000) setup=(a=A([0])) evals=1
  24.000 ns (0 allocations: 0 bytes)
A([100000])

```

That could be used for your mutable scalars inside your immutable struct as well. It is a little bit ugly to have to intialize and mutate scalars as if they are arrays, but I in general feel safer with that. I have even recently discussed all the alternatives on how to do that, [here](https://discourse.julialang.org/t/mutable-scalar-in-immutable-object-the-best-alternative/57401).

---

_[View the full topic](https://discourse.julialang.org/t/code-runtime-constantly-increasing-with-time/60437)._
