We Measured the LLM Token Cost of 4 Markup Formats: TSX Costs 94% More Than Pug
We measured four markup formats with one tokenizer. TSX costs 94% more than Pug, and the attribute everyone blames for it turns out to cost nothing.
The study compares four markup formats (HTML, Pug, JSX, and TSX) for token costs. Pug leads all samples with the cheapest markup, while HTML costs 94% more than Pug on average. JSX and TSX fall at the opposite end, with JSX costing three times Pug for small samples and about 1.9× for larger ones. The cost differences stem from HTML's structural costs like closing tags (48 tokens in the article sample) and JSX/TSX's JavaScript integration.
Pug avoids these costs entirely by using indentation instead of closing tags and a simpler attribute syntax. The analysis reveals that while markup costs vary widely, consistency in ranking across samples suggests syntax plays a larger role than example choice.
Written by urgent.news from HackerNoon's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.