# Why with @threads, the execution time is worse?

**URL:** https://discourse.julialang.org/t/why-with-threads-the-execution-time-is-worse/68160
**Category:** Performance
**Tags:** question, multithreading
**Created:** [September 14, 2021, 5:56pm UTC](https://discourse.julialang.org/t/why-with-threads-the-execution-time-is-worse/68160 "2021-09-14T17:56:59Z")
**Posts on this page:** 1
**Showing post:** 20

<div class="post-metadata">

### Author: ![Amro](https://avatars.discourse-cdn.com/v4/letter/a/4491bb/32.png) [@Amro](https://discourse.julialang.org/u/Amro)
#### Post date: [September 16, 2021, 9:44pm UTC](https://discourse.julialang.org/t/why-with-threads-the-execution-time-is-worse/68160/20 "2021-09-16T21:44:37Z")

</div>

Thank you @stillyslalom for your explanation. I have compared between the `@batch` and the method here:[https://discourse.julialang.org/t/optional-macro-invocation/18588/21](https://discourse.julialang.org/t/optional-macro-invocation/18588/21)

```julia
function ss()
dt = 0.001;     
tmin = 0;  
tmax = 5;
timeSim = tmin:dt:tmax;
A_Mat = spzeros(9,9); 
for i in 1:9
  A_Mat[i,i] = 1;
end
I_Mat = ones(9,3);
  iter = 0;
  for t in timeSim
      iter += 1;
      n=101
      #@threadsif n>100 for i in 1:n #by using it the time is 182 ms
      @batch minbatch=15 for i in 1:n #by using it the time is 879.872 ms
      V_Mat = A_Mat \ I_Mat;
    end
end
end
using SparseArrays;
using LinearAlgebra;
using .Threads
using Polyester
using BenchmarkTools
@btime ss()

```

Any reason why `@batch` results in a really big number comparing with conditional thread `@threadsif ` ?

---

_[View the full topic](https://discourse.julialang.org/t/why-with-threads-the-execution-time-is-worse/68160)._
