/
pkgbmark.jl
181 lines (147 loc) · 5.39 KB
/
pkgbmark.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
import BenchmarkTools
import GitHub
import JSON
import PkgBenchmark
export bmark_results_to_dataframes, judgement_results_to_dataframes, profile_package, to_gist
"""
stats = bmark_results_to_dataframes(results)
Convert `PkgBenchmark` results to a dictionary of `DataFrame`s.
The benchmark SUITE should have been constructed in
the form
SUITE[solver][case] = ...
where `solver` will be recorded as one of the solvers
to be compared in the DataFrame and case is a test
case. For example:
SUITE["CG"]["BCSSTK09"] = @benchmarkable ...
SUITE["LBFGS"]["ROSENBR"] = @benchmarkable ...
Inputs:
- `results::BenchmarkResults`: the result of `PkgBenchmark.benchmarkpkg`
Output:
- `stats::Dict{Symbol,DataFrame}`: a dictionary of `DataFrame`s containing the
benchmark results per solver.
"""
function bmark_results_to_dataframes(results::PkgBenchmark.BenchmarkResults)
entries = BenchmarkTools.leaves(PkgBenchmark.benchmarkgroup(results))
entries = entries[sortperm(map(x -> string(first(x)), entries))]
solvers = unique(map(pair -> pair[1][1], entries))
names = [:name, :time, :memory, :gctime, :allocations]
types = [String, Float64, Float64, Float64, Int]
stats = Dict{Symbol, DataFrame}()
for solver in solvers
stats[Symbol(solver)] = DataFrame(names .=> [T[] for T in types])
end
for entry in entries
case, trial = entry
name = case[end]
solver = Symbol(case[1])
time = BenchmarkTools.time(trial)
mem = BenchmarkTools.memory(trial)
gctime = BenchmarkTools.gctime(trial)
allocs = BenchmarkTools.allocs(trial)
push!(stats[solver], [name, time, mem, gctime, allocs])
end
stats
end
"""
stats = judgement_results_to_dataframes(judgement)
Convert `BenchmarkJudgement` results to a dictionary of `DataFrame`s.
Inputs:
- `judgement::BenchmarkJudgement`: the result of, e.g.,
commit = benchmarkpkg(mypkg) # benchmark a commit or pull request
main = benchmarkpkg(mypkg, "main") # baseline benchmark
judgement = judge(commit, main)
Output:
- `stats::Dict{Symbol,Dict{Symbol,DataFrame}}`: a dictionary of
`Dict{Symbol,DataFrame}`s containing the target and baseline benchmark results.
The elements of this dictionary are the same as those returned by
`bmark_results_to_dataframes(main)` and `bmark_results_to_dataframes(commit)`.
"""
function judgement_results_to_dataframes(judgement::PkgBenchmark.BenchmarkJudgement)
target_stats = bmark_results_to_dataframes(judgement.target_results)
baseline_stats = bmark_results_to_dataframes(judgement.baseline_results)
Dict{Symbol, Dict{Symbol, DataFrame}}(
k => Dict{Symbol, DataFrame}(:target => target_stats[k], :baseline => baseline_stats[k]) for
k ∈ keys(target_stats)
)
end
"""
p = profile_solvers(results)
Produce performance profiles based on `PkgBenchmark.benchmarkpkg` results.
Inputs:
- `results::BenchmarkResults`: the result of `PkgBenchmark.benchmarkpkg`.
"""
function profile_solvers(results::PkgBenchmark.BenchmarkResults)
# guard against zero gctimes
costs =
[df -> df[!, :time], df -> df[!, :memory], df -> df[!, :gctime] .+ 1, df -> df[!, :allocations]]
profile_solvers(
bmark_results_to_dataframes(results),
costs,
["time", "memory", "gctime+1", "allocations"],
)
end
"""
p = profile_package(judgement)
Produce performance profiles based on `PkgBenchmark.BenchmarkJudgement` results.
Inputs:
- `judgement::BenchmarkJudgement`: the result of, e.g.,
commit = benchmarkpkg(mypkg) # benchmark a commit or pull request
main = benchmarkpkg(mypkg, "main") # baseline benchmark
judgement = judge(commit, main)
"""
function profile_package(judgement::PkgBenchmark.BenchmarkJudgement)
# guard against zero gctimes
costs =
[df -> df[!, :time], df -> df[!, :memory], df -> df[!, :gctime] .+ 1, df -> df[!, :allocations]]
judgement_dataframes = judgement_results_to_dataframes(judgement)
Dict{Symbol, Plots.Plot}(
k => profile_solvers(
judgement_dataframes[k],
costs,
["time", "memory", "gctime+1", "allocations"],
) for k ∈ keys(judgement_dataframes)
)
end
"""
posted_gist = to_gist(results, p)
Create and post a gist with the benchmark results and performance profiles.
Inputs:
- `results::BenchmarkResults`: the result of `PkgBenchmark.benchmarkpkg`
- `p`:: the result of `profile_solvers`.
Output:
- the return value of GitHub.jl's `create_gist`.
"""
function to_gist(results::PkgBenchmark.BenchmarkResults, p)
filename = tempname()
svgfilename = "$(filename).svg"
savefig(p, svgfilename)
svgfilecontents = escape_string(read(svgfilename, String))
gist_json = JSON.parse(
"""
{
"description": "Benchmarks uploaded by SolverBenchmark.jl",
"public": true,
"files": {
"bmark.md": {
"content": "$(escape_string(sprint(PkgBenchmark.export_markdown, results; context=stdout)))"
},
"bmark.svg": {
"content": "$(svgfilecontents)"
}
}
}
""",
)
# Need to add GITHUB_AUTH to your .bashrc
myauth = GitHub.authenticate(ENV["GITHUB_AUTH"])
GitHub.create_gist(params = gist_json, auth = myauth)
end
"""
posted_gist = to_gist(results)
Create and post a gist with the benchmark results and performance profiles.
Inputs:
- `results::BenchmarkResults`: the result of `PkgBenchmark.benchmarkpkg`
Output:
- the return value of GitHub.jl's `create_gist`.
"""
to_gist(results) = to_gist(results, profile_solvers(results))