Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3 argument dot is slower than a matmul and two arg dot #1287

Open
SobhanMP opened this issue Nov 29, 2024 · 0 comments
Open

3 argument dot is slower than a matmul and two arg dot #1287

SobhanMP opened this issue Nov 29, 2024 · 0 comments

Comments

@SobhanMP
Copy link

Somewhat counter intuitive:

using LinearAlgebra, StaticArrays, BenchmarkTools

f1(x, A) = dot(x, A * x)
f2(x, A) = dot(x, A, x)
let 
    x = randn(3)
    A = randn(3, 3)
    A = A * A' + 1e-6 * I
    sx = SVector{3}(x...)
    sA = SMatrix{3,3}(A...)
    display(@benchmark(f1($sx, $sA)))
    display(@benchmark(f2($sx, $sA)))
end


BenchmarkTools.Trial: 10000 samples with 1000 evaluations.
 Range (min … max):  2.813 ns … 18.835 ns  ┊ GC (min … max): 0.00% … 0.00%
 Time  (median):     2.817 ns              ┊ GC (median):    0.00%
 Time  (mean ± σ):   2.878 ns ±  0.673 ns  ┊ GC (mean ± σ):  0.00% ± 0.00%

  █   ▅▁                                                     ▁
  █▅▁▁██▄▁▄▁▁▁▁▁▇▁▁▁▁▆▃▁▁▃▃▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▃▄▄▃▆▇▅ █
  2.81 ns      Histogram: log(frequency) by time     3.54 ns <

 Memory estimate: 0 bytes, allocs estimate: 0.
BenchmarkTools.Trial: 10000 samples with 1000 evaluations.
 Range (min … max):  3.815 ns … 54.783 ns  ┊ GC (min … max): 0.00% … 0.00%
 Time  (median):     3.821 ns              ┊ GC (median):    0.00%
 Time  (mean ± σ):   3.931 ns ±  1.141 ns  ┊ GC (mean ± σ):  0.00% ± 0.00%

  █  ▆     ▁                                                 ▁
  █▆▅█▅▇▃▅▇█▃▅▃▅▄▅▁▁▁▄▁▁▁▃▁▁▁▁▁▃▃▁▃▁▃▁▁▁▃▁▁▁▁▃▁▃▃▁▁▁▁▄▁▁▁▁▁▃ █
  3.82 ns      Histogram: log(frequency) by time      5.3 ns <

 Memory estimate: 0 bytes, allocs estimate: 0.
julia> versioninfo()
Julia Version 1.11.1
Commit 8f5b7ca12ad (2024-10-16 10:53 UTC)
Build Info:
 Official https://julialang.org/ release
Platform Info:
 OS: Linux (x86_64-linux-gnu)
 CPU: 16 × 11th Gen Intel(R) Core(TM) i7-11700K @ 3.60GHz
 WORD_SIZE: 64
 LLVM: libLLVM-16.0.6 (ORCJIT, rocketlake)
Threads: 16 default, 0 interactive, 8 GC (on 16 virtual cores)
Environment:
 JULIA_EDITOR = code
 JULIA_NUM_THREADS = 16

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant