# Vector{Float} times Vector{Complex} slower than Vector{Complex} times Vector{Complex}

**URL:** <https://discourse.julialang.org/t/vector-float-times-vector-complex-slower-than-vector-complex-times-vector-complex/26857>\
**Category:** Performance\
**Tags:** question, linearalgebra\
**Created:** [July 26, 2019, 4:57pm UTC](https://discourse.julialang.org/t/vector-float-times-vector-complex-slower-than-vector-complex-times-vector-complex/26857 "2019-07-26T16:57:00Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [July 26, 2019, 4:57pm UTC](https://discourse.julialang.org/t/vector-float-times-vector-complex-slower-than-vector-complex-times-vector-complex/26857/1 "2019-07-26T16:57:00Z")

</div>

If you define  
`Q = collect(-10:.01:10) v = Q.-transpose(Q) cv = complex.(v) comp = exp.(-im.*Q)`  
then multiplying cv_comp takes 2.94ms on my computer compared with 3.41ms for v_comp (times measured with btime) Any idea why this is?

---

<div class="post-metadata">

**Author:** ![robsmith11](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/robsmith11/32/29641_2.png) [@robsmith11](https://discourse.julialang.org/u/robsmith11)\
**Post date:** [July 26, 2019, 5:02pm UTC](https://discourse.julialang.org/t/vector-float-times-vector-complex-slower-than-vector-complex-times-vector-complex/26857/2 "2019-07-26T17:02:58Z")

</div>

The former has the extra step of converting `Float`s to `Complex`s.

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [July 26, 2019, 5:15pm UTC](https://discourse.julialang.org/t/vector-float-times-vector-complex-slower-than-vector-complex-times-vector-complex/26857/3 "2019-07-26T17:15:01Z")

</div>

That would make sense if it was also slower for single element multiplication, but it’s not. Also it ideally would be possible to perform the multiplication without conversion since multiplying real by complex is easy

---

<div class="post-metadata">

**Author:** ![carstenbauer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/carstenbauer/32/4981_2.png) [@carstenbauer](https://discourse.julialang.org/u/carstenbauer)\
**Post date:** [July 26, 2019, 5:15pm UTC](https://discourse.julialang.org/t/vector-float-times-vector-complex-slower-than-vector-complex-times-vector-complex/26857/4 "2019-07-26T17:15:50Z")

</div>

First of all, running your code, I get

```julia
Q = collect(-10:.01:10)
v = Q.-transpose(Q)
cv = complex.(v)
comp = exp.(-im.*Q)

using BenchmarkTools
@btime $cv * $comp; # 2.561 ms (2 allocations: 31.39 KiB)
@btime $v * $comp; # 2.610 ms (2 allocations: 31.39 KiB)

```

Secondly, `cv` and `v` are matrices, not vectors.  
( `typeof(v) == Array{Complex{Float64},2}`).

Also note that you generally doesn’t have to (and shouldn’t) `collect` ranges.

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [July 26, 2019, 5:59pm UTC](https://discourse.julialang.org/t/vector-float-times-vector-complex-slower-than-vector-complex-times-vector-complex/26857/5 "2019-07-26T17:59:51Z")

</div>

Could it be a blas difference? I’m on linux.

---

<div class="post-metadata">

**Author:** ![foobar\_lv2](https://avatars.discourse-cdn.com/v4/letter/f/ee59a6/32.png) [@foobar\_lv2](https://discourse.julialang.org/u/foobar_lv2)\
**Post date:** [July 26, 2019, 6:30pm UTC](https://discourse.julialang.org/t/vector-float-times-vector-complex-slower-than-vector-complex-times-vector-complex/26857/6 "2019-07-26T18:30:49Z")

</div>

[https://github.com/JuliaLang/julia/issues/20060](https://github.com/JuliaLang/julia/issues/20060)

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [July 26, 2019, 6:41pm UTC](https://discourse.julialang.org/t/vector-float-times-vector-complex-slower-than-vector-complex-times-vector-complex/26857/7 "2019-07-26T18:41:59Z")

</div>

Thanks for finding the issue. It would be great if this were improved, though I understand it’s probably difficult if BLAS doesn’t support it natively
