# Vector addition in Julia slower than numpy in Linux

**URL:** <https://discourse.julialang.org/t/vector-addition-in-julia-slower-than-numpy-in-linux/38520>\
**Category:** Performance\
**Created:** [May 1, 2020, 2:07am UTC](https://discourse.julialang.org/t/vector-addition-in-julia-slower-than-numpy-in-linux/38520 "2020-05-01T02:07:39Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![aminsadeghi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aminsadeghi/32/22853_2.png) [@aminsadeghi](https://discourse.julialang.org/u/aminsadeghi)\
**Post date:** [May 1, 2020, 2:07am UTC](https://discourse.julialang.org/t/vector-addition-in-julia-slower-than-numpy-in-linux/38520/1 "2020-05-01T02:07:40Z")

</div>

I tried this on `Julia 1.4` on Ubuntu 19.10:

```python
import numpy as np
a = np.random.rand(500_000)
b = np.random.rand(500_000)
%timeit a + b
115 µs ± 1.03 µs per loop (mean ± std. dev. of 7 runs, 10000 loops each)

```

```julia
using BenchmarkTools
a = rand(500_000)
b = rand(500_000)
@btime a .+ b;
545.357 μs (2 allocations: 3.81 MiB)

```

Strangely, I tried it on a Macbook and `Julia` was actually faster than `numpy`, maybe by 20% or something.

---

<div class="post-metadata">

**Author:** ![jlapeyre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jlapeyre/32/4514_2.png) [@jlapeyre](https://discourse.julialang.org/u/jlapeyre)\
**Post date:** [May 1, 2020, 2:33am UTC](https://discourse.julialang.org/t/vector-addition-in-julia-slower-than-numpy-in-linux/38520/2 "2020-05-01T02:33:33Z")

</div>

This

```julia
a = np.random.rand(500_000)

```

errors with

```julia
    a = np.random.rand(500_000)
                             ^
SyntaxError: invalid syntax

```

---

<div class="post-metadata">

**Author:** ![aminsadeghi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aminsadeghi/32/22853_2.png) [@aminsadeghi](https://discourse.julialang.org/u/aminsadeghi)\
**Post date:** [May 1, 2020, 2:53am UTC](https://discourse.julialang.org/t/vector-addition-in-julia-slower-than-numpy-in-linux/38520/3 "2020-05-01T02:53:54Z")

</div>

Maybe it’s because of this line

```julia
%timeit a + b

```

You need to run this in IPython console, `%timeit` command won’t work otherwise.

---

<div class="post-metadata">

**Author:** ![stillyslalom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stillyslalom/32/45687_2.png) [@stillyslalom](https://discourse.julialang.org/u/stillyslalom)\
**Post date:** [May 1, 2020, 3:08am UTC](https://discourse.julialang.org/t/vector-addition-in-julia-slower-than-numpy-in-linux/38520/4 "2020-05-01T03:08:17Z")

</div>

I’m seeing similar times on my machine:

```julia
>>> timeit.timeit('a + b', setup='import numpy as np; a=np.random.rand(500_000); b = np.copy(a)', number=1000)/1000
0.0004245378542691469

```

```julia
julia> @btime $a .+ $b
  436.089 μs (2 allocations: 781.33 KiB)

```

If you want to pull out the big guns,

```julia
julia> using LoopVectorization

julia> @btime vmapnt!(+, $c, $a, $b)
  80.321 μs (0 allocations: 0 bytes)

```

edit: machine info

```julia
julia> versioninfo()
Julia Version 1.2.0
Commit c6da87ff4b (2019-08-20 00:03 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Xeon(R) CPU E5-2695 v4 @ 2.10GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-6.0.1 (ORCJIT, broadwell)

```

---

<div class="post-metadata">

**Author:** ![zhangliye](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zhangliye/32/3208_2.png) [@zhangliye](https://discourse.julialang.org/u/zhangliye)\
**Post date:** [May 1, 2020, 3:08am UTC](https://discourse.julialang.org/t/vector-addition-in-julia-slower-than-numpy-in-linux/38520/5 "2020-05-01T03:08:28Z")

</div>

The followings are the results on my machine. Python is slightly faster.

```julia
import numpy as np
a = np.random.rand(500_000)
b = np.random.rand(500_000)
%timeit a + b
368 µs ± 4.3 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)

```

```julia
using BenchmarkTools
a = rand(500_000)
b = rand(500_000)
@btime a .+ b;
495.616 μs (4 allocations: 3.81 MiB)

```

The OS information,

```julia
Julia Version 1.4.1
Commit 381693d3df* (2020-04-14 17:20 UTC)
Platform Info:
  OS: macOS (x86_64-apple-darwin18.7.0)
  CPU: Intel(R) Core(TM) i5-8500 CPU @ 3.00GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-8.0.1 (ORCJIT, skylake)

```

---

<div class="post-metadata">

**Author:** ![jlapeyre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jlapeyre/32/4514_2.png) [@jlapeyre](https://discourse.julialang.org/u/jlapeyre)\
**Post date:** [May 1, 2020, 4:42am UTC](https://discourse.julialang.org/t/vector-addition-in-julia-slower-than-numpy-in-linux/38520/6 "2020-05-01T04:42:13Z")

</div>

> [@jlapeyre](#):
>
> SyntaxError: invalid syntax

That was with python 2 and possibly an older version of numpy. In any case, underscores in integer literals work in python 3 for me; and the error was a red herring.

---

<div class="post-metadata">

**Author:** ![aminsadeghi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aminsadeghi/32/22853_2.png) [@aminsadeghi](https://discourse.julialang.org/u/aminsadeghi)\
**Post date:** [May 1, 2020, 5:22am UTC](https://discourse.julialang.org/t/vector-addition-in-julia-slower-than-numpy-in-linux/38520/7 "2020-05-01T05:22:27Z")

</div>

Our `Julia` run times are more or less close, but my `numpy` timing’s ~4X faster than yours. So maybe it’s something new in `numpy`? What’s your `numpy` version? Mine’s 1.17.2

---

<div class="post-metadata">

**Author:** ![aminsadeghi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aminsadeghi/32/22853_2.png) [@aminsadeghi](https://discourse.julialang.org/u/aminsadeghi)\
**Post date:** [May 1, 2020, 5:25am UTC](https://discourse.julialang.org/t/vector-addition-in-julia-slower-than-numpy-in-linux/38520/8 "2020-05-01T05:25:21Z")

</div>

Same comment as @stillyslalom, our `Julia` timing matches, but not `numpy`’s. What’s your `numpy` version. Given that based on @stillyslalom’s values using `LoopVectorization`, I’m guessing that maybe that’s what they do in `numpy`?

---

<div class="post-metadata">

**Author:** ![stillyslalom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stillyslalom/32/45687_2.png) [@stillyslalom](https://discourse.julialang.org/u/stillyslalom)\
**Post date:** [May 1, 2020, 5:32am UTC](https://discourse.julialang.org/t/vector-addition-in-julia-slower-than-numpy-in-linux/38520/9 "2020-05-01T05:32:57Z")

</div>

With the most recent version of Numpy, I get the same timings:

```julia
>>> np. __version__'1.18.3'
>>> timeit.timeit('a + b', setup='import numpy as np; a=np.random.rand(500_000); b = np.copy(a)', number=1000)/1000
0.00043422764912247656

```

---

<div class="post-metadata">

**Author:** ![zhangliye](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zhangliye/32/3208_2.png) [@zhangliye](https://discourse.julialang.org/u/zhangliye)\
**Post date:** [May 1, 2020, 5:36am UTC](https://discourse.julialang.org/t/vector-addition-in-julia-slower-than-numpy-in-linux/38520/10 "2020-05-01T05:36:01Z")

</div>

numpy version: 1.17.4  
python version: 3.7.6

OS: macOS (x86\_64-apple-darwin18.7.0)  
CPU: Intel(R) Core™ i5-8500 CPU @ 3.00GHz  
WORD\_SIZE: 64

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [May 1, 2020, 5:36am UTC](https://discourse.julialang.org/t/vector-addition-in-julia-slower-than-numpy-in-linux/38520/11 "2020-05-01T05:36:52Z")

</div>

Is `numpy` using multithreading?

---

<div class="post-metadata">

**Author:** ![Elrod](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/elrod/32/22461_2.png) [@Elrod](https://discourse.julialang.org/u/Elrod)\
**Post date:** [May 1, 2020, 7:12am UTC](https://discourse.julialang.org/t/vector-addition-in-julia-slower-than-numpy-in-linux/38520/12 "2020-05-01T07:12:31Z")

</div>

That is an impressive speedup!

I’m not seeing the magnitude, and not before a much larger size.  
First, to get it out of the way

```python
>>> timeit.timeit('a + b', setup='import numpy as np; a=np.random.rand(500_000); b = np.copy(a)', number=1000)/1000
0.000551134126028046
>>> timeit.timeit('a + b', setup='import numpy as np; a=np.random.rand(500_000); b = np.copy(a)', number=1000)/1000
0.000551150968996808

```

I actually happen to see worse performance at this size for `vmapnt!`, but performance is pretty similar to Python:

```julia
julia> using LoopVectorization, BenchmarkTools

julia> a = rand(500_000); b = rand(length(a));

julia> c1 = similar(a); c2 = similar(a);

julia> @btime $a .+ $b;
  563.405 μs (2 allocations: 3.81 MiB)

julia> @btime vmapnt!(+, $c1, $a, $b);
  522.161 μs (0 allocations: 0 bytes)

julia> @btime $c2 .= $a .+ $b;
  511.718 μs (0 allocations: 0 bytes)

julia> c1 == c2
true

```

But if I make the arrays 10x smaller, I do see an improvement:

```julia
julia> a = rand(50_000); b = rand(length(a));

julia> c1 = similar(a); c2 = similar(a);

julia> @btime vmapnt!(+, $c1, $a, $b);
  27.126 μs (0 allocations: 0 bytes)

julia> @btime $c2 .= $a .+ $b;
  31.831 μs (0 allocations: 0 bytes)

julia> c1 == c2
true

```

Of course, performance improves by more than 10x because we’re far into the realm of memory-bottlenecks. But that also means that the nontemporal stores weren’t helping for vectors of length 500\_000.  
On my computer, the L3 cache can fit over 3,200,000 doubles.

```julia
julia> L = LoopVectorization.VectorizationBase.CACHE_SIZE[3] ÷ sizeof(Float64)
3244032

julia> versioninfo()
Julia Version 1.5.0-DEV.696
Commit e09b3d6d1a* (2020-04-26 16:15 UTC)
Platform Info:
  OS: Linux (x86_64-generic-linux)
  CPU: Intel(R) Core(TM) i9-10980XE CPU @ 3.00GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-10.0.0 (ORCJIT, skylake)

```

So it can comfortably hold all three arrays.  
So, lets see what happens if two arrays just fit in the L3 cache.

```julia
julia> L = LoopVectorization.VectorizationBase.CACHE_SIZE[3] ÷ (2sizeof(Float64))
1622016

julia> a = rand(L); b = rand(length(a));

julia> c1 = similar(a); c2 = similar(a);

julia> @btime vmapnt!(+, $c1, $a, $b);
  1.616 ms (0 allocations: 0 bytes)

julia> @btime $c2 .= $a .+ $b;
  1.706 ms (0 allocations: 0 bytes)

julia> c1 == c2
true

```

Small difference. Make the arrays 50% longer:

```julia
julia> a = rand(3L >>> 1); b = rand(length(a));

julia> c1 = similar(a); c2 = similar(a);

julia> @btime vmapnt!(+, $c1, $a, $b);
  2.668 ms (0 allocations: 0 bytes)

julia> @btime $c2 .= $a .+ $b;
  3.060 ms (0 allocations: 0 bytes)

julia> c1 == c2
true

```

Letting 1 array fill the cache:

```julia
julia> a = rand(2L); b = rand(length(a));

julia> c1 = similar(a); c2 = similar(a);

julia> @btime vmapnt!(+, $c1, $a, $b);
  3.411 ms (0 allocations: 0 bytes)

julia> @btime $c2 .= $a .+ $b;
  4.135 ms (0 allocations: 0 bytes)

julia> c1 == c2
true

```

Only half an array fits in the L3:

```julia
julia> a = rand(4L); b = rand(length(a));

julia> c1 = similar(a); c2 = similar(a);

julia> @btime vmapnt!(+, $c1, $a, $b);
  7.380 ms (0 allocations: 0 bytes)

julia> @btime $c2 .= $a .+ $b;
  9.140 ms (0 allocations: 0 bytes)

julia> c1 == c2
true

```

> **Dumps for L1 and L2 cache**
>
> For the L1 cache:
> 
> ```julia
> julia> a = rand(L); b = rand(length(a));
> 
> julia> c1 = similar(a); c2 = similar(a);
> 
> julia> @btime vmapnt!(+, $c1, $a, $b);
> 827.247 ns (0 allocations: 0 bytes)
> 
> julia> @btime $c2 .= $a .+ $b;
> 393.866 ns (0 allocations: 0 bytes)
> 
> julia> c1 == c2
> true
> 
> julia> a = rand(2L); b = rand(length(a));
> 
> julia> c1 = similar(a); c2 = similar(a);
> 
> julia> @btime vmapnt!(+, $c1, $a, $b);
> 1.864 μs (0 allocations: 0 bytes)
> 
> julia> @btime $c2 .= $a .+ $b;
> 720.099 ns (0 allocations: 0 bytes)
> 
> julia> c1 == c2
> true
> 
> julia> a = rand(4L); b = rand(length(a));
> 
> julia> c1 = similar(a); c2 = similar(a);
> 
> julia> @btime vmapnt!(+, $c1, $a, $b);
> 3.767 μs (0 allocations: 0 bytes)
> 
> julia> @btime $c2 .= $a .+ $b;
> 1.391 μs (0 allocations: 0 bytes)
> 
> julia> c1 == c2
> true
> 
> ```
> 
> and the L2:
> 
> ```julia
> julia> L = LoopVectorization.VectorizationBase.CACHE_SIZE[2] ÷ (2sizeof(Float64))
> 65536
> 
> julia> a = rand(L >>> 1); b = rand(length(a));
> 
> julia> c1 = similar(a); c2 = similar(a);
> 
> julia> @btime vmapnt!(+, $c1, $a, $b);
> 15.050 μs (0 allocations: 0 bytes)
> 
> julia> @btime $c2 .= $a .+ $b;
> 6.783 μs (0 allocations: 0 bytes)
> 
> julia> a = rand(3L >>> 2); b = rand(length(a));
> 
> julia> c1 = similar(a); c2 = similar(a);
> 
> julia> @btime vmapnt!(+, $c1, $a, $b);
> 27.858 μs (0 allocations: 0 bytes)
> 
> julia> @btime $c2 .= $a .+ $b;
> 25.433 μs (0 allocations: 0 bytes)
> 
> julia> a = rand(L); b = rand(length(a));
> 
> julia> c1 = similar(a); c2 = similar(a);
> 
> julia> @btime vmapnt!(+, $c1, $a, $b);
> 43.216 μs (0 allocations: 0 bytes)
> 
> julia> @btime $c2 .= $a .+ $b;
> 59.119 μs (0 allocations: 0 bytes)
> 
> julia> c1 == c2
> true
> 
> julia> a = rand(2L); b = rand(length(a));
> 
> julia> c1 = similar(a); c2 = similar(a);
> 
> julia> @btime vmapnt!(+, $c1, $a, $b);
> 137.887 μs (0 allocations: 0 bytes)
> 
> julia> @btime $c2 .= $a .+ $b;
> 131.966 μs (0 allocations: 0 bytes)
> 
> julia> c1 == c2
> true
> 
> julia> a = rand(4L); b = rand(length(a));
> 
> julia> c1 = similar(a); c2 = similar(a);
> 
> julia> @btime vmapnt!(+, $c1, $a, $b);
> 277.129 μs (0 allocations: 0 bytes)
> 
> julia> @btime $c2 .= $a .+ $b;
> 267.334 μs (0 allocations: 0 bytes)
> 
> julia> c1 == c2
> true
> 
> ```

On my computer, when streaming single threaded additions, the nontemporal stores seem to lead to beter performance when either:

- `a` and `b` are much larger than the L3 cache
- `a` and `b` just barely fit in the L2 cache.

And equal or worse performance otherwise. I never get anything close to your 5x gain.

I need to use multithreading to just barely beat your time

```julia
julia> using LoopVectorization, BenchmarkTools

julia> a = rand(500_000); b = rand(length(a));

julia> c1 = similar(a); c2 = similar(a);

julia> @btime vmapntt!(+, $c1, $a, $b);
  64.925 μs (93 allocations: 12.89 KiB)

```

---

<div class="post-metadata">

**Author:** ![jbrea](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jbrea/32/3879_2.png) [@jbrea](https://discourse.julialang.org/u/jbrea)\
**Post date:** [May 1, 2020, 8:03am UTC](https://discourse.julialang.org/t/vector-addition-in-julia-slower-than-numpy-in-linux/38520/13 "2020-05-01T08:03:16Z")

</div>

On my (slow) machine julia is faster:

```python
Python 3.8.2 (default, Apr 8 2020, 14:31:25) 
Type 'copyright', 'credits' or 'license' for more information
IPython 7.13.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import numpy as np 
   ...: a = np.random.rand(500_000) 
   ...: b = np.random.rand(500_000) 
   ...: %timeit a + b                                                                          
1.29 ms ± 5.09 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)

In [2]: np. __version__                                                                         
Out[2]: '1.18.3'

```

```julia
julia> using BenchmarkTools

julia> a = rand(500_000);

julia> b = rand(500_000);

julia> @btime a .+ b;
  1.195 ms (4 allocations: 3.81 MiB)

julia> @btime $a .+ $b;
  1.176 ms (2 allocations: 3.81 MiB)

julia> versioninfo()
Julia Version 1.4.1
Commit 381693d3df* (2020-04-14 17:20 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Core(TM) i7-5600U CPU @ 2.60GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-8.0.1 (ORCJIT, broadwell)

```

Edit: Don’t know if it is fairer to compare with or without interpolation…

---

<div class="post-metadata">

**Author:** ![juthohaegeman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juthohaegeman/32/8620_2.png) [@juthohaegeman](https://discourse.julialang.org/u/juthohaegeman)\
**Post date:** [May 1, 2020, 8:07am UTC](https://discourse.julialang.org/t/vector-addition-in-julia-slower-than-numpy-in-linux/38520/14 "2020-05-01T08:07:28Z")

</div>

I think Python uses multithreading. On my system

```julia
In [3]: >>> timeit.timeit('a + b', setup='import numpy as np; a=np.random.rand(500_000); b = np.copy(a)', numb
   ...: er=1000)/1000 
   ...:                                                                                                       
Out[3]: 0.0003835020289999989

In [4]: >>> timeit.timeit('a + b', setup='import numpy as np; a=np.random.rand(500_000); b = np.copy(a)', numb
   ...: er=1000)/1000 
   ...:                                                                                                       
Out[4]: 0.0003862037549999968

In [5]: >>> timeit.timeit('a + b', setup='import numpy as np; a=np.random.rand(500_000); b = np.copy(a)', numb
   ...: er=100000)/100000                                                                                     
Out[5]: 0.0003821436223

```

In the last run I used a huge number of repetitions to clearly see the CPU usage of Python using about 3 cores (on my quad core macbook pro, but with many other things running at the same time).

Using `export JULIA_NUM_THREADS=4` and `using Strided`

```julia
julia> a = rand(500_000); b = rand(length(a));

julia> c1 = similar(a); c2 = similar(a);

julia> @btime $a .+ $b;
  470.189 μs (2 allocations: 3.81 MiB)

julia> @btime @strided $a .+ $b;
  417.899 μs (38 allocations: 3.82 MiB)

julia> @btime $c1 .= $a .+ $b;
  451.231 μs (0 allocations: 0 bytes)

julia> @btime @strided $c2 .= $a .+ $b;
  319.303 μs (34 allocations: 3.38 KiB)

```

Not sure why there is such a big difference between the allocating and non-allocating version. But certainly the threading strategy is overly complicated (and thus creating too much overhead) for such a simple problem.

```julia
julia> versioninfo()
Julia Version 1.4.0
Commit b8e9a9ecc6 (2020-03-21 16:36 UTC)
Platform Info:
  OS: macOS (x86_64-apple-darwin18.6.0)
  CPU: Intel(R) Core(TM) i7-6920HQ CPU @ 2.90GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-8.0.1 (ORCJIT, skylake)
Environment:
  JULIA_NUM_THREADS = 4

```

---

<div class="post-metadata">

**Author:** ![Azamat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/azamat/32/6892_2.png) [@Azamat](https://discourse.julialang.org/u/Azamat)\
**Post date:** [May 1, 2020, 9:07am UTC](https://discourse.julialang.org/t/vector-addition-in-julia-slower-than-numpy-in-linux/38520/15 "2020-05-01T09:07:35Z")

</div>

Possibly of relevance: [sum(a) is now 30% slower than NumPy · Issue #30290 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/issues/30290)

---

<div class="post-metadata">

**Author:** ![aminsadeghi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aminsadeghi/32/22853_2.png) [@aminsadeghi](https://discourse.julialang.org/u/aminsadeghi)\
**Post date:** [May 1, 2020, 1:33pm UTC](https://discourse.julialang.org/t/vector-addition-in-julia-slower-than-numpy-in-linux/38520/16 "2020-05-01T13:33:01Z")

</div>

I guess that’s the case. But even so, I started Julia with 4 threads, set number of `BLAS` threads to 4, and still `numpy` beats `Julia` by 4X.

---

<div class="post-metadata">

**Author:** ![CameronBieganek](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cameronbieganek/32/6915_2.png) [@CameronBieganek](https://discourse.julialang.org/u/CameronBieganek)\
**Post date:** [May 1, 2020, 2:43pm UTC](https://discourse.julialang.org/t/vector-addition-in-julia-slower-than-numpy-in-linux/38520/17 "2020-05-01T14:43:46Z")

</div>

> [@aminsadeghi](#):
>
> I started Julia with 4 threads, set number of `BLAS` threads to 4, and still `numpy` beats `Julia` by 4X.

I think in Julia `a .+ b` is inherently single threaded, even if you start Julia with 4 threads.

---

<div class="post-metadata">

**Author:** ![stillyslalom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stillyslalom/32/45687_2.png) [@stillyslalom](https://discourse.julialang.org/u/stillyslalom)\
**Post date:** [May 1, 2020, 2:58pm UTC](https://discourse.julialang.org/t/vector-addition-in-julia-slower-than-numpy-in-linux/38520/18 "2020-05-01T14:58:53Z")

</div>

The extreme speedup I saw was (sadly) due to user error: I accidentally used arrays of length 100,000 rather than 500,000 for my `vmapnt!` run. Don’t try to benchmark past midnight, folks!

```julia
julia> @btime @. $c1 = $a + $b;
  407.343 μs (0 allocations: 0 bytes)

julia> @btime vmapnt!(+, $c1, $a, $b);
  407.012 μs (0 allocations: 0 bytes)

```

---

<div class="post-metadata">

**Author:** ![aminsadeghi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aminsadeghi/32/22853_2.png) [@aminsadeghi](https://discourse.julialang.org/u/aminsadeghi)\
**Post date:** [May 1, 2020, 3:09pm UTC](https://discourse.julialang.org/t/vector-addition-in-julia-slower-than-numpy-in-linux/38520/19 "2020-05-01T15:09:13Z")

</div>

I see. But, strangely, `Julia` matched `numpy` in my Macbook, I only see the 4X mismatch on `Ubuntu 19.10`.

---

<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:** [May 1, 2020, 3:12pm UTC](https://discourse.julialang.org/t/vector-addition-in-julia-slower-than-numpy-in-linux/38520/20 "2020-05-01T15:12:27Z")

</div>

Something odd going on with Ubuntu maybe. On MacOS it’s pretty close:

```julia
In [11]: %timeit a + b                                                          
500 µs ± 4.45 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)

julia> @btime $a .+ $b;
  500.413 μs (2 allocations: 3.81 MiB)

```

Numpy 1.18.1  
Julia 1.4.0

[Next page](https://discourse.julialang.org/t/vector-addition-in-julia-slower-than-numpy-in-linux/38520.md?page=2)
