We Asked 10 LLMs to Write Efficient Code. Only 4 Got Better.

*By Vilius Vystartas May 2026*

Every LLM can write code that works. The question is: can they write code that's efficient — and does telling them to be efficient actually help?

I tested 10 models on 10 coding tasks, each in two phases: unprompted (the model writes its own code) and prompted (explicitly told to write clean, DRY, efficient code). That's 200 API calls, $0.56 total. The results are... not what most prompt engineers would predict.

GPT-5.4 was the only model where prompting gave a substantial boost (+20pp). For most models, the "write efficient code" prompt was meaningless or actively harmful.


How the Metric Works

Each task has a known optimal token budget — the minimum tokens needed to produce correct, DRY code for that task (e.g., 70 tokens for 10 styled buttons using CSS classes vs 340 tokens for 10 separate button blocks). The efficiency score is optimal_tokens / actual_tokens, capped at 1.0, displayed as a percentage.

A score of 63% means the model used about 1.6× the optimal — not bad. A score of 43% means it used about 2.3× the optimal. The gap between unprompted and prompted tells you whether the "write efficient code" instruction actually changes behaviour.


The Leaderboard (Sorted by Prompted Efficiency)

# Model Unprompted Prompted Δ Frugal Price/1M Correctness
--- ------- :----------: :--------: :-: :------: :--------: :-----------:
🥇 GPT-5.4 43% 63% +20pp 30% $6.25 78% → 85%
🥈 Qwen 3.6 Plus 44% 60% +17pp 40% $0.81 78% → 87%
🥉 Gemma 4 31B 54% 58% +4pp 50% $0.20 92% both
4 DeepSeek Chat 51% 55% +4pp 30% $1.00 91% → 80%
5 Claude Sonnet 4 47% 52% +4pp 40% $6.60 92% both
6 LFM 2 24B A2B 54% 47% -6pp 30% $1.00 90% → 80%
7 Mistral Large 2411 54% 46% -8pp 40% $1.00 90% → 82%
8 Gemini 2.5 Flash 47% 46% -1pp 50% $0.96 92% → 90%
9 Cohere Command A 60% 44% -17pp 40% $10.00 90% → 82%
10 Kimi K2.6 34% 43% +9pp 30% $1.57 76% → 86%

What Stands Out

GPT-5.4 Is the Prompt Whisperer

GPT-5.4 improved on 7 of 10 tasks when prompted for efficiency. The biggest wins were config-generation (+81pp — went from 12 inline JSON blocks to a template loop), html-from-data (+71pp), and magic-strings (+38pp — switched to an Enum). It's the only model in the batch where the "write efficient code" instruction consistently produces different (and better) output.

The cost is notable — $0.10 for 20 tasks is mid-range, not cheap, not expensive. But the efficiency gain is real.

Gemma 4 31B: The Quiet Winner

Half of Gemma 4's tasks were already "frugal" — naturally efficient without being told. It scored 92% correctness on both phases at just $0.003 total. That's a 40× cost advantage over GPT-5.4 with higher correctness and competitive efficiency. For high-volume production where you want concise, correct code, Gemma 4 31B is the value pick of this batch.

Cohere Command A: Prompting Backfires

Cohere Command A had the highest unprompted efficiency in the batch (60%) — it naturally writes concise code. But when told "write efficient code," it ballooned output on several tasks. html-from-data went from a tight 45-token solution to a 600+-token monstrosity (-92pp gap). The prompt made it overthink.

Lesson: if a model is already efficient, don't prompt it to be more efficient.

Qwen 3.6 Plus: Second Place, Slowest

Qwen 3.6 Plus scored second in prompted efficiency (+17pp improvement) but took 26 minutes for 20 tasks — by far the slowest model. The efficiency gain is real (especially on html-from-data where it went from hardcoded rows to a map/join pattern), but you're waiting for it. Batch workloads only.

The Kimi Surprise

Kimi K2.6 had the lowest unprompted efficiency (34% — verbose, boilerplate-heavy code) but improved the most at the bottom end (+9pp). Still last place, but the prompt actually helped it compress — which is the opposite of the Cohere effect. Some models need the nudge.

Frugality: What Does It Mean?

"Frugal" means the model naturally produced code at or near the optimal token count without being asked. Gemma 4 31B and Gemini 2.5 Flash led at 50% — half their tasks were already efficient. GPT-5.4, DeepSeek Chat, and Kimi K2.6 were only 30% frugal — they needed the prompt to tighten up.


The Bigger Picture

Group Models Behaviour
Prompt-responsive GPT-5.4, Qwen 3.6 Plus Efficiency improves substantially with prompting
Prompt-neutral Gemma 4 31B, DeepSeek Chat, Claude Sonnet 4, Gemini 2.5 Flash, Kimi K2.6 Prompt has little effect (±4pp)
Prompt-antagonistic LFM 2 24B A2B, Mistral Large 2411, Cohere Command A Efficiency drops when prompted

The prompt-antagonistic group is the most interesting. These models know how to write efficient code (54-60% unprompted), but the explicit instruction triggers over-engineering — they add abstractions, comments, error handling, and other bloat that makes the output less efficient by the metric.

If the prompt says "write efficient code" and the model responds by writing more tokens, something in the training signal is misaligned.


My Picks


Methodology

Ten real-world coding tasks across CSS, JavaScript, Python, SQL, and bash — each with a known optimal token budget for a correct, DRY solution. Tasks included: styling 10 buttons (CSS), rendering 20 data rows as HTML (JS/HTML), bulk renaming (shell), form validation (Python), parametrized tests (Python), unit conversion (Python), SQL reporting queries, config generation (JSON), magic string replacement (Python/Enum), and middleware decorator pattern (Python/Flask).

Each model ran 10 tasks unprompted, then the same 10 tasks with an efficiency prompt appended. Scoring: efficiency_ratio = optimal_tokens / actual_tokens (capped at 1.0), displayed as a percentage. Correctness scored against expected output patterns.

Total cost: $0.56 for 200 API calls (10 models × 10 tasks × 2 phases). Temperature: 0.1. Max tokens: 600.

Full results: benchmarks.workswithagents.dev

← Back to blog

Spotted something?

Suggest an improvement, report an error, or just say hi.