-
Notifications
You must be signed in to change notification settings - Fork 28
/
benchmarkconfig.jl
96 lines (82 loc) · 2.79 KB
/
benchmarkconfig.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
"""
BenchmarkConfig
A `BenchmarkConfig` contains the configuration for the benchmarks to be executed
by [`benchmarkpkg`](@ref).
This includes the following:
* The commit of the package the benchmarks are run on.
* What julia command should be run, i.e. the path to the Julia executable and
the command flags used (e.g. optimization level with `-O`).
* Custom environment variables (e.g. `JULIA_NUM_THREADS`).
"""
struct BenchmarkConfig
id::Union{String,Nothing}
juliacmd::Cmd
env::Dict{String,Any}
end
"""
BenchmarkConfig(;id::Union{String, Nothing} = nothing,
juliacmd::Cmd = `joinpath(Sys.BINDIR, Base.julia_exename())`,
env::Dict{String, Any} = Dict{String, Any}())
Creates a `BenchmarkConfig` from the following keyword arguments:
* `id` - A git identifier like a commit, branch, tag, "HEAD", "HEAD~1" etc.
If `id == nothing` then benchmark will be done on the current state
of the repo (even if it is dirty).
* `juliacmd` - Used to exectue the benchmarks, defaults to the julia executable
that the Pkgbenchmark-functions are called from. Can also include command flags.
* `env` - Contains custom environment variables that will be active when the
benchmarks are run.
# Examples
```julia
julia> using Pkgbenchmark
julia> BenchmarkConfig(id = "performance_improvements",
juliacmd = `julia -O3`,
env = Dict("JULIA_NUM_THREADS" => 4))
BenchmarkConfig:
id: performance_improvements
juliacmd: `julia -O3`
env: JULIA_NUM_THREADS => 4
```
"""
function BenchmarkConfig(;id::Union{String,Nothing} = nothing,
juliacmd::Cmd = `$(joinpath(Sys.BINDIR, Base.julia_exename()))`,
env::Dict = Dict{String,Any}())
BenchmarkConfig(id, juliacmd, env)
end
BenchmarkConfig(cfg::BenchmarkConfig) = cfg
BenchmarkConfig(str::String) = BenchmarkConfig(id = str)
BenchmarkConfig(::Nothing) = BenchmarkConfig()
function BenchmarkConfig(d::Dict)
BenchmarkConfig(
d["id"],
Cmd(d["juliacmd"]),
d["env"]
)
end
# Arr!...
function Base.Cmd(d::Dict)
Cmd(
Cmd(convert(Vector{String}, d["exec"])),
d["ignorestatus"],
d["flags"],
d["env"],
d["dir"],
)
end
const _INDENT = " "
function Base.show(io::IO, bcfg::BenchmarkConfig)
println(io, "BenchmarkConfig:")
print(io, _INDENT, "id: "); show(bcfg.id); println()
println(io, _INDENT, "juliacmd: ", bcfg.juliacmd)
print(io, _INDENT, "env: ")
if !isempty(bcfg.env)
first = true
for (k, v) in bcfg.env
if !first
println(io)
print(io, _INDENT, " "^strwidth("env: "))
end
first = false
print(io, k, " => ", v)
end
end
end