# Time it takes to multiply two floats

**URL:** <https://discourse.julialang.org/t/time-it-takes-to-multiply-two-floats/85933>\
**Category:** Numerics\
**Tags:** float\
**Created:** [August 18, 2022, 4:40pm UTC](https://discourse.julialang.org/t/time-it-takes-to-multiply-two-floats/85933 "2022-08-18T16:40:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![JUAN\_CARLOS\_GALVIS\_A](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juan_carlos_galvis_a/32/38882_2.png) [@JUAN\_CARLOS\_GALVIS\_A](https://discourse.julialang.org/u/JUAN_CARLOS_GALVIS_A)\
**Post date:** [August 18, 2022, 4:40pm UTC](https://discourse.julialang.org/t/time-it-takes-to-multiply-two-floats/85933/1 "2022-08-18T16:40:04Z")

</div>

When i benchmark the multiplication of two Float16, compared to the multiplication of two Float64, it seems it takes the same time. Is this right?

---

<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:** [August 18, 2022, 4:44pm UTC](https://discourse.julialang.org/t/time-it-takes-to-multiply-two-floats/85933/2 "2022-08-18T16:44:18Z")

</div>

No. Benchmarking ns operations is hard. On most cpus, Float16 multiplication will be roughly 10x slower than Float64. On an M1 chip, Float16 should be similar speed (but it depends what you do with it, and I think it will only be fast on 1.9)

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [August 18, 2022, 6:09pm UTC](https://discourse.julialang.org/t/time-it-takes-to-multiply-two-floats/85933/3 "2022-08-18T18:09:31Z")

</div>

For a long vector of these floats, it seems that the performance (here - 11th Gen Intel), performance is quite similar, but that `LoopVectorization` can extract a bit of performance of the lower precision:

```julia
(v1.8) julia> using LoopVectorization

(v1.8) julia> f(x,y,z) = z .= x .* y
f (generic function with 2 methods)

(v1.8) julia> f2(x,y,z) = @turbo z .= x .* y
f2 (generic function with 1 method)

(v1.8) julia> x = rand(Float16, 10^6); y = rand(Float16, 10^6); z = similar(x);

(v1.8) julia> @btime f($x,$y,$z);
  1.090 ms (0 allocations: 0 bytes)

(v1.8) julia> @btime f2($x,$y,$z);
  887.598 μs (0 allocations: 0 bytes)

(v1.8) julia> x = rand(Float64, 10^6); y = rand(Float64, 10^6); z = similar(x);

(v1.8) julia> @btime f($x,$y,$z);
  1.048 ms (0 allocations: 0 bytes)

(v1.8) julia> @btime f2($x,$y,$z);
  1.070 ms (0 allocations: 0 bytes)

(v1.8) julia> x = rand(Float32, 10^6); y = rand(Float32, 10^6); z = similar(x);

(v1.8) julia> @btime f($x,$y,$z);
  274.767 μs (0 allocations: 0 bytes)

(v1.8) julia> @btime f2($x,$y,$z);
  273.939 μs (0 allocations: 0 bytes)

```

Not much, though, I was expecting a significant speedup due to to SIMD here, similar or greater to what one gets with 32bits.
