# Multithreading in Agents.jl

**URL:** <https://discourse.julialang.org/t/multithreading-in-agents-jl/118452>\
**Category:** Modelling & Simulations\
**Tags:** agents, eventqueueabm\
**Created:** [August 21, 2024, 1:15pm UTC](https://discourse.julialang.org/t/multithreading-in-agents-jl/118452 "2024-08-21T13:15:01Z")\
**Posts on this page:** 1\
**Showing post:** 11

<div class="post-metadata">

**Author:** ![DanielVandH](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/danielvandh/32/31134_2.png) [@DanielVandH](https://discourse.julialang.org/u/DanielVandH)\
**Post date:** [August 22, 2024, 2:36pm UTC](https://discourse.julialang.org/t/multithreading-in-agents-jl/118452/11 "2024-08-22T14:36:29Z")

</div>

I agree with @nilshg that it’s impossible to really know what the issue is that you’re having, but note that

```julia
@time for i in 1:160000
         aa[i] .= [1, 1, 1, 1] 
       end

```

could be

```julia
@time for i in 1:160000
         aa[i] .= (1, 1, 1, 1)
       end

```

which will get rid of them.

```julia
julia> function ex1(aa)
       for i in 1:160000
       aa[i] .= [1, 1, 1, 1]
       end
       end
ex1 (generic function with 1 method)

julia> function ex2(aa)
       for i in 1:160000
       aa[i] .= (1, 1, 1, 1)
       end
       end
ex2 (generic function with 1 method)

julia> using BenchmarkTools

julia> @benchmark ex1($aa)
BenchmarkTools.Trial: 842 samples with 1 evaluation.
 Range (min … max): 3.575 ms … 161.583 ms ┊ GC (min … max): 0.00% … 93.63%
 Time (median): 5.540 ms ┊ GC (median): 0.00%
 Time (mean ± σ): 5.918 ms ± 5.723 ms ┊ GC (mean ± σ): 11.47% ± 12.36%

   █▃▁
  ▆███▆▄▃▃▃▃▂▃▂▃▃▃▄▃▄▅▄▅▅▄▅▄▄▄▄▅▅▄▃▃▃▂▂▂▂▂▃▂▁▂▂▂▂▂▂▂▁▁▂▁▁▁▁▂▂ ▃
  3.58 ms Histogram: frequency by time 12.1 ms <

 Memory estimate: 14.65 MiB, allocs estimate: 160000.

julia> @benchmark ex2($aa)
BenchmarkTools.Trial: 5279 samples with 1 evaluation.
 Range (min … max): 717.100 μs … 2.393 ms ┊ GC (min … max): 0.00% … 0.00%
 Time (median): 869.900 μs ┊ GC (median): 0.00%
 Time (mean ± σ): 937.408 μs ± 195.761 μs ┊ GC (mean ± σ): 0.00% ± 0.00%

     ▃▇█▄▁▂▂ ▁
  ▁▃▆█████████▇▆▅▅▅▄▃▃▃▃▄▃▃▃▃▃▂▂▃▂▂▂▂▂▂▂▂▂▂▂▂▁▁▂▂▁▁▁▂▁▁▁▁▁▁▁▁▁▁ ▃
  717 μs Histogram: frequency by time 1.63 ms <

 Memory estimate: 0 bytes, allocs estimate: 0.

```

---

_[View the full topic](https://discourse.julialang.org/t/multithreading-in-agents-jl/118452)._
