Skip to content

Commit

Permalink
Merge e24140a into 29ed73f
Browse files Browse the repository at this point in the history
  • Loading branch information
omus committed May 4, 2020
2 parents 29ed73f + e24140a commit a1c118b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
8 changes: 4 additions & 4 deletions src/judge.jl
@@ -1,12 +1,12 @@
"""
judge(pkg::String,
judge(pkg::Union{Module, String},
[target]::Union{String, BenchmarkConfig},
baseline::Union{String, BenchmarkConfig};
kwargs...)
**Arguments**:
- `pkg` - The path to the package to benchmark, use `pathof(Package)`
- `pkg` - Package to benchmark. Either a package module, name, or directory.
- `target` - What do judge, given as a git id or a [`BenchmarkConfig`](@ref). If skipped, use the current state of the package repo.
- `baseline` - The commit / [`BenchmarkConfig`](@ref) to compare `target` against.
Expand All @@ -21,7 +21,7 @@ The remaining keyword arguments are passed to [`benchmarkpkg`](@ref)
Returns a [`BenchmarkJudgement`](@ref)
"""
function BenchmarkTools.judge(pkg::String, target::Union{BenchmarkConfig,String}, baseline::Union{BenchmarkConfig,String};
function BenchmarkTools.judge(pkg::Union{Module,String}, target::Union{BenchmarkConfig,String}, baseline::Union{BenchmarkConfig,String};
f=minimum, judgekwargs=Dict(), kwargs...)

target, baseline = BenchmarkConfig(target), BenchmarkConfig(baseline)
Expand All @@ -32,7 +32,7 @@ function BenchmarkTools.judge(pkg::String, target::Union{BenchmarkConfig,String}
return judge(group_target, group_baseline, f; judgekwargs=judgekwargs)
end

function BenchmarkTools.judge(pkg::String, baseline::Union{BenchmarkConfig,String}; kwargs...)
function BenchmarkTools.judge(pkg::Union{Module,String}, baseline::Union{BenchmarkConfig,String}; kwargs...)
judge(pkg, BenchmarkConfig(), baseline; kwargs...)
end

Expand Down
22 changes: 16 additions & 6 deletions src/runbenchmark.jl
Expand Up @@ -5,7 +5,8 @@ Run a benchmark on the package `pkg` using the [`BenchmarkConfig`](@ref) or git
Examples of git identifiers are commit shas, branch names, or e.g. `"HEAD~1"`.
Return a [`BenchmarkResults`](@ref).
The argument `pkg` can be a name of a package or a path to a directory to a package.
The argument `pkg` can be the module of a package, a package name, or the path to the
package's root directory.
**Keyword arguments**:
Expand All @@ -28,16 +29,18 @@ The result can be used by functions such as [`judge`](@ref). If you choose to, y
using PkgBenchmark
import MyPkg
benchmarkpkg(pathof(MyPkg)) # run the benchmarks at the current state of the repository
benchmarkpkg(pathof(MyPkg), "my-feature") # run the benchmarks for a particular branch/commit/tag
benchmarkpkg(pathof(MyPkg), "my-feature"; script="/home/me/mycustombenchmark.jl")
benchmarkpkg(pathof(MyPkg), BenchmarkConfig(id = "my-feature",
benchmarkpkg(MyPkg) # run the benchmarks at the current state of the repository
benchmarkpkg(MyPkg, "my-feature") # run the benchmarks for a particular branch/commit/tag
benchmarkpkg(MyPkg, "my-feature"; script="/home/me/mycustombenchmark.jl")
benchmarkpkg(MyPkg, BenchmarkConfig(id = "my-feature",
env = Dict("JULIA_NUM_THREADS" => 4),
juliacmd = `julia -O3`))
benchmarkpkg(pathof(MyPkg), # Run the benchmarks and divide the (median of) results by 1000
benchmarkpkg(MyPkg, # Run the benchmarks and divide the (median of) results by 1000
postprocess=(results)->(results["g"] = median(results["g"])/1_000)
```
"""
function benchmarkpkg end

function benchmarkpkg(
pkg::String,
target=BenchmarkConfig();
Expand Down Expand Up @@ -151,6 +154,13 @@ function benchmarkpkg(
return results
end

function benchmarkpkg(pkg::Module, args...; kwargs...)
dir = pathof(pkg)
dir !== nothing || throw(ArgumentError("Module $pkg is not a package"))
pkg_root = dirname(dirname(dir))
benchmarkpkg(pkg_root, args...; kwargs...)
end

"""
objectpath(x) -> (pkg_uuid::Union{String,Nothing}, pkg_name::String, name::Symbol...)
Expand Down
8 changes: 8 additions & 0 deletions test/runtests.jl
Expand Up @@ -24,6 +24,9 @@ end

const BENCHMARK_DIR = joinpath(@__DIR__, "..", "benchmark")

# A module which isn't a package
module Empty end

function temp_pkg_dir(fn::Function; tmp_dir=joinpath(tempdir(), randstring()),
remove_tmp_dir::Bool=true, initialize::Bool=true)
# Used in tests below to set up and tear down a sandboxed package directory
Expand Down Expand Up @@ -222,3 +225,8 @@ end
@testset "doctest" begin
doctest(PkgBenchmark)
end

@testset "package module" begin
@test_throws ArgumentError benchmarkpkg(Empty)
@test benchmarkpkg(PkgBenchmark) isa BenchmarkResults
end

0 comments on commit a1c118b

Please sign in to comment.