Skip to content

chore: reorganize timing script as benchmarks/benchmark_smtb.py - #229

Open
petercorke wants to merge 3 commits into
rai-opensource:masterfrom
petercorke:chore/reorganize-timing-script
Open

petercorke wants to merge 3 commits into
rai-opensource:masterfrom
petercorke:chore/reorganize-timing-script

Conversation

@petercorke

Copy link
Copy Markdown
Collaborator

Reworks the ad hoc micro-benchmark script (spatialmath/timing.py) into something useful as a reference. Three commits, best reviewed one at a time:

  1. Reorganize: split into per-category tables (SO(3)/SE(3) base, SE3, quaternion base, UnitQuaternion, twist/exp-map base, Twist3, NumPy baseline). Fixed a corrupted header and mislabelled rows, added coverage for RPY/Euler/quaternion conversions and SE3 @ SE3, collapsed the timeit boilerplate, and switched to min-of-5-repeats to suppress GC/scheduler noise.
  2. Move: spatialmath/timing.py to benchmarks/benchmark_smtb.py (pure rename). It's a dev tool, not library API, so it no longer ships in the wheel. Nothing in the repo referenced the old path.
  3. Header: print CPU, OS, Python, numpy and spatialmath versions and the timing settings before the results, so pasted tables are self-describing.

Run with python benchmarks/benchmark_smtb.py. Checked on Python 3.14 / macOS (Apple M1).

🤖 Generated with Claude Code

petercorke and others added 3 commits September 18, 2026 20:46
…oilerplate

Reworks the ad hoc, partly-commented-out timing script (which had been
manually re-enabled with a couple of tweaks, uncommitted, sitting in
the working tree across several perf PRs this session) into something
that's actually a useful reference:

- Split into separate tables, one per category (SO(3)/SE(3) base
  functions, SE3 class, quaternion base functions, UnitQuaternion
  class, twist/exponential-map base functions, Twist3 class, NumPy
  baseline), printed with a plain header between each. Base-level
  (module functions on raw arrays) and class-level (constructors/
  operators/properties on instances) are now consistently separated
  throughout, rather than mixed together - the old Twist3 section in
  particular had base functions (skew, trlog, trexp, rodrigues, ...)
  interleaved with class-level operations.
- Fixed a corrupted docstring header left over from a bad find/replace
  on upstream (`# -*- coding", t)` / `@author", t)`), unrelated to any
  of this but noticed while rewriting the file.
- Fixed mislabelled/ambiguous rows: `inner()` -> `np.inner(s, s).sum()`,
  bare `cross()` -> `base.cross(a, b)` (paired explicitly against
  `np.cross(a, b)`), and rows comparing decomposed-(R,t) vs full-4x4
  composition that had identical labels for different code paths.
- Added coverage that didn't exist before: SE3 <-> RPY, SE3 <-> Euler,
  SE3 -> UnitQuaternion, UnitQuaternion <-> rotation matrix,
  UnitQuaternion -> SE3, and SE3 @ SE3 (normalized compose) alongside
  SE3 * SE3.
- Collapsed the `timeit.timeit(...); result(...)` two-line-per-test
  boilerplate into a single `timeit(stmt, label, setup)` call (module
  import aliased to `_timeit` to free up the name). Replaced the
  single `timeit.timeit(..., number=N)` run per test with
  `min(timeit.repeat(..., number=N, repeat=REPEATS))` - a single long
  run doesn't distinguish real cost from a GC pause or OS scheduling
  hiccup, min-of-repeats does. N dropped from 100_000 to 10_000 (an
  arbitrary starting point either way) since the repeats now do the
  work of suppressing noise that a bigger N was being used for.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
The script is a dev tool, not library API; move it out of the installed
package so it no longer ships in the wheel.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
CPU, OS, Python, numpy and spatialmath versions and the timing settings,
so a pasted table is self-describing. Modeled on RTB's rne_speed.py.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants