Text width measurement benchmark for Shields.io badge rendering —
commit 0c49f70
pretext measures text using actual font outlines via the Canvas API (@napi-rs/canvas
Skia backend), while anafanafo uses pre-computed character-width lookup
tables. The table below shows measured widths and their differences.
MIT), typical badges, long sentences, full alphabet,
digits, and special characters
11px Verdana,
bold 10px Verdana, bold 11px Helvetica
measureText() via @napi-rs/canvas + Skia —
sub-pixel precision
Uses pre-computed character-width data stored as JSON arrays, one per supported font. Each character's width is looked up and summed to estimate the total string width. Fast but limited to the bundled font set, and returns rounded integer values.
A text layout library that delegates measurement to the Canvas API. In the
Shields.io server environment, @napi-rs/canvas provides an
OffscreenCanvas polyfill backed by Skia, giving access to
real font metrics. Returns floating-point widths with sub-pixel precision.
| anafanafo | pretext | |
|---|---|---|
| Speed | ~350 ms / 130k calls | ~800 ms / 130k calls |
| Per-call cost | ~0.003 ms | ~0.006 ms |
| Precision | Integer pixels (rounded) | Sub-pixel (float) |
| Font support | 4 bundled font/size combos | Any system / loaded font |
| Dependencies | None (pure JS + data) | @napi-rs/canvas (native addon) |
| Accuracy | Approximation from metrics tables | Real font shaping via Skia |
| Bundle size | ~45 KB (data tables) | ~15 KB (JS) + native binary |