Skip to content

Commit

Permalink
create benchmark groups
Browse files Browse the repository at this point in the history
  • Loading branch information
bvdmitri committed Nov 24, 2023
1 parent 64ef9bd commit 1c08e12
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 26 deletions.
1 change: 1 addition & 0 deletions .JuliaFormatter.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# See https://domluna.github.io/JuliaFormatter.jl/stable/ for a list of options
style = "blue"
margin = 140
64 changes: 38 additions & 26 deletions benchmarks/speed/benchmarks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,32 @@ using BenchmarkTools, LinearAlgebra
using FastCholesky

const SUITE = BenchmarkGroup()
const BenchmarkFloatTypes = (Float32, Float64, BigFloat)

for T in BenchmarkFloatTypes
SUITE[string(T)] = BenchmarkGroup()
SUITE[string(T)]["Number"] = BenchmarkGroup()
SUITE[string(T)]["Matrix"] = BenchmarkGroup()
SUITE[string(T)]["Diagonal"] = BenchmarkGroup()
end

# general benchmarks
for T in (Float32, Float64, BigFloat)
for T in BenchmarkFloatTypes

# number
a = rand(T)
SUITE["fastcholesky-" *"Type:"*string(T)] = @benchmarkable fastcholesky($a)
SUITE["fastcholesky!-" *"Type:"*string(T)] = @benchmarkable fastcholesky!($a)
SUITE["cholinv-" *"Type:"*string(T)] = @benchmarkable cholinv($a)
SUITE["cholsqrt-" *"Type:"*string(T)] = @benchmarkable cholsqrt($a)
SUITE["chollogdet-" *"Type:"*string(T)] = @benchmarkable chollogdet($a)
SUITE["cholinv_logdet-"*"Type:"*string(T)] = @benchmarkable cholinv_logdet($a)

SUITE[string(T)]["Number"]["fastcholesky"] = @benchmarkable fastcholesky($a)
SUITE[string(T)]["Number"]["fastcholesky!"] = @benchmarkable fastcholesky!($a)
SUITE[string(T)]["Number"]["cholinv"] = @benchmarkable cholinv($a)
SUITE[string(T)]["Number"]["cholsqrt"] = @benchmarkable cholsqrt($a)
SUITE[string(T)]["Number"]["chollogdet"] = @benchmarkable chollogdet($a)
SUITE[string(T)]["Number"]["cholinv_logdet"] = @benchmarkable cholinv_logdet($a)

for dim in (2, 5, 10, 20, 50, 100, 200, 500)

SUITE[string(T)]["Matrix"]["dim:" * string(dim)] = BenchmarkGroup()

# Skip `BigFloat` benchmarks for large dimensions because they are extremely slow
if (T == BigFloat) && (dim >= 100)
continue
Expand All @@ -30,33 +40,35 @@ for T in (Float32, Float64, BigFloat)

# The inplace version works only for `Matrix{<:BlasFloat}`
if T <: LinearAlgebra.BlasFloat
SUITE["fastcholesky!-" *"Type:Matrix{"*string(T)*"}-Dim:"*string(dim)] = @benchmarkable fastcholesky!($C)
SUITE[string(T)]["Matrix"]["dim:" * string(dim)]["fastcholesky!"] = @benchmarkable fastcholesky!($C)
end

# `sqrt` does not work for `BigFloat` inputs
if T != BigFloat
SUITE["cholsqrt-" *"Type:Matrix{"*string(T)*"}-Dim:"*string(dim)] = @benchmarkable cholsqrt($B)
SUITE[string(T)]["Matrix"]["dim:" * string(dim)]["cholsqrt"] = @benchmarkable cholsqrt($B)
end

