@@ -18,22 +18,42 @@ function simple_bench(N, T=Float64)
18
18
============================================
19
19
""" )
20
20
ops = [
21
- (" Matrix multiplication " , * , (A, A), (SA, SA)),
22
- (" Matrix multiplication (mutating) " , mul!, (B, A, A), (MB, MA, MA)),
23
- (" Matrix addition " , + , (A, A), (SA, SA)),
24
- (" Matrix addition (mutating) " , add!, (B, A, A), (MB, MA, MA)),
25
- (" Matrix determinant " , det, A, SA),
26
- (" Matrix inverse " , inv, A, SA),
27
- (" Matrix symmetric eigendecomposition" , eigen, A, SA),
28
- (" Matrix Cholesky decomposition " , cholesky, A, SA)
21
+ (" Matrix multiplication " , * , (A, A), (SA, SA)),
22
+ (" Matrix multiplication (mutating) " , mul!, (B, A, A), (MB, MA, MA)),
23
+ (" Matrix addition " , + , (A, A), (SA, SA)),
24
+ (" Matrix addition (mutating) " , add!, (B, A, A), (MB, MA, MA)),
25
+ (" Matrix determinant " , det, (A,), (SA,)),
26
+ (" Matrix inverse " , inv, (A,), (SA,)),
27
+ (" Matrix symmetric eigendecomposition" , eigen, (A,), (SA,)),
28
+ (" Matrix Cholesky decomposition " , cholesky, (A,), (SA,)),
29
+ (" Matrix LU decomposition " , lu, (A,), (SA,)),
30
+ (" Matrix QR decomposition " , qr, (A,), (SA,)),
29
31
]
30
32
for (name, op, Aargs, SAargs) in ops
31
- if Aargs isa Tuple && length (Aargs) == 2
32
- speedup = @belapsed ($ op ($ Aargs[1 ], $ Aargs[2 ])) / @belapsed ($ op ($ SAargs[1 ], $ SAargs[2 ]))
33
- elseif Aargs isa Tuple && length (Aargs) == 3
34
- speedup = @belapsed ($ op ($ Aargs[1 ], $ Aargs[2 ], $ Aargs[3 ])) / @belapsed ($ op ($ SAargs[1 ], $ SAargs[2 ], $ SAargs[3 ]))
33
+ # We load from Ref's here to avoid the compiler completely removing the
34
+ # benchmark in some cases.
35
+ #
36
+ # Like any microbenchmark, the speedups you see here should only be
37
+ # taken as roughly indicative of the speedup you may see in real code.
38
+ if length (Aargs) == 1
39
+ A1 = Ref (Aargs[1 ])
40
+ SA1 = Ref (SAargs[1 ])
41
+ speedup = @belapsed ($ op ($ A1[])) / @belapsed ($ op ($ SA1[]))
42
+ elseif length (Aargs) == 2
43
+ A1 = Ref (Aargs[1 ])
44
+ A2 = Ref (Aargs[2 ])
45
+ SA1 = Ref (SAargs[1 ])
46
+ SA2 = Ref (SAargs[2 ])
47
+ speedup = @belapsed ($ op ($ A1[], $ A2[])) / @belapsed ($ op ($ SA1[], $ SA2[]))
48
+ elseif length (Aargs) == 3
49
+ A1 = Ref (Aargs[1 ])
50
+ A2 = Ref (Aargs[2 ])
51
+ A3 = Ref (Aargs[3 ])
52
+ SA1 = Ref (SAargs[1 ])
53
+ SA2 = Ref (SAargs[2 ])
54
+ SA3 = Ref (SAargs[3 ])
55
+ speedup = @belapsed ($ op ($ A1[], $ A2[], $ A3[])) / @belapsed ($ op ($ SA1[], $ SA2[], $ SA3[]))
35
56
else
36
- speedup = @belapsed ($ op ($ Aargs)) / @belapsed ($ op ($ SAargs))
37
57
end
38
58
println (name* " -> $(round (speedup, digits= 1 )) x speedup" )
39
59
end
0 commit comments