Measure performance
lucent bench times each case natively and as JavaScript, and shows the speedup.
import { pathLength, spiralLength } from "./path.lucent";
const points = Array.from({ length: 1000 }, (_, i) => ({ x: Math.cos(i / 10) * i, y: Math.sin(i / 10) * i,}));
export default { objects: () => pathLength(points), native: () => spiralLength(1000),};npx lucent benchCASE JS LUCENT SPEEDUPsrc/path.bench.tsobjects 54.0 µs 67.1 µs 0.8xnative 90.9 µs 7.9 µs 11.5x
per call, best of 5 rounds; desktop Hermes, so devices differ- A
*.bench.tsfile next to your modules exports an object of cases: functions without arguments. - Each case runs as your compiled module and as the same TypeScript run as JavaScript, in a desktop Hermes. The results must be equal.
- A speedup below 1x usually means the call copies more data than it computes on. Design the boundary first explains why.
- Absolute times differ on devices; the comparison carries over. For numbers on a device, time the call in the app's release build.