# define benchmarks
SUITE["fastcholesky-" *"Type:Matrix{"*string(T)*"}-Dim:"*string(dim)] = @benchmarkable fastcholesky($B)
SUITE["cholinv-" *"Type:Matrix{"*string(T)*"}-Dim:"*string(dim)] = @benchmarkable cholinv($B)
SUITE["chollogdet-" *"Type:Matrix{"*string(T)*"}-Dim:"*string(dim)] = @benchmarkable chollogdet($B)
SUITE["cholinv_logdet-"*"Type:Matrix{"*string(T)*"}-Dim:"*string(dim)] = @benchmarkable cholinv_logdet($B)

SUITE[string(T)]["Matrix"]["dim:" * string(dim)]["fastcholesky"] = @benchmarkable fastcholesky($B)
SUITE[string(T)]["Matrix"]["dim:" * string(dim)]["cholinv"] = @benchmarkable cholinv($B)
SUITE[string(T)]["Matrix"]["dim:" * string(dim)]["chollogdet"] = @benchmarkable chollogdet($B)
SUITE[string(T)]["Matrix"]["dim:" * string(dim)]["cholinv_logdet"] = @benchmarkable cholinv_logdet($B)

SUITE[string(T)]["Diagonal"]["dim:" * string(dim)] = BenchmarkGroup()

# Diagonal{T} benchmarks
SUITE["fastcholesky-" *"Type:Diagonal{"*string(T)*"}"] = @benchmarkable fastcholesky($(Diagonal(ones(T, dim))))
SUITE["cholinv-" *"Type:Diagonal{"*string(T)*"}"] = @benchmarkable cholinv($(Diagonal(ones(T, dim))))
SUITE["cholsqrt-" *"Type:Diagonal{"*string(T)*"}"] = @benchmarkable cholsqrt($(Diagonal(ones(T, dim))))
SUITE["chollogdet-" *"Type:Diagonal{"*string(T)*"}"] = @benchmarkable chollogdet($(Diagonal(ones(T, dim))))
SUITE["cholinv_logdet-"*"Type:Diagonal{"*string(T)*"}"] = @benchmarkable cholinv_logdet($(Diagonal(ones(T, dim))))

SUITE[string(T)]["Diagonal"]["dim:" * string(dim)]["fastcholesky"]= @benchmarkable fastcholesky($(Diagonal(ones(T, dim))))
SUITE[string(T)]["Diagonal"]["dim:" * string(dim)]["cholinv"] = @benchmarkable cholinv($(Diagonal(ones(T, dim))))
SUITE[string(T)]["Diagonal"]["dim:" * string(dim)]["cholsqrt"] = @benchmarkable cholsqrt($(Diagonal(ones(T, dim))))
SUITE[string(T)]["Diagonal"]["dim:" * string(dim)]["chollogdet"] = @benchmarkable chollogdet($(Diagonal(ones(T, dim))))
SUITE[string(T)]["Diagonal"]["dim:" * string(dim)]["cholinv_logdet"] = @benchmarkable cholinv_logdet($(Diagonal(ones(T, dim))))
end

end

SUITE["UniformScaling"] = BenchmarkGroup()

# Uniformscaling benchmarks
SUITE["fastcholesky-" *"Type:UniformScaling"] = @benchmarkable fastcholesky($(3.0I))
SUITE["fastcholesky!-" *"Type:UniformScaling"] = @benchmarkable fastcholesky!($(3.0I))
SUITE["cholinv-" *"Type:UniformScaling"] = @benchmarkable cholinv($(3.0I))
SUITE["cholsqrt-" *"Type:UniformScaling"] = @benchmarkable cholsqrt($(3.0I))
SUITE["UniformScaling"]["fastcholesky"] = @benchmarkable fastcholesky($(3.0I))
SUITE["UniformScaling"]["fastcholesky!"] = @benchmarkable fastcholesky!($(3.0I))
SUITE["UniformScaling"]["cholinv"] = @benchmarkable cholinv($(3.0I))
SUITE["UniformScaling"]["cholsqrt"] = @benchmarkable cholsqrt($(3.0I))

0 comments on commit 1c08e12

Please sign in to comment.