Skip to content
metonymPublic

About

Fast profiling and benchmarking for Bun.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

182 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ostia

Fast profiling and benchmarking for Bun.

ostia times commands and functions on Bun, then tells you whether a change made them slower: it compares two runs with statistics that account for how noisy your machine is, and ostia ab confirms a regression in fresh processes before it reports one. The CLI and the library do the same things, and every result is one JSON document.

// suite.ts
import { group, task } from "ostia"
import { dedupe } from "./dedupe.ts"

const ids = Array.from({ length: 2_000 }, (_, i) => (i * 7919) % 500)

group("ids", () => {
  task("dedupe 2,000", () => dedupe(ids))
  task("sort 2,000", () => ids.toSorted((a, b) => a - b))
})
ostia bench suite.ts as it runs: a progress bar at task 1 of 2, dedupe 2,000, then at 2 of 2, sort 2,000, then the result: fastest dedupe 2,000 at 18.4 µs, sort 2,000 at 97.9 µs, 5.31 times as long, each with its noise and instructions per call

It tells you when a change made something slower. Rewrite dedupe from a Set to indexOf, and ostia ab runs your suite against HEAD and the working tree in alternating batches in one process:

ostia ab suite.ts after dedupe moved from a Set to indexOf: fail, dedupe 2,000 regressed +207%, confirmed by repeats in fresh processes, sort 2,000 unchanged, ending with the command to profile it

Exit 1 on a regression, so CI can gate on it. ostia time does the same for whole commands:

ostia time on gzip -1 and gzip -9 of the same file: gzip -1 is 12.9 times faster, with each command's noise and user and system time ostia has no dependencies and needs Bun ≥ 1.4.

Quick start

bun add -d ostia

Write a suite with group() and task(), as above, then:

ostia bench suite.ts      # time each task
ostia ab suite.ts         # compare the working tree with HEAD

Exit status: 0 pass, 1 a regression (ab, compare, ci), 2 an error.

Common tasks

# Time two commands against each other
ostia time "bun a.ts" "bun b.ts"

# Compare two saved runs
ostia compare before.json after.json

# Save a baseline on known-good code, then gate CI on it
ostia baseline save
ostia ci

# Capture a CPU profile while timing
ostia time "bun a.ts" --cpu

# One JSON object per line, for a script or an agent
ostia bench suite.ts --format events

These docs ship in the package, at node_modules/ostia/docs/.

From code

const doc = await time({
  commands: ["bun a.ts", { command: "bun b.ts", label: "b", prepare: "rm -rf dist" }],
  samples: 20,
  cpu: true,
})

group("parse", () => {
  sweep({ size: range(100, 10_000) }, ({ size }) => {
    const input = buildInput(size) // unmeasured setup, once per point
    task("parse", () => parse(input), { isolate: true })
  })
})

const result = compareDocuments(await loadDocument("before.json"), doc)
if (result.summary.verdict === "fail") process.exitCode = 1

const { text } = await renderers.markdown.render(doc, {})

Docs

About

Fast profiling and benchmarking for Bun.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages