# How to make Julia slow?

**URL:** https://discourse.julialang.org/t/how-to-make-julia-slow/28742
**Category:** Performance
**Tags:** question
**Created:** [September 13, 2019, 10:11pm UTC](https://discourse.julialang.org/t/how-to-make-julia-slow/28742 "2019-09-13T22:11:39Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![Carol](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/carol/32/8140_2.png) [@Carol](https://discourse.julialang.org/u/Carol)
#### Post date: [September 13, 2019, 10:11pm UTC](https://discourse.julialang.org/t/how-to-make-julia-slow/28742/1 "2019-09-13T22:11:39Z")

</div>

Hi,

I want to test the speed of dot product `dot()`(speeded up by Julia) V.S. dot product without any parallel. I want to see how fast does Julia speed up the dot product.

For non-parallel dot product, I write a for-loop:

```julia
function sdot(x,y)
    n = length(x)
    res = 0.0
    for i in 1:n
        res += x[i] * y[i]
    end
    return res
end

```

And I also checked that ‘@show Threads.nthreads()’ returned 1 to make sure Julia use only 1 thread.

But I’m not sure **whether Julia will still use any other parallel method** by default to speed up the for loop in my `sdot()`, because I know Julia is very smart.

My final question is: how I can avoid any kind of speeding up in Julia? Since I want to make the comparison fair.

Thanks,  
Carol

---

<div class="post-metadata">

### Author: ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)
#### Post date: [September 13, 2019, 10:32pm UTC](https://discourse.julialang.org/t/how-to-make-julia-slow/28742/2 "2019-09-13T22:32:32Z")

</div>

> [@Carol](#):
>
> Since I want to make the comparison fair.

What are you comparing with?

---

<div class="post-metadata">

### Author: ![Carol](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/carol/32/8140_2.png) [@Carol](https://discourse.julialang.org/u/Carol)
#### Post date: [September 13, 2019, 10:38pm UTC](https://discourse.julialang.org/t/how-to-make-julia-slow/28742/3 "2019-09-13T22:38:50Z")

</div>

`sdot()` and `LinearAlgebra.dot()`

---

<div class="post-metadata">

### Author: ![dilumaluthge](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dilumaluthge/32/29283_2.png) [@dilumaluthge](https://discourse.julialang.org/u/dilumaluthge)
#### Post date: [September 13, 2019, 11:18pm UTC](https://discourse.julialang.org/t/how-to-make-julia-slow/28742/4 "2019-09-13T23:18:31Z")

</div>

You could try starting Julia with `julia -O0` or `julia -O1`.

> -O, --optimize={0,1,2,3}  
> Set the optimization level (default level is 2 if unspecified or 3 if used without a level)

---

<div class="post-metadata">

### Author: ![dilumaluthge](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dilumaluthge/32/29283_2.png) [@dilumaluthge](https://discourse.julialang.org/u/dilumaluthge)
#### Post date: [September 13, 2019, 11:19pm UTC](https://discourse.julialang.org/t/how-to-make-julia-slow/28742/5 "2019-09-13T23:19:33Z")

</div>

Another way to make Julia slow is to start Julia with `julia --inline=no`.

> -inline={yes|no}  
> Control whether inlining is permitted, including overriding @inline declarations

---

<div class="post-metadata">

### Author: ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)
#### Post date: [September 14, 2019, 2:18am UTC](https://discourse.julialang.org/t/how-to-make-julia-slow/28742/6 "2019-09-14T02:18:37Z")

</div>

> [@Carol](#):
>
> But I’m not sure **whether Julia will still use any other parallel method** by default to speed up the for loop in my `sdot()` , because I know Julia is very smart.

Julia doesn’t do any automatic parallelization. You have to explicitly annotate loops that you want to parallelize.

---

<div class="post-metadata">

### Author: ![ffevotte](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ffevotte/32/6587_2.png) [@ffevotte](https://discourse.julialang.org/u/ffevotte)
#### Post date: [September 14, 2019, 9:09pm UTC](https://discourse.julialang.org/t/how-to-make-julia-slow/28742/7 "2019-09-14T21:09:37Z")

</div>

Maybe it’s useful to mention here that for arrays of floating-point numbers, `LinearAlgebra.dot` actually calls the underlying BLAS implementation (OpenBLAS by default, MKL if you recompiled Julia specifically).

In this specific instance, it would perhaps be more accurate to say that `dot` is sped up by C (and not Julia). Consequently, perhaps `dot` is not the best choice for your benchmark. Could you please tell us more about the kind of tests you’re performing, and the kind of conclusions you’d like to draw from them?

---

<div class="post-metadata">

### Author: ![johnh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/johnh/32/3615_2.png) [@johnh](https://discourse.julialang.org/u/johnh)
#### Post date: [September 15, 2019, 5:38am UTC](https://discourse.julialang.org/t/how-to-make-julia-slow/28742/8 "2019-09-15T05:38:56Z")

</div>

You can see what code is being generated by Julia using the @code\_llvm and @code\_native macros.

[https://pkg.julialang.org/docs/julia/THl1k/1.1.1/devdocs/reflection.html#Intermediate-and-compiled-representations-1](https://pkg.julialang.org/docs/julia/THl1k/1.1.1/devdocs/reflection.html#Intermediate-and-compiled-representations-1)

---

<div class="post-metadata">

### Author: ![Carol](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/carol/32/8140_2.png) [@Carol](https://discourse.julialang.org/u/Carol)
#### Post date: [September 16, 2019, 8:05am UTC](https://discourse.julialang.org/t/how-to-make-julia-slow/28742/9 "2019-09-16T08:05:24Z")

</div>

Hi, could you please tell me where I can know what’s the difference between those levels? I cannot find answer on google.

---

<div class="post-metadata">

### Author: ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)
#### Post date: [September 16, 2019, 4:32pm UTC](https://discourse.julialang.org/t/how-to-make-julia-slow/28742/10 "2019-09-16T16:32:51Z")

</div>

Julia -O0, -O1 are mostly too slow to be of use. -O2 is the default. -O3 does practically nothing over -O2.

---

<div class="post-metadata">

### Author: ![Carol](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/carol/32/8140_2.png) [@Carol](https://discourse.julialang.org/u/Carol)
#### Post date: [September 16, 2019, 6:53pm UTC](https://discourse.julialang.org/t/how-to-make-julia-slow/28742/12 "2019-09-16T18:53:07Z")

</div>

I already tested the speed under different optimization levels, and it’s consistent with your explanation. But I still want to know more details, because I have one question from my testing result:

Why different level will not affect BLAS(which is used in `dot()` ), but will affect for loop (which is used in `sdot` )?

Thanks you very much for your time

---

<div class="post-metadata">

### Author: ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)
#### Post date: [September 16, 2019, 6:55pm UTC](https://discourse.julialang.org/t/how-to-make-julia-slow/28742/13 "2019-09-16T18:55:09Z")

</div>

BLAS is an already compiled library that Julia calls into. `sdot` is compiled by Julia itself so the optimization level will matter there.
