-
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
5 changed files
with
147 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,15 @@ uuid = "10150987-6cc1-4b76-abee-b1c1cbd91c01" | |
authors = ["Alexius Wadell <[email protected]> and contributors"] | ||
version = "0.1.0" | ||
|
||
[deps] | ||
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf" | ||
MacroTools = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09" | ||
Revise = "295af30f-e4ad-537b-8983-00126c2a3abe" | ||
|
||
[compat] | ||
Revise = "3" | ||
MacroTools = "0.5" | ||
BenchmarkTools = "1" | ||
julia = "1.6" | ||
|
||
[extras] | ||
|
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,5 @@ | ||
using BenchmarkTools | ||
|
||
suite = BenchmarkGroup() | ||
suite["sin"] = @benchmarkable sin(rand()) | ||
suite["sincos"] = @benchmarkable sincos(rand()) |
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 |
---|---|---|
@@ -1,5 +1,116 @@ | ||
module PkgJogger | ||
|
||
# Write your package code here. | ||
using MacroTools | ||
using BenchmarkTools | ||
|
||
export @jog | ||
|
||
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 [(:BenchmarkTools, :run), (:BenchmarkTools, :warmup), (:PkgJogger, :benchmark)] | ||
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 | ||
|
||
|
||
""" | ||
benchmark(s::BenchmarkGroup) | ||
Warmup, tune and run a benchmark suite | ||
""" | ||
function benchmark(s::BenchmarkTools.BenchmarkGroup; kwargs...) | ||
warmup(s) | ||
tune!(s) | ||
BenchmarkTools.run(s) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,5 @@ using PkgJogger | |
using Test | ||
|
||
@testset "PkgJogger.jl" begin | ||
# Write your tests here. | ||
include("smoke.jl") | ||
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,21 @@ | ||
using Test | ||
using PkgJogger | ||
import BenchmarkTools | ||
|
||
benchmark_dir = PkgJogger.benchmark_dir(PkgJogger) | ||
|
||
@testset "canonical" begin | ||
@jog PkgJogger | ||
@test @isdefined JogPkgJogger | ||
|
||
# Run Benchmarks | ||
r = JogPkgJogger.benchmark() | ||
@test typeof(r) <: BenchmarkTools.BenchmarkGroup | ||
|
||
# Warmup | ||
@test_nowarn JogPkgJogger.warmup() | ||
|
||
# Running | ||
r = JogPkgJogger.run() | ||
@test typeof(r) <: BenchmarkTools.BenchmarkGroup | ||
end |