From cbddb0f25bf9891b1e801671da39d375e9d70591 Mon Sep 17 00:00:00 2001 From: Charles Kawczynski Date: Wed, 17 Mar 2021 11:49:55 -0700 Subject: [PATCH] Add perf timings in docs --- docs/make.jl | 3 ++- docs/src/perf.jl | 48 ++++++++++++++++++++++++++++++++++ docs/src/performance.md | 2 +- docs/src/performance_timing.md | 8 ++++++ 4 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 docs/src/perf.jl create mode 100644 docs/src/performance_timing.md diff --git a/docs/make.jl b/docs/make.jl index 8a4a1ff..37727ee 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -15,7 +15,8 @@ makedocs( modules = [DispatchedTuples], pages = Any[ "Home" => "index.md", - "Performance" => "performance.md", + "Performance introspection" => "performance.md", + "Performance timing" => "performance_timing.md", "API" => "api.md", ], ) diff --git a/docs/src/perf.jl b/docs/src/perf.jl new file mode 100644 index 0000000..7d69917 --- /dev/null +++ b/docs/src/perf.jl @@ -0,0 +1,48 @@ +using DispatchedTuples +using BenchmarkTools + +# (N, N_buf) are low for quick doc builds +# (N, N_buf) = (5, 3) is reasonable +N = 0 +N_buf = 1 + +foo(i) = Symbol(:Foo, i) +expr(i) = :(struct $(foo(i)) end) +for i in 1:N+N_buf + eval(expr(i)) +end + +fooinst(i::Int) = eval(:($(foo(i))))() + +footup(n::Int) = ntuple(n) do i + (fooinst(i), i) +end + +function perf_dt(N, N_buf) + println("********* DispatchedTuple") + for n in N_buf:N+N_buf + println("--- n = $n") + tup = footup(n) + @btime footup($n) + + dtup = DispatchedTuple(tup) + @btime DispatchedTuple($tup) + # @btime $dtup[Foo3()] # always results in 0.028 ns (0 allocations: 0 bytes) + end +end + +function perf_ds(N, N_buf) + println("********* DispatchedSet") + for n in N_buf:N+N_buf + println("--- n = $n") + tup = footup(n) + @btime footup($n) + + dtup = DispatchedSet(tup) + @btime DispatchedSet($tup) + # @btime $dtup[Foo3()] # always results in 0.028 ns (0 allocations: 0 bytes) + end +end + +perf_dt(N, N_buf) +perf_ds(N, N_buf) diff --git a/docs/src/performance.md b/docs/src/performance.md index 1fad614..c1d542b 100644 --- a/docs/src/performance.md +++ b/docs/src/performance.md @@ -1,4 +1,4 @@ -# Performance +# Performance introspection The performance of `DispatchedTuple`s should scale similar to the performance of ordinary tuples (good with small tuples, but expensive with larger ones). diff --git a/docs/src/performance_timing.md b/docs/src/performance_timing.md new file mode 100644 index 0000000..e72d98c --- /dev/null +++ b/docs/src/performance_timing.md @@ -0,0 +1,8 @@ +# Performance timing + +See the `perf.jl` file for adjusting / experimenting with timings. Note that the output is limited for quick doc builds. + +```@example perf +include("perf.jl") +nothing +```