measure-fn: see where the time goes
Contents
Repository: https://github.com/7flash/measure-fn · Package: bun add measure-fn or npm install measure-fn (version 6.0.0) · License: MIT · Dependencies: none
measure-fn wraps a named operation, times it and prints one compact line when it starts and one when it ends. It tracks nesting, so a request shows its database calls underneath it. The wrapped function returns its normal result, and errors are logged and then rethrown unchanged.
import { createMeasure } from "measure-fn";
const api = createMeasure("api");
const count = await api.root("GET /users", async () => {
const users = await api("load users", async () => [{ id: 1 }, { id: 2 }]);
return await api("count users", async () => users.length);
});
[api] a → GET /users
[api] a-a → load users
[api] a-a ✓ 0.40ms → [{"id":1},{"id":2}]
[api] a-b → count users
[api] a-b ✓ 0.08ms → 2
[api] a ✓ 0.95ms → 2
What you get#
- Nesting that survives
await. Node.js and Bun useAsyncLocalStorage, so a step inside a request stays a child of that request. - Sync and async versions:
api.sync(...)for synchronous code, andwrap()for functions, including generators. - Retries, timeouts and fallbacks.
.retry()honoursretryIf, andcatchgives a fallback value. - Quiet or filtered. Silent mode, levels such as
errors(only failures and slow calls) and per-scope filters. - Safe logs. Secrets in logged URLs are redacted.
- Works in browsers, with a separate build.
Where it runs#
measure-fn is the logging layer of the other two webstack libraries:
- every request in TradJS apps;
- the database calls in sqlite-zod-orm.
Proof it works#
- A 418-case behaviour matrix covers every API path, in sync and async, success and error, with nesting, retries, timeouts, silent and filtered modes. It found one real bug: turning on silent mode during a span dropped that span's end line. The fix is on the next version's branch.
- 524 tests pass under Bun.
- Next: a benchmark of the per-call cost when logging is on, off or filtered, and a real-run check under HTTP load. The load check confirms that every started span gets its end line, that ids stay unique and that nesting stays intact. The next version (6.1) is released only after that benchmark shows a clean result on a quiet machine.
Links#
- Source and README (with an upgrade guide from 3.x, 4.x and 5.x): https://github.com/7flash/measure-fn
- Report on the webstack real-run checks: https://diadem.fun/coin/berlian/webstack-real-run-report
One person, many companies, one coin. Every project I build sends a share of its revenue back to buy $BERLIAN on the open market, and every buy is published with its transaction.
More from Gor Berlian
CNC foam-panel router: assembly in 42 pictures
42 steps, each with a picture of the whole machine and a close-up of the parts added. English and Indonesian.
1,008,000 gravity
TradJS 4.7.0 in testing: 1,902 tests and 118 browser steps on the development branch
Repository: https://github.com/7flash/TradJS · On npm today: tradjs 4.6.5 · Tested here: the 4.7.0 development branch, 19 November 2026, Bun 1.4.3 on Windows 11.

The Plain Web Stack
TradJS, sqlite-zod-orm and measure-fn: what they are, how they are tested, and when to use them. A short book, November 2026.
