|
| 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