Skip to content

Commit

Permalink
add a template and plugin for PkgBenchmarks (#261)
Browse files Browse the repository at this point in the history
* add a template and plugin for BenchmarkTools

* Rename into PkgBenchmark

* Fix tests

* Docstring

---------

Co-authored-by: = <=>
Co-authored-by: Guillaume Dalle <[email protected]>
  • Loading branch information
anandijain and gdalle authored Dec 18, 2023
1 parent e7b5a51 commit dea191b
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/src/user.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ Citation
RegisterAction
Formatter
CodeOwners
PkgBenchmark
```

## A More Complicated Example
Expand Down
1 change: 1 addition & 0 deletions src/PkgTemplates.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export
License,
Logo,
NoDeploy,
PkgBenchmark,
PkgEvalBadge,
ProjectFile,
Readme,
Expand Down
1 change: 1 addition & 0 deletions src/plugin.jl
Original file line number Diff line number Diff line change
Expand Up @@ -376,3 +376,4 @@ include(joinpath("plugins", "badges.jl"))
include(joinpath("plugins", "register.jl"))
include(joinpath("plugins", "dependabot.jl"))
include(joinpath("plugins", "formatter.jl"))
include(joinpath("plugins", "pkgbenchmark.jl"))
21 changes: 21 additions & 0 deletions src/plugins/pkgbenchmark.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""
PkgBenchmark(; file="$(contractuser(default_file("benchmark", "benchmarks.jl")))")
Sets up a [PkgBenchmark.jl](https://github.com/JuliaCI/PkgBenchmark.jl) benchmark suite.
To ensure benchmark reproducibility, you will need to manually create an environment in the `benchmark` subfolder (for which the `Manifest.toml` is committed to version control).
In this environment, you should at the very least:
- `pkg> add BenchmarkTools`
- `pkg> dev` your new package.
## Keyword Arguments
- `file::AbstractString`: Template file for `benchmarks.jl`.
"""
@plugin struct PkgBenchmark <: FilePlugin
file::String = default_file("benchmark", "benchmarks.jl")
end

source(p::PkgBenchmark) = p.file
destination(::PkgBenchmark) = joinpath("benchmark", "benchmarks.jl")
view(::PkgBenchmark, ::Template, pkg::AbstractString) = Dict("PKG" => pkg)
7 changes: 7 additions & 0 deletions templates/benchmark/benchmarks.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using {{{PKG}}}
using BenchmarkTools

SUITE = BenchmarkGroup()
SUITE["rand"] = @benchmarkable rand(10)

# Write your benchmarks here.
7 changes: 7 additions & 0 deletions test/fixtures/WackyOptions/benchmark/benchmarks.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using WackyOptions
using BenchmarkTools

SUITE = BenchmarkGroup()
SUITE["rand"] = @benchmarkable rand(10)

# Write your benchmarks here.
1 change: 1 addition & 0 deletions test/reference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ end
GitHubActions(; x86=true, linux=false, coverage=false),
GitLabCI(; coverage=false, extra_versions=[v"0.6"]),
License(; name="ISC"),
PkgBenchmark(),
PkgEvalBadge(),
ProjectFile(; version=v"1"),
Readme(; inline_badges=true, badge_off=[Codecov]),
Expand Down

0 comments on commit dea191b

Please sign in to comment.