-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
193 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# This file contains functions that the generated modules will dispatch to | ||
|
||
# List of Module => function that `JogPkgName` will dispatch to | ||
const DISPATCH_METHODS = [ | ||
:BenchmarkTools => :run, | ||
:BenchmarkTools => :warmup, | ||
:PkgJogger => :benchmark | ||
] | ||
|
||
""" | ||
benchmark(s::BenchmarkGroup) | ||
Warmup, tune and run a benchmark suite | ||
""" | ||
function benchmark(s::BenchmarkTools.BenchmarkGroup; kwargs...) | ||
warmup(s) | ||
tune!(s) | ||
BenchmarkTools.run(s) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
# This file contains functions related to building the JogPkgName module | ||
|
||
""" | ||
@jog PkgName | ||
Creates a module named `JogPkgName` of benchmarks for `PkgName` pulled from | ||
`PKG_DIR/benchmark/bench_*.jl` | ||
Methods: | ||
- `suite()` Return a `BenchmarkGroup` of the benchmarks for `PkgName` | ||
- `benchmark()` Warmup, tune and run the suite | ||
""" | ||
macro jog(pkg) | ||
# Module Name | ||
modname = Symbol(:Jog, pkg) | ||
|
||
# Locate benchmark folder | ||
bench_dir = @eval benchmark_dir($pkg) | ||
|
||
# Generate modules | ||
suite_modules = Expr[] | ||
benchmarks = Symbol[] | ||
for (name, file) in locate_benchmarks(bench_dir) | ||
push!(suite_modules, build_module(name, file)) | ||
push!(benchmarks, Symbol(name)) | ||
end | ||
|
||
# Dispatch to PkgJogger functions | ||
dispatch_funcs = Expr[] | ||
for (m, f) in DISPATCH_METHODS | ||
exp = quote | ||
$f(args...; kwargs...) = $(m).$(f)(suite(), args...; kwargs...) | ||
end | ||
push!(dispatch_funcs, exp) | ||
end | ||
|
||
# Flatten out modules into a Vector{Expr} | ||
suite_exp = getfield(MacroTools.flatten(quote $(suite_modules...) end), :args) | ||
|
||
# Generate Module for Jogging pkg | ||
quote | ||
@eval module $modname | ||
using $pkg | ||
using BenchmarkTools | ||
using PkgJogger | ||
using Revise | ||
|
||
# Set Revise Mode and put submodules here | ||
__revise_mode__ = :eval | ||
$(suite_exp...) | ||
|
||
""" | ||
suite() | ||
Gets the BenchmarkTools suite for $($pkg) | ||
""" | ||
function suite() | ||
suite = BenchmarkGroup() | ||
for (n, m) in zip([$(string.(benchmarks)...)], [$(benchmarks...)]) | ||
suite[n] = m.suite | ||
end | ||
suite | ||
end | ||
|
||
$(dispatch_funcs...) | ||
end | ||
end | ||
end | ||
|
||
""" | ||
benchmark_dir(pkg) | ||
Expected location of benchmarks for `pkg` | ||
""" | ||
function benchmark_dir(pkg::Module) | ||
pkg_dir = joinpath(dirname(pathof(pkg)), "..") | ||
joinpath(pkg_dir, "benchmark") |> abspath | ||
end | ||
|
||
|
||
function locate_benchmarks(dir) | ||
suite = Dict{String, String}() | ||
for file in readdir(dir; join=true) | ||
m = match(r"bench_(.*?)\.jl$", file) | ||
if m !== nothing | ||
suite[m.captures[1]] = file | ||
end | ||
end | ||
suite | ||
end | ||
|
||
""" | ||
build_module(name, file) | ||
Construct a module wrapping the BenchmarkGroup defined by `file` with `name` | ||
""" | ||
function build_module(name, file) | ||
modname = Symbol(name) | ||
exp = quote | ||
module $modname | ||
__revise_mode__ = :eval | ||
include($file) | ||
end | ||
Revise.track($modname, $file) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78dede2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JuliaRegistrator register()
78dede2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Registration pull request created: JuliaRegistries/General/42636
After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.
This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via: