Skip to main content

Fonts

Drawing text.

DejaVuSans.ttf, libstb's Font against Pillow's FreeType binding on its basic layout engine (so Pillow is not charged for shaping, which stb_truetype does not do). The two rasterize differently, so this compares speed only. stb_truetype has no security guarantee on untrusted fonts; FreeType is hardened. No speed number captures that.

open: load the font file, get a font object

On average (E ⁣[tlibstbtPillow]\mathbb{E}\!\left[\dfrac{t_{\text{libstb}}}{t_{\text{Pillow}}}\right], the mean of each case's own ratio): 0.48×; below 1 means libstb took less time.

Time per call (lower is better)

See the numbers
CaselibstbPillowlibstb / Pillow
16px24.1 µs66.2 µs0.36×
32px32.7 µs67.4 µs0.48×
64px32.2 µs55.6 µs0.58×

measure: how big would this text be

On average (E ⁣[tlibstbtPillow]\mathbb{E}\!\left[\dfrac{t_{\text{libstb}}}{t_{\text{Pillow}}}\right], the mean of each case's own ratio): 0.07×; below 1 means libstb took less time.

Time per call (lower is better)

See the numbers
CaselibstbPillowlibstb / Pillow
short 16px9.9 µs83.1 µs0.12×
short 32px9.7 µs84.0 µs0.12×
short 64px7.5 µs85.4 µs0.09×
paragraph 16px16.9 µs814.8 µs0.02×
paragraph 32px20.7 µs775.3 µs0.03×
paragraph 64px20.7 µs788.0 µs0.03×

render: text in, coverage bitmap out (measure + allocate + draw)

On average (E ⁣[tlibstbtPillow]\mathbb{E}\!\left[\dfrac{t_{\text{libstb}}}{t_{\text{Pillow}}}\right], the mean of each case's own ratio): 0.10×; below 1 means libstb took less time.

Time per call (lower is better)

See the numbers
CaselibstbPillowlibstb / Pillow
short 16px35.4 µs277.8 µs0.13×
short 32px41.5 µs293.4 µs0.14×
short 64px61.6 µs366.1 µs0.17×
paragraph 16px101.9 µs2.57 ms0.04×
paragraph 32px143.7 µs2.91 ms0.05×
paragraph 64px244.5 µs3.70 ms0.07×