Skip to content

Commit

Permalink
Add benchmark/bench_sparse.jl
Browse files Browse the repository at this point in the history
  • Loading branch information
tkf committed Jun 6, 2018
1 parent 637d6b9 commit 5de66c7
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
63 changes: 63 additions & 0 deletions benchmark/bench_sparse.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
include("preamble.jl")
using BenchmarkTools
using MatrixCombinators: muled, empty_array, mul!, _mul!, DumbExecutor

suite = BenchmarkGroup()
suite["default"] = suite_default = BenchmarkGroup()
suite["dumb"] = suite_dumb = BenchmarkGroup()
# suite_manual = BenchmarkGroup()


function benchmarkables_DiagTimesCSC(n, p, xtype, q=0.1)
if xtype <: Vector
make_x = (rng, n) -> randn(rng, n)
elseif xtype <: SparseVector
make_x = (rng, n) -> sprand(rng, n, q)
else
error("Unknown x type: $xtype")
end

prepare = function(rng)
D = Diagonal(randn(rng, n))
S = sprand(rng, n, n, p)
x = make_x(rng, n)
y = empty_array(Vector{Float64}, n)
M = muled(D, S)
return y, M, x
end

bench_default = @benchmarkable(
mul!(y, M, x),
setup = begin
y, M, x = $prepare($(MersenneTwister(1)))
end)

bench_dumb = @benchmarkable(
_mul!(executor, y, M, x),
setup = begin
y, M, x = $prepare($(MersenneTwister(1)))
executor = DumbExecutor(M.executor.allocator)
end)

return bench_default, bench_dumb
end


let bg_default = suite_default["DiagTimesCSC"] = BenchmarkGroup()
bg_dumb = suite_dumb["DiagTimesCSC"] = BenchmarkGroup()
# bg_manual = suite_manual["DiagTimesCSC"] = BenchmarkGroup()

for args in [
(1000, 0.1, Vector),
(1000, 0.01, Vector),
(1000, 0.001, Vector),
(1000, 0.1, SparseVector),
]
# bg_default[args], bg_dumb[args], bg_manual[args] =
bg_default[args], bg_dumb[args] =
benchmarkables_DiagTimesCSC(args...)
end
end


suite
6 changes: 6 additions & 0 deletions benchmark/preamble.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@static if VERSION < v"0.7.0-"
const ComplexF64 = Complex128
const ComplexF32 = Complex64
else
using Random
end

0 comments on commit 5de66c7

Please sign in to comment.