Skip to content

Commit 58cf141

Browse files
FelixBenninggdalle
andauthored
Add Example Code to Common Workflow (#290)
* common workflow with examples * use old_results variable Co-authored-by: Guillaume Dalle <[email protected]> * use old_results variable 2 Co-authored-by: Guillaume Dalle <[email protected]> * use old_results variable 3 Co-authored-by: Guillaume Dalle <[email protected]> * Add docstrings to load and save + tweak manual --------- Co-authored-by: Guillaume Dalle <[email protected]>
1 parent c0a7157 commit 58cf141

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

docs/src/manual.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -888,10 +888,23 @@ A common workflow used in BenchmarkTools is the following:
888888

889889
1. Start a Julia session
890890
2. Execute a benchmark suite using an old version of your package
891-
3. Save the results somehow (e.g. in a JSON file)
891+
```julia
892+
old_results = run(suite, verbose = true)
893+
```
894+
4. Save the results somehow (e.g. in a JSON file)
895+
```julia
896+
BenchmarkTools.save("old_results.json", old_results)
897+
```
892898
4. Start a new Julia session
893899
5. Execute a benchmark suite using a new version of your package
894-
6. Compare the new results with the results saved in step 3 to determine regression status
900+
```julia
901+
results = run(suite, verbose = true)
902+
```
903+
7. Compare the new results with the results saved in step 3 to determine regression status
904+
```julia
905+
old_results = BenchmarkTools.load("old_results.json")
906+
BenchmarkTools.judge(minimum(results), minimum(old_results))
907+
```
895908

896909
There are a couple of problems with this workflow, and all of which revolve around parameter tuning (which would occur during steps 2 and 5):
897910

docs/src/reference.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@ Private = false
77

88
```@docs
99
Base.run
10+
BenchmarkTools.save
11+
BenchmarkTools.load
1012
```

src/serialization.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ function badext(filename)
8989
throw(ArgumentError(msg))
9090
end
9191

92+
"""
93+
BenchmarkTools.save(filename, args...)
94+
95+
Save serialized benchmarking objects (e.g. results or parameters) to a JSON file.
96+
"""
9297
function save(filename::AbstractString, args...)
9398
endswith(filename, ".json") || badext(filename)
9499
open(filename, "w") do io
@@ -116,6 +121,11 @@ function save(io::IO, args...)
116121
return JSON.print(io, [VERSIONS, goodargs])
117122
end
118123

124+
"""
125+
BenchmarkTools.load(filename)
126+
127+
Load serialized benchmarking objects (e.g. results or parameters) from a JSON file.
128+
"""
119129
function load(filename::AbstractString, args...)
120130
endswith(filename, ".json") || badext(filename)
121131
open(filename, "r") do f

0 commit comments

Comments
 (0)