diff --git a/benchmark/Project.toml b/benchmark/Project.toml index 3cbe72fa..5a82d61b 100644 --- a/benchmark/Project.toml +++ b/benchmark/Project.toml @@ -2,3 +2,4 @@ BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" PkgBenchmark = "32113eaa-f34f-5b0d-bd6c-c81e245fc73d" +Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" diff --git a/benchmark/bench_matrix_ops.jl b/benchmark/bench_matrix_ops.jl new file mode 100644 index 00000000..2795c1e2 --- /dev/null +++ b/benchmark/bench_matrix_ops.jl @@ -0,0 +1,45 @@ +module BenchMatrixOps + +import Random +using BenchmarkTools +using LinearAlgebra +using StaticArrays + +const suite = BenchmarkGroup() +const matrix_sizes = if haskey(ENV, "GITHUB_EVENT_PATH") + (1, 2, 3, 4, 10, 20) +else + 1:20 +end + +# Use same arrays across processes (at least with the same Julia version): +Random.seed!(1234) + +# Unary operators +for f in [det, inv, exp] + s1 = suite["$f"] = BenchmarkGroup() + for N in matrix_sizes + SA = @SMatrix rand(N, N) + A = Array(SA) + s2 = s1[string(N, pad=2)] = BenchmarkGroup() + s2["SMatrix"] = @benchmarkable $f($SA) + s2["Matrix"] = @benchmarkable $f($A) + end +end + +# Binary operators +for f in [*, \] + s1 = suite["$f"] = BenchmarkGroup() + for N in matrix_sizes + SA = @SMatrix rand(N, N) + SB = @SMatrix rand(N, N) + A = Array(SA) + B = Array(SB) + s2 = s1[string(N, pad=2)] = BenchmarkGroup() + s2["SMatrix"] = @benchmarkable $f($SA, $SB) + s2["Matrix"] = @benchmarkable $f($A, $B) + end +end + +end # module +BenchMatrixOps.suite