This is a small, objective experiment that compares three TOON libraries (toonify, toons, toon-formatter) for payload size, token counts, and dumps/loads performance. It also validates typed round-trips with Pydantic. It runs locally with no network calls.
- Bytes and token counts for a small RAG-style context payload.
- Bytes and token counts for a small answer payload.
- Dumps/loads timing across toonify, toons, and toon-formatter.
- Typed validation for TOON outputs using Pydantic models.
Install dependencies:
python -m pip install -r requirements.txtpython run.py- Token counts use
tiktokenwithgpt-5.2as the reference tokenizer. ChangeMODEL_NAMEinrun.pyif you want a different tokenizer. - Iteration count is controlled by
ITERATIONSinrun.py. - TOON output uses short keys to reflect the common production pattern where key shortening compounds savings.
- Cost estimation uses the
PRICINGtable inrun.py(USD per 1M tokens).