TokenSave Data · Dataset
Python vs Java vs Go vs C: how many tokens the same code costs
The same two programs cost 809 GPT tokens in Python and 1,536 in C (+90%). Python and Ruby were the cheapest languages on every tokenizer we tested; Go and C were the most expensive. Claude 5.5 needed 43% to 59% more tokens than GPT for the same code.
Measured 2026-10-18 · 10 languages · 2 programs · 4 tokenizers · License CC BY 4.0 · Related: token cost by data format
DOI 10.5281/zenodo.23446563 · Also on Hugging Face · Kaggle · GitHub
Key findings
- Python and Ruby are the cheapest. Both programs together cost 809 GPT tokens in Python and 819 in Ruby. JavaScript needs +20%, Java +50%, Go +68% and C +90%.
- The ranking holds on every tokenizer. Python and Ruby stay at the top and Go and C at the bottom on Claude 5.5, Claude Haiku 4.5, Gemini and GPT alike.
- Claude 5.5 costs 43% to 59% more than GPT for the same code. The gap is largest for Java (+59%). Gemini sits between them at 12% to 25% more than GPT.
- Types add tokens. TypeScript needs 11% more GPT tokens than the same JavaScript.
- File size is a rough guide only. Java has the most characters (5,101), but Go and C need more tokens. Characters and lines do not map neatly onto tokens.
All 10 languages
Tokens for both programs together, with the difference versus Python on the same tokenizer in brackets. Per-program counts are in the CSV.
| Language | Lines | Claude Opus/Sonnet 5.5 | Claude Haiku 4.5 | Gemini 3.x | GPT o200k |
|---|---|---|---|---|---|
| Python | 107 | 1,176 (±0%) | 970 (±0%) | 963 (±0%) | 809 (±0%) |
| Ruby | 109 | 1,181 (±0%) | 961 (-1%) | 944 (-2%) | 819 (+1%) |
| JavaScript | 126 | 1,442 (+23%) | 1,199 (+24%) | 1,184 (+23%) | 967 (+20%) |
| TypeScript | 127 | 1,590 (+35%) | 1,311 (+35%) | 1,288 (+34%) | 1,070 (+32%) |
| PHP | 139 | 1,609 (+37%) | 1,311 (+35%) | 1,262 (+31%) | 1,128 (+39%) |
| Rust | 142 | 1,815 (+54%) | 1,452 (+50%) | 1,411 (+47%) | 1,189 (+47%) |
| Java | 154 | 1,934 (+64%) | 1,551 (+60%) | 1,511 (+57%) | 1,217 (+50%) |
| C++ | 172 | 1,933 (+64%) | 1,626 (+68%) | 1,617 (+68%) | 1,343 (+66%) |
| Go | 199 | 2,143 (+82%) | 1,749 (+80%) | 1,701 (+77%) | 1,359 (+68%) |
| C | 177 | 2,219 (+89%) | 1,859 (+92%) | 1,820 (+89%) | 1,536 (+90%) |
Method
- Two programs written in each language: an inventory class (add, restock, sell, a low-stock list, total value and a formatted report) and Dijkstra's shortest path on a 6-node graph with path reconstruction. Every version was compiled or run and printed exactly the same output as the Python version.
- Code is idiomatic for each language with no comments: for example Java uses
PriorityQueue, Go usescontainer/heap, and C uses a simple array scan instead of a heap. All 20 source files are in the JSON download. - Claude: each file sent through Claude Code (
claude -p) with a fixed one-line system prompt; reported input tokens minus the same run with a one-character message. Opus 5.5 and Sonnet 5.5 gave identical counts, and a re-run gave identical counts. - Gemini: Google AI Studio prompt token counter on Gemini 3.8 Flash, minus its one start token. Four files were measured twice with identical results.
- GPT: tiktoken with
o200k_base.
Limitations
- Two small programs. Real projects with comments, long names or heavy boilerplate can shift the numbers; the ranking is more stable than the exact percentages.
- Style matters: the same language written more tersely or more verbosely will cost a different number of tokens.
- Input tokens only; it does not measure how well each model writes or understands each language.
How to cite
Free to use, quote and republish with attribution under CC BY 4.0. Please link to this page.
TokenSave (2026). Token cost by programming language: the same programs in 10 languages on Claude, Gemini and GPT [Data set]. Zenodo. https://doi.org/10.5281/zenodo.23446563
Embed the chart
Related
- Token cost by data format (JSON vs CSV vs TOON)
- Token cost by language on Claude, Gemini and GPT
- Count tokens for your own code
Questions or corrections: contact@jonhisking.com