# Loosing performance with \`Threads.@threads\` for loop

**URL:** <https://discourse.julialang.org/t/loosing-performance-with-threads-threads-for-loop/69358>\
**Category:** Performance\
**Tags:** parallel, multithreading, threads\
**Created:** [October 7, 2021, 10:17am UTC](https://discourse.julialang.org/t/loosing-performance-with-threads-threads-for-loop/69358 "2021-10-07T10:17:03Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![Kevin\_Kleinbeck](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kevin_kleinbeck/32/21278_2.png) [@Kevin\_Kleinbeck](https://discourse.julialang.org/u/Kevin_Kleinbeck)\
**Post date:** [October 7, 2021, 12:41pm UTC](https://discourse.julialang.org/t/loosing-performance-with-threads-threads-for-loop/69358/6 "2021-10-07T12:41:58Z")

</div>

Thanks for the tests! I fear something must be severely wrong wither with the server or my julia environment:

```julia
julia> test1(1)
3.523 s (20467 allocations: 571.43 MiB)

```

```julia
julia> test1(2)
12.826 s (10615 allocations: 566.19 MiB)

```

```julia
julia> test1(5)
19.033 s (4687 allocations: 553.89 MiB)

```

```julia
julia> test1(10)
11.294 s (2490 allocations: 534.52 MiB)

```

```julia
julia> test1(40)
9.206 s (889 allocations: 496.15 MiB)

```

```julia
julia> test2()
694.097 ms (502 allocations: 572.43 MiB)

```

Global scope cannot be the problem: I used @goerch 's examples for this and in my production code, where I observed these problems, everything is also nicely packed into functions.

---

_[View the full topic](https://discourse.julialang.org/t/loosing-performance-with-threads-threads-for-loop/69358)._
