Skip to content

Commit

Permalink
Tidy up benchmarks.jl, add option to select suites
Browse files Browse the repository at this point in the history
Example of selecting a suite:
```julia
benchmarkpkg(GCPDecompositions, BenchmarkConfig(;env=Dict("GCP_BENCHMARK_SUITES"=>"mttkrp")))
```

Inspired by: https://github.com/JuliaCI/BaseBenchmarks.jl/blob/0ec1edace2d731de8d926f4b48a22cf2e5cc99c2/src/BaseBenchmarks.jl
  • Loading branch information
dahong67 committed Nov 4, 2023
1 parent 3aa8c86 commit dc961f3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
24 changes: 13 additions & 11 deletions benchmark/benchmarks.jl
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
using BenchmarkTools

BenchmarkTools.DEFAULT_PARAMETERS.seconds = 1
# Default benchmark parameters
BenchmarkTools.DEFAULT_PARAMETERS.seconds = 1.0

const SUITE = BenchmarkGroup()

module BenchmarkGCP
include("gcp.jl")
end
# Benchmark suite modules
const SUITE_MODULES = Dict("gcp" => :BenchmarkGCP, "mttkrp" => :BenchmarkMTTKRP)
const DEFAULT_SUITES = join(keys(SUITE_MODULES), ' ')

module BenchmarkMTTKRP
include("mttkrp.jl")
# Create top-level suite including only sub-suites
# specified by ENV variable "GCP_BENCHMARK_SUITES"
const SUITE = BenchmarkGroup()
SELECTED_SUITES = split(get(ENV, "GCP_BENCHMARK_SUITES", DEFAULT_SUITES))
for suite_name in SELECTED_SUITES
module_name = SUITE_MODULES[suite_name]
include(joinpath(@__DIR__, "$(suite_name).jl"))
SUITE[suite_name] = eval(module_name).SUITE
end

SUITE["gcp"] = BenchmarkGCP.SUITE
SUITE["mttkrp"] = BenchmarkMTTKRP.SUITE
4 changes: 4 additions & 0 deletions benchmark/gcp.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module BenchmarkGCP

using BenchmarkTools

using Random
Expand Down Expand Up @@ -40,3 +42,5 @@ for sz in [(15, 20, 25), (30, 40, 50)], r in 1:2
X = [rand(Bernoulli(M[I]/(M[I] + 1))) for I in CartesianIndices(size(M))]
bench_gcp["bernoulliOdds-size(X)=$sz, rank(X)=$r"] = @benchmarkable gcp($X, $r, BernoulliOddsLoss())
end

end
4 changes: 4 additions & 0 deletions benchmark/mttkrp.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module BenchmarkMTTKRP

using BenchmarkTools

using Random
Expand All @@ -17,4 +19,6 @@ for sz in shapes, r in rs
X = randn(sz)
U = [randn(Ik,r) for Ik in sz]
bench_mttkrp["mttkrp-size(X)=$sz, rank(X)=$r"] = @benchmarkable GCPDecompositions.mttkrp($X, $U, $n)
end

end

0 comments on commit dc961f3

Please sign in to comment.