Skip to content

Commit a1dfaf1

Browse files
authored
Better printing of benchmarks (#158)
1 parent 77704d3 commit a1dfaf1

5 files changed

Lines changed: 30 additions & 18 deletions

File tree

.github/workflows/CI.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ jobs:
4848
- name: Install dependencies (replaces buildpkg)
4949
run: julia --project=${{ matrix.pkg.dir}}/ -e '
5050
using Pkg;
51+
Pkg.Registry.update();
5152
if "${{ matrix.pkg.name}}" == "DifferentiationInterfaceTest";
5253
Pkg.develop(PackageSpec(path="./DifferentiationInterface"));
5354
end;
@@ -88,6 +89,7 @@ jobs:
8889
- name: Install dependencies
8990
run: julia --project=${{ matrix.pkg.dir}}/docs/ -e '
9091
using Pkg;
92+
Pkg.Registry.update();
9193
if "${{ matrix.pkg.name}}" == "DifferentiationInterface";
9294
Pkg.develop(PackageSpec(path="./DifferentiationInterface"));
9395
else;

DifferentiationInterfaceTest/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
1919

2020
[compat]
2121
ADTypes = "0.2.7"
22-
Chairmarks = "1.2"
22+
Chairmarks = "1.2.1"
2323
ComponentArrays = "0.15"
2424
DocStringExtensions = "0.9"
2525
JET = "0.8"

DifferentiationInterfaceTest/docs/Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ Enzyme = "7da242da-08ed-463a-9acd-ee780be4f1d9"
88
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
99
Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a"
1010
PrettyTables = "08abe8d2-0d0c-5749-adfa-8a2ac140af0d"
11+
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"

DifferentiationInterfaceTest/docs/src/tutorial.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ We present a typical workflow with DifferentiationInterfaceTest.jl, building on
99
```@repl tuto
1010
using DifferentiationInterface, DifferentiationInterfaceTest
1111
import ForwardDiff, Enzyme
12-
import DataFrames
12+
import DataFrames, Markdown, PrettyTables, Printf
1313
```
1414

1515
## Introduction
@@ -84,6 +84,15 @@ Here's what the resulting `DataFrame` looks like with all its columns.
8484
Note that we only compare (possibly) in-place operators, because they are always more efficient.
8585

8686
```@example tuto
87-
import Markdown, PrettyTables # hide
88-
Markdown.parse(PrettyTables.pretty_table(String, df; backend=Val(:markdown), header=names(df))) # hide
87+
function formatter(v, i, j)
88+
if j in (14, 15) # time, bytes
89+
return Printf.@sprintf("%.1e", v)
90+
elseif j == 16 # allocs
91+
return Printf.@sprintf("%.1f", v)
92+
else
93+
return v
94+
end
95+
end
96+
table = PrettyTables.pretty_table(String, df; backend=Val(:markdown), header=names(df), formatters=formatter)
97+
Markdown.parse(table) # hide
8998
```

DifferentiationInterfaceTest/src/tests/benchmark.jl

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ $(TYPEDFIELDS)
5050
output_size::Tuple
5151
calls::Int
5252
samples::Int
53+
evals::Int
5354
time::Float64
5455
bytes::Float64
5556
allocs::Float64
5657
compile_fraction::Float64
5758
gc_fraction::Float64
58-
evals::Float64
5959
end
6060

6161
function record!(
@@ -80,12 +80,12 @@ function record!(
8080
output_size=size(scenario.y),
8181
calls=calls,
8282
samples=length(bench.samples),
83+
evals=Int(bench_min.evals),
8384
time=bench_min.time,
8485
bytes=bench_min.bytes,
8586
allocs=bench_min.allocs,
8687
compile_fraction=bench_min.compile_fraction,
8788
gc_fraction=bench_min.gc_fraction,
88-
evals=bench_min.evals,
8989
)
9090
return push!(data, row)
9191
end
@@ -98,7 +98,7 @@ function run_benchmark!(
9898
(; f, x, y, dx) = deepcopy(scen)
9999
# benchmark
100100
extras = prepare_pushforward(f, ba, x)
101-
bench0 = @be prepare_pushforward(f, ba, x) evals = 1 samples = 2
101+
bench0 = @be prepare_pushforward(f, ba, x) evals = 1 samples = 1
102102
bench1 = @be mysimilar(y) value_and_pushforward!!(f, _, ba, x, dx, extras)
103103
bench2 = @be mysimilar(y) pushforward!!(f, _, ba, x, dx, extras)
104104
# count
@@ -123,7 +123,7 @@ function run_benchmark!(
123123
f! = f
124124
# benchmark
125125
extras = prepare_pushforward(f!, ba, y, x)
126-
bench0 = @be prepare_pushforward(f!, ba, y, x) evals = 1 samples = 2
126+
bench0 = @be prepare_pushforward(f!, ba, y, x) evals = 1 samples = 1
127127
bench1 = @be (mysimilar(y), mysimilar(y)) value_and_pushforward!!(
128128
f!, _[1], _[2], ba, x, dx, extras
129129
)
@@ -153,7 +153,7 @@ function run_benchmark!(
153153
(; f, x, y, dy) = deepcopy(scen)
154154
# benchmark
155155
extras = prepare_pullback(f, ba, x)
156-
bench0 = @be prepare_pullback(f, ba, x) evals = 1 samples = 2
156+
bench0 = @be prepare_pullback(f, ba, x) evals = 1 samples = 1
157157
bench1 = @be mysimilar(x) value_and_pullback!!(f, _, ba, x, dy, extras)
158158
bench2 = @be mysimilar(x) pullback!!(f, _, ba, x, dy, extras)
159159
bench3 = @be value_and_pullback!!_split(f, ba, x, extras)
@@ -188,7 +188,7 @@ function run_benchmark!(
188188
f! = f
189189
# benchmark
190190
extras = prepare_pullback(f!, ba, y, x)
191-
bench0 = @be prepare_pullback(f!, ba, y, x) evals = 1 samples = 2
191+
bench0 = @be prepare_pullback(f!, ba, y, x) evals = 1 samples = 1
192192
bench1 = @be (mysimilar(y), mysimilar(x)) value_and_pullback!!(
193193
f!, _[1], _[2], ba, x, dy, extras
194194
)
@@ -216,7 +216,7 @@ function run_benchmark!(
216216
(; f, x, y) = deepcopy(scen)
217217
# benchmark
218218
extras = prepare_derivative(f, ba, x)
219-
bench0 = @be prepare_derivative(f, ba, x) evals = 1 samples = 2
219+
bench0 = @be prepare_derivative(f, ba, x) evals = 1 samples = 1
220220
bench1 = @be mysimilar(y) value_and_derivative!!(f, _, ba, x, extras)
221221
bench2 = @be mysimilar(y) derivative!!(f, _, ba, x, extras)
222222
# count
@@ -241,7 +241,7 @@ function run_benchmark!(
241241
f! = f
242242
# benchmark
243243
extras = prepare_derivative(f!, ba, y, x)
244-
bench0 = @be prepare_derivative(f!, ba, y, x) evals = 1 samples = 2
244+
bench0 = @be prepare_derivative(f!, ba, y, x) evals = 1 samples = 1
245245
bench1 = @be (mysimilar(y), mysimilar(y)) value_and_derivative!!(
246246
f!, _[1], _[2], ba, x, extras
247247
)
@@ -265,7 +265,7 @@ function run_benchmark!(
265265
(; f, x) = deepcopy(scen)
266266
# benchmark
267267
extras = prepare_gradient(f, ba, x)
268-
bench0 = @be prepare_gradient(f, ba, x) evals = 1 samples = 2
268+
bench0 = @be prepare_gradient(f, ba, x) evals = 1 samples = 1
269269
bench1 = @be mysimilar(x) value_and_gradient!!(f, _, ba, x, extras)
270270
bench2 = @be mysimilar(x) gradient!!(f, _, ba, x, extras)
271271
# count
@@ -292,7 +292,7 @@ function run_benchmark!(
292292
jac_template = Matrix{eltype(y)}(undef, length(y), length(x))
293293
# benchmark
294294
extras = prepare_jacobian(f, ba, x)
295-
bench0 = @be prepare_jacobian(f, ba, x) evals = 1 samples = 2
295+
bench0 = @be prepare_jacobian(f, ba, x) evals = 1 samples = 1
296296
bench1 = @be mysimilar(jac_template) value_and_jacobian!!(f, _, ba, x, extras)
297297
bench2 = @be mysimilar(jac_template) jacobian!!(f, _, ba, x, extras)
298298
# count
@@ -318,7 +318,7 @@ function run_benchmark!(
318318
jac_template = Matrix{eltype(y)}(undef, length(y), length(x))
319319
# benchmark
320320
extras = prepare_jacobian(f!, ba, y, x)
321-
bench0 = @be prepare_jacobian(f!, ba, y, x) evals = 1 samples = 2
321+
bench0 = @be prepare_jacobian(f!, ba, y, x) evals = 1 samples = 1
322322
bench1 = @be (mysimilar(y), mysimilar(jac_template)) value_and_jacobian!!(
323323
f!, _[1], _[2], ba, x, extras
324324
)
@@ -344,7 +344,7 @@ function run_benchmark!(
344344
(; f, x, y) = deepcopy(scen)
345345
# benchmark
346346
extras = prepare_second_derivative(f, ba, x)
347-
bench0 = @be prepare_second_derivative(f, ba, x) evals = 1 samples = 2
347+
bench0 = @be prepare_second_derivative(f, ba, x) evals = 1 samples = 1
348348
bench1 = @be mysimilar(y) second_derivative!!(f, _, ba, x, extras)
349349
# count
350350
cc = CallCounter(f)
@@ -366,7 +366,7 @@ function run_benchmark!(
366366
(; f, x, y, dx) = deepcopy(scen)
367367
# benchmark
368368
extras = prepare_hvp(f, ba, x, dx)
369-
bench0 = @be prepare_hvp(f, ba, x, dx) evals = 1 samples = 2
369+
bench0 = @be prepare_hvp(f, ba, x, dx) evals = 1 samples = 1
370370
bench1 = @be mysimilar(x) hvp!!(f, _, ba, x, dx, extras)
371371
# count
372372
cc = CallCounter(f)
@@ -389,7 +389,7 @@ function run_benchmark!(
389389
hess_template = Matrix{typeof(y)}(undef, length(x), length(x))
390390
# benchmark
391391
extras = prepare_hessian(f, ba, x)
392-
bench0 = @be prepare_hessian(f, ba, x) evals = 1 samples = 2
392+
bench0 = @be prepare_hessian(f, ba, x) evals = 1 samples = 1
393393
bench1 = @be mysimilar(hess_template) hessian!!(f, _, ba, x, extras)
394394
# count
395395
cc = CallCounter(f)

0 commit comments

Comments
 (0)