Skip to content

Commit

Permalink
Add docs on performance
Browse files Browse the repository at this point in the history
  • Loading branch information
charleskawczynski committed Mar 12, 2021
1 parent 27a9c04 commit a2c01ae
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 9 deletions.
9 changes: 9 additions & 0 deletions docs/make.jl
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
using Documenter, DispatchedTuples

format = Documenter.HTML(
prettyurls = !isempty(get(ENV, "CI", "")),
collapselevel = 1,
)

makedocs(
sitename = "DispatchedTuples.jl",
strict = true,
format = format,
checkdocs = :exports,
clean = true,
doctest = true,
modules = [DispatchedTuples],
pages = Any[
"Home" => "index.md",
"Performance" => "performance.md",
"API" => "api.md",
],
)

Expand Down
8 changes: 8 additions & 0 deletions docs/src/api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# API

```@docs
DispatchedTuples.AbstractDispatchedTuple
DispatchedTuples.DispatchedTuple
DispatchedTuples.DispatchedSet
DispatchedTuples.dispatch
```
9 changes: 0 additions & 9 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,3 @@ dispatch(dtup, Baz()) # returns ()
```

For convenience, `DispatchedTuple` can alternatively take a `Tuple` of two-element `Tuple`s.

## API

```@docs
DispatchedTuples.AbstractDispatchedTuple
DispatchedTuples.DispatchedTuple
DispatchedTuples.DispatchedSet
DispatchedTuples.dispatch
```
63 changes: 63 additions & 0 deletions docs/src/performance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Performance

The performance of `DispatchedTuple`s should scale similar to the performance of ordinary tuples (good with small tuples, but expensive with larger ones).

```@example perf
using DispatchedTuples
using InteractiveUtils
struct Foo end;
struct Bar end;
struct Baz end;
tup = (
Pair(Foo(), 1),
Pair(Bar(), 3),
Pair(Foo(), 2),
)
tupset = (
Pair(Foo(), 1),
Pair(Bar(), 3),
Pair(Baz(), 2),
)
dtup = DispatchedTuple(tup);
dset = DispatchedSet(tupset);
nothing
```

Using `dispatch` on a `DispatchedTuple` is equivalent to hard-coding the intended indexes ahead of time, which means that the LLVM code is concise:

## DispatchedTuple

```@example perf
get_foo_magic(dtup) = (dtup.tup[1][2], dtup.tup[3][2])
@code_typed get_foo_magic(dtup)
```
```@example perf
@code_typed dispatch(dtup, Foo())
```

```@example perf
@code_native get_foo_magic(dtup)
```
```@example perf
@code_native dispatch(dtup, Foo())
```

## DispatchedSet

```@example perf
get_foo_magic(dset) = dset.tup[1][2]
@code_typed get_foo_magic(dset)
```
```@example perf
@code_typed dispatch(dset, Foo())
```

```@example perf
@code_native get_foo_magic(dset)
```
```@example perf
@code_native dispatch(dset, Foo())
```

0 comments on commit a2c01ae

Please sign in to comment.