Mercurial > repos > public > sbplib_julia
comparison benchmark/benchmark_utils.jl @ 1854:654a2b7e6824 tooling/benchmarks
Merge default
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Sat, 11 Jan 2025 10:19:47 +0100 |
parents | 471a948cd2b2 |
children | e1d64f4110bd |
comparison
equal
deleted
inserted
replaced
1378:2b5480e2d4bf | 1854:654a2b7e6824 |
---|---|
1 import PkgBenchmark | 1 import PkgBenchmark |
2 import Markdown | 2 import Markdown |
3 import Mustache | 3 import Mustache |
4 import Dates | 4 import Dates |
5 | 5 |
6 import Sbplib | 6 import Diffinitive |
7 | 7 |
8 const sbplib_root = splitpath(pathof(Sbplib))[1:end-2] |> joinpath | 8 const diffinitive_root = splitpath(pathof(Diffinitive))[1:end-2] |> joinpath |
9 const results_dir = mkpath(joinpath(sbplib_root, "benchmark/results")) | 9 const results_dir = mkpath(joinpath(diffinitive_root, "benchmark/results")) |
10 const template_path = joinpath(sbplib_root, "benchmark/result.tmpl") | 10 const template_path = joinpath(diffinitive_root, "benchmark/result.tmpl") |
11 | 11 |
12 """ | 12 """ |
13 mainmain(;rev=nothing, target=nothing, baseline=nothing , kwargs...) | 13 mainmain(;rev=nothing, target=nothing, baseline=nothing , kwargs...) |
14 | 14 |
15 Calls `run_benchmark(args...; kwargs...)` and writes the results as an HTML | 15 Calls `run_benchmark(args...; kwargs...)` and writes the results as an HTML |
21 * If both `target` and `baseline` is set those revision are compared. | 21 * If both `target` and `baseline` is set those revision are compared. |
22 | 22 |
23 For control over what happens to the benchmark result datastructure see the | 23 For control over what happens to the benchmark result datastructure see the |
24 different methods of [`run_benchmark`](@ref) | 24 different methods of [`run_benchmark`](@ref) |
25 """ | 25 """ |
26 function main(;rev=nothing, target=nothing, baseline=nothing , kwargs...) | 26 function main(;rev=nothing, target=nothing, baseline=nothing, name=nothing, kwargs...) |
27 if !isnothing(rev) | 27 if !isnothing(rev) |
28 r = run_benchmark(rev; kwargs...) | 28 r = run_benchmark(rev; kwargs...) |
29 elseif !isnothing(baseline) | 29 elseif !isnothing(baseline) |
30 if isnothing(target) | 30 if isnothing(target) |
31 r = compare_benchmarks(baseline; kwargs...) | 31 r = compare_benchmarks(baseline; kwargs...) |
35 else | 35 else |
36 # Neither rev, or baseline were set => Run on current working directory. | 36 # Neither rev, or baseline were set => Run on current working directory. |
37 r = run_benchmark(;kwargs...) | 37 r = run_benchmark(;kwargs...) |
38 end | 38 end |
39 | 39 |
40 file_path = write_result_html(r) | 40 file_path = write_result_html(r; name) |
41 open_in_default_browser(file_path) | 41 open_in_default_browser(file_path) |
42 end | 42 end |
43 | 43 |
44 | 44 |
45 """ | 45 """ |
47 | 47 |
48 Run the benchmark suite for the current working directory and return a | 48 Run the benchmark suite for the current working directory and return a |
49 `PkgBenchmark.BenchmarkResult` | 49 `PkgBenchmark.BenchmarkResult` |
50 """ | 50 """ |
51 function run_benchmark(;kwargs...) | 51 function run_benchmark(;kwargs...) |
52 r = PkgBenchmark.benchmarkpkg(Sbplib; kwargs...) | 52 r = PkgBenchmark.benchmarkpkg(Diffinitive; kwargs...) |
53 | 53 |
54 rev = hg_rev() # Should be changed to hg_id() when the html can handle it. | 54 rev = hg_rev() # Should be changed to hg_id() when the html can handle it. |
55 | 55 |
56 return add_rev_info(r, rev) | 56 return add_rev_info(r, rev) |
57 end | 57 end |
135 | 135 |
136 dt = Dates.format(PkgBenchmark.date(r), "yyyy-mm-dd HH:MM:SS") | 136 dt = Dates.format(PkgBenchmark.date(r), "yyyy-mm-dd HH:MM:SS") |
137 Mustache.render(io, template, Dict("title"=>dt, "content"=>content)) | 137 Mustache.render(io, template, Dict("title"=>dt, "content"=>content)) |
138 end | 138 end |
139 | 139 |
140 function write_result_html(r) | 140 function write_result_html(r; name=nothing) |
141 dt = Dates.format(PkgBenchmark.date(r), "yyyy-mm-dd HHMMSS") | 141 dt = Dates.format(PkgBenchmark.date(r), "yyyy-mm-dd HHMMSS") |
142 file_path = joinpath(results_dir, dt*".html") | 142 |
143 if isnothing(name) | |
144 file_path = joinpath(results_dir, dt*".html") | |
145 else | |
146 file_path = joinpath(results_dir, dt*" "*name*".html") | |
147 end | |
143 | 148 |
144 open(file_path, "w") do io | 149 open(file_path, "w") do io |
145 write_result_html(io, r) | 150 write_result_html(io, r) |
146 end | 151 end |
147 | 152 |
151 | 156 |
152 PkgBenchmark.date(j::PkgBenchmark.BenchmarkJudgement) = PkgBenchmark.date(PkgBenchmark.target_result(j)) | 157 PkgBenchmark.date(j::PkgBenchmark.BenchmarkJudgement) = PkgBenchmark.date(PkgBenchmark.target_result(j)) |
153 | 158 |
154 | 159 |
155 function hg_id() | 160 function hg_id() |
156 cmd = Cmd(`hg id`, dir=sbplib_root) | 161 cmd = Cmd(`hg id`, dir=diffinitive_root) |
157 return readchomp(addenv(cmd, "HGPLAIN"=>"")) | 162 return readchomp(addenv(cmd, "HGPLAIN"=>"")) |
158 end | 163 end |
159 | 164 |
160 function hg_rev() | 165 function hg_rev() |
161 cmd = Cmd(`hg id -i`, dir=sbplib_root) | 166 cmd = Cmd(`hg id -i`, dir=diffinitive_root) |
162 return readchomp(addenv(cmd, "HGPLAIN"=>"")) | 167 return readchomp(addenv(cmd, "HGPLAIN"=>"")) |
163 end | 168 end |
164 | 169 |
165 function hg_update(rev) | 170 function hg_update(rev) |
166 cmd = Cmd(`hg update --check -r $rev`, dir=sbplib_root) | 171 cmd = Cmd(`hg update --check -r $rev`, dir=diffinitive_root) |
167 run(addenv(cmd, "HGPLAIN"=>"")) | 172 run(addenv(cmd, "HGPLAIN"=>"")) |
168 | 173 |
169 return nothing | 174 return nothing |
170 end | 175 end |
171 | 176 |
175 Make a hg commit with the provided message. If `secret` is true the commit is | 180 Make a hg commit with the provided message. If `secret` is true the commit is |
176 in the secret phase stopping it from being pushed. | 181 in the secret phase stopping it from being pushed. |
177 """ | 182 """ |
178 function hg_commit(msg; secret=false) | 183 function hg_commit(msg; secret=false) |
179 if secret | 184 if secret |
180 cmd = Cmd(`hg commit --verbose --secret --message $msg`, dir=sbplib_root) | 185 cmd = Cmd(`hg commit --verbose --secret --message $msg`, dir=diffinitive_root) |
181 else | 186 else |
182 cmd = Cmd(`hg commit --verbose --message $msg`, dir=sbplib_root) | 187 cmd = Cmd(`hg commit --verbose --message $msg`, dir=diffinitive_root) |
183 end | 188 end |
184 | 189 |
185 out = readchomp(addenv(cmd, "HGPLAIN"=>"")) | 190 out = readchomp(addenv(cmd, "HGPLAIN"=>"")) |
186 | 191 |
187 return only(match(r"committed changeset \d+:([0-9a-z]+)", out)) | 192 return only(match(r"committed changeset \d+:([0-9a-z]+)", out)) |
193 Strips the given commit from the repo. If `keep` is true, the changes of the | 198 Strips the given commit from the repo. If `keep` is true, the changes of the |
194 commit are kept in the working directory. | 199 commit are kept in the working directory. |
195 """ | 200 """ |
196 function hg_strip(rev; keep=false) | 201 function hg_strip(rev; keep=false) |
197 if keep | 202 if keep |
198 cmd = Cmd(`hg --config extensions.strip= strip --keep -r $rev`, dir=sbplib_root) | 203 cmd = Cmd(`hg --config extensions.strip= strip --keep -r $rev`, dir=diffinitive_root) |
199 else | 204 else |
200 cmd = Cmd(`hg --config extensions.strip= strip -r $rev`, dir=sbplib_root) | 205 cmd = Cmd(`hg --config extensions.strip= strip -r $rev`, dir=diffinitive_root) |
201 end | 206 end |
202 | 207 |
203 run(addenv(cmd, "HGPLAIN"=>"")) | 208 run(addenv(cmd, "HGPLAIN"=>"")) |
204 | 209 |
205 return nothing | 210 return nothing |
209 hg_is_dirty() | 214 hg_is_dirty() |
210 | 215 |
211 Return true if the repositopry has uncommited changes. | 216 Return true if the repositopry has uncommited changes. |
212 """ | 217 """ |
213 function hg_is_dirty() | 218 function hg_is_dirty() |
214 cmd = Cmd(`hg identify --id`, dir=sbplib_root) | 219 cmd = Cmd(`hg identify --id`, dir=diffinitive_root) |
215 out = readchomp(addenv(cmd, "HGPLAIN"=>"")) | 220 out = readchomp(addenv(cmd, "HGPLAIN"=>"")) |
216 | 221 |
217 return endswith(out, "+") | 222 return endswith(out, "+") |
218 end | 223 end |
219 | 224 |