Commit 7ad87a3
perf(distance): use ** operator and drop * 1.0 idiom
`rssi * 1.0 / power` (Python 2 era idiom) is identical to `rssi / power`
in Python 3 since `/` already produces float; the extra multiplication
adds ~0.5µs per call. `pow(x, n)` goes through the builtin dispatch path
while `x ** n` uses the faster operator path — measurable on both the
integer-exponent (`**10`) and float-exponent (`**7.7095`) cases.
Microbench (CPython 3.13, 2M iters):
close (ratio<1): 0.84s → 0.57s (-31%)
near (ratio≈1): 0.59s → 0.47s (-21%)
far (ratio>1): 0.71s → 0.57s (-19%)
zero (early): unchanged
Output identical for all existing pinned test values.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 95b0c33 commit 7ad87a3
3 files changed
Lines changed: 31 additions & 5 deletions
File tree
- bench
- src/bluetooth_data_tools
- tests/benchmarks
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
3 | 1 | | |
4 | 2 | | |
5 | 3 | | |
6 | 4 | | |
7 | 5 | | |
8 | 6 | | |
9 | 7 | | |
10 | | - | |
11 | | - | |
| 8 | + | |
| 9 | + | |
12 | 10 | | |
13 | | - | |
| 11 | + | |
14 | 12 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
0 commit comments