Skip to content

Commit 0259b2d

Browse files
committed
Add docs script with benchmarks of different computations
1 parent c553fca commit 0259b2d

3 files changed

Lines changed: 103 additions & 1 deletion

File tree

docs/Project.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[deps]
22
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
3+
Chairmarks = "0ca39b1e-fe0b-4e98-acfc-b1656634c4de"
34
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
45
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
56
DocumenterCitations = "daee34ce-89f3-4625-b898-19384cb65244"
@@ -12,7 +13,7 @@ Typstry = "f0ed7684-a786-439e-b1e3-3b82803b501e"
1213
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"
1314

1415
[compat]
15-
ProfileCanvas = "0.1.7"
1616
Documenter = "1"
1717
DocumenterCitations = "1"
18+
ProfileCanvas = "0.1.7"
1819
Typstry = "0.6"

docs/make.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ makedocs(
4747
"caches.md",
4848
"performance_tips.md",
4949
"benchmarks.md",
50+
"sarray-benchmarks.md",
5051
"uncertainty_predictions.md",
5152
"api_reference.md",
5253
],

docs/src/sarray-benchmarks.md

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# StaticArray Benchmarks
2+
3+
We explore the compute time requirements for pose estimation under different configurations:
4+
comparing **3dof vs 6dof**, the impact of **StaticArrays**, and solving with **additional line angle features**.
5+
6+
## Setup
7+
8+
```@example sarray_bench
9+
using RunwayLib, Unitful.DefaultSymbols, Rotations
10+
using StaticArrays, Chairmarks, Printf, Markdown
11+
12+
runway_corners = [
13+
WorldPoint(0.0m, 50m, 0m), # near left
14+
WorldPoint(3000.0m, 50m, 0m), # far left
15+
WorldPoint(3000.0m, -50m, 0m), # far right
16+
WorldPoint(0.0m, -50m, 0m), # near right
17+
]
18+
19+
cam_pos = WorldPoint(-2000.0m, 12m, 150m)
20+
cam_rot = RotZYX(roll=1.5°, pitch=5°, yaw=0°)
21+
22+
true_observations = [project(cam_pos, cam_rot, p) for p in runway_corners]
23+
noisy_observations = [p + ProjectionPoint(2.0*randn(2)px) for p in true_observations]
24+
25+
fmt(t) = @sprintf("%.1f μs", t * 1e6)
26+
speedup(a, b) = @sprintf("%.2f×", a / b)
27+
28+
pf_arr = PointFeatures(runway_corners, noisy_observations)
29+
nothing # hide
30+
```
31+
32+
## 3dof vs 6dof
33+
34+
We first compare the two solver modes using regular `Vector`-backed `PointFeatures`.
35+
36+
```@example sarray_bench
37+
b_6dof = minimum(@be pf_arr estimatepose6dof)
38+
b_3dof = minimum(@be pf_arr estimatepose3dof(_, NO_LINES, cam_rot))
39+
40+
Markdown.parse("""
41+
| | 6dof | 3dof | Speedup |
42+
|:---------------|:----------------|:----------------|:-----------------|
43+
| Regular arrays | $(fmt(b_6dof.time)) | $(fmt(b_3dof.time)) | $(speedup(b_6dof.time, b_3dof.time)) |
44+
""")
45+
```
46+
47+
## Impact of StaticArrays
48+
49+
Wrapping the point features in `SVector` allows the compiler to unroll loops and avoid heap allocations.
50+
51+
```@example sarray_bench
52+
pf_sa = PointFeatures(SVector{4}(runway_corners), SVector{4}(noisy_observations))
53+
54+
b_6dof_sa = minimum(@be pf_sa estimatepose6dof)
55+
b_3dof_sa = minimum(@be pf_sa estimatepose3dof(_, NO_LINES, cam_rot))
56+
57+
Markdown.parse("""
58+
| | 6dof | 3dof | Speedup |
59+
|:-----------------|:----------------|:----------------|:-----------------|
60+
| Regular arrays | $(fmt(b_6dof.time)) | $(fmt(b_3dof.time)) | $(speedup(b_6dof.time, b_3dof.time)) |
61+
| StaticArrays | $(fmt(b_6dof_sa.time)) | $(fmt(b_3dof_sa.time)) | $(speedup(b_6dof_sa.time, b_3dof_sa.time)) |
62+
| SA speedup | $(speedup(b_6dof.time, b_6dof_sa.time)) | $(speedup(b_3dof.time, b_3dof_sa.time)) | |
63+
""")
64+
```
65+
66+
## With line angle features
67+
68+
Adding observed runway edge angles as `LineFeatures` provides additional constraints to the solver.
69+
70+
```@example sarray_bench
71+
line_pts = [
72+
(runway_corners[1], runway_corners[2]),
73+
(runway_corners[3], runway_corners[4]),
74+
]
75+
true_lines = map(line_pts) do (p1, p2)
76+
proj1 = project(cam_pos, cam_rot, p1)
77+
proj2 = project(cam_pos, cam_rot, p2)
78+
getline(proj1, proj2)
79+
end
80+
observed_lines = [
81+
Line(r + 1px*randn(), theta + deg2rad(1°)*randn())
82+
for (; r, theta) in true_lines
83+
]
84+
85+
lf_arr = LineFeatures(line_pts, observed_lines)
86+
lf_sa = LineFeatures(SVector{2}(line_pts), SVector{2}(observed_lines))
87+
88+
bl_6dof = minimum(@be (pf_arr, lf_arr) estimatepose6dof(_...))
89+
bl_3dof = minimum(@be (pf_arr, lf_arr) estimatepose3dof(_..., cam_rot))
90+
bl_6dof_sa = minimum(@be (pf_sa, lf_sa) estimatepose6dof(_...))
91+
bl_3dof_sa = minimum(@be (pf_sa, lf_sa) estimatepose3dof(_..., cam_rot))
92+
93+
Markdown.parse("""
94+
| | 6dof | 3dof | Speedup |
95+
|:-----------------|:----------------|:----------------|:-----------------|
96+
| Regular arrays | $(fmt(bl_6dof.time)) | $(fmt(bl_3dof.time)) | $(speedup(bl_6dof.time, bl_3dof.time)) |
97+
| StaticArrays | $(fmt(bl_6dof_sa.time)) | $(fmt(bl_3dof_sa.time)) | $(speedup(bl_6dof_sa.time, bl_3dof_sa.time)) |
98+
| SA speedup | $(speedup(bl_6dof.time, bl_6dof_sa.time)) | $(speedup(bl_3dof.time, bl_3dof_sa.time)) | |
99+
""")
100+
```

0 commit comments

Comments
 (0)