{"id":4532,"date":"2026-05-27T05:51:51","date_gmt":"2026-05-26T22:51:51","guid":{"rendered":"https:\/\/daiilynews.cu.ma\/?p=4532"},"modified":"2026-05-27T05:51:51","modified_gmt":"2026-05-26T22:51:51","slug":"we-asked-10-llms-to-write-efficient-code-only-4-got-better","status":"publish","type":"post","link":"https:\/\/daiilynews.cu.ma\/?p=4532","title":{"rendered":"We Asked 10 LLMs to Write Efficient Code. Only 4 Got Better."},"content":{"rendered":"<p> <br \/>\n<br \/>\n                By Vilius Vystartas | May 2026<\/p>\n<p>Every LLM can write code that works. The question is: can they write code that&#8217;s efficient \u2014 and does telling them to be efficient actually help?<\/p>\n<p>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&#8217;s 200 API calls, $0.56 total. The results are&#8230; not what most prompt engineers would predict.<\/p>\n<p>GPT-5.4 was the only model where prompting gave a substantial boost (+0.20). For most models, the &#8220;write efficient code&#8221; prompt was meaningless or actively harmful.<\/p>\n<p>  How the Metric Works<\/p>\n<p>Each task has a known optimal token budget \u2014 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.<\/p>\n<p>A score of 0.63 means the model used about 1.6x the optimal \u2014 not bad. A score of 0.43 means it used about 2.3x the optimal. The gap between unprompted and prompted tells you whether the &#8220;write efficient code&#8221; instruction actually changes behaviour.<\/p>\n<p>  The Leaderboard (Sorted by Prompted Efficiency)<\/p>\n<p>#<br \/>\nModel<br \/>\nUnprompted<br \/>\nPrompted<br \/>\n\u0394<br \/>\nFrugal<br \/>\nCost<br \/>\nCorrectness<\/p>\n<p>\ud83e\udd47<br \/>\nGPT-5.4<br \/>\n0.43<br \/>\n0.63<br \/>\n+0.20<br \/>\n30%<br \/>\n$0.096<br \/>\n78% \u2192 85%<\/p>\n<p>\ud83e\udd48<br \/>\nQwen 3.6 Plus<br \/>\n0.44<br \/>\n0.60<br \/>\n+0.17<br \/>\n40%<br \/>\n$0.158<br \/>\n78% \u2192 87%<\/p>\n<p>\ud83e\udd49<br \/>\nGemma 4 31B<br \/>\n0.54<br \/>\n0.58<br \/>\n+0.04<br \/>\n50%<br \/>\n$0.003<br \/>\n92% both<\/p>\n<p>4<br \/>\nDeepSeek Chat<br \/>\n0.51<br \/>\n0.55<br \/>\n+0.04<br \/>\n30%<br \/>\n$0.006<br \/>\n91% \u2192 80%<\/p>\n<p>5<br \/>\nClaude Sonnet 4<br \/>\n0.47<br \/>\n0.52<br \/>\n+0.04<br \/>\n40%<br \/>\n$0.121<br \/>\n92% both<\/p>\n<p>6<br \/>\nLFM 2 24B A2B<br \/>\n0.54<br \/>\n0.47<br \/>\n-0.06<br \/>\n30%<br \/>\n$0.001<br \/>\n90% \u2192 80%<\/p>\n<p>7<br \/>\nMistral Large 2411<br \/>\n0.54<br \/>\n0.46<br \/>\n-0.08<br \/>\n40%<br \/>\n$0.050<br \/>\n90% \u2192 82%<\/p>\n<p>8<br \/>\nGemini 2.5 Flash<br \/>\n0.47<br \/>\n0.46<br \/>\n-0.01<br \/>\n50%<br \/>\n$0.020<br \/>\n92% \u2192 90%<\/p>\n<p>9<br \/>\nCohere Command A<br \/>\n0.60<br \/>\n0.44<br \/>\n-0.17<br \/>\n40%<br \/>\n$0.071<br \/>\n90% \u2192 82%<\/p>\n<p>10<br \/>\nKimi K2.6<br \/>\n0.34<br \/>\n0.43<br \/>\n+0.09<br \/>\n30%<br \/>\n$0.029<br \/>\n76% \u2192 86%<\/p>\n<p>  What Stands Out<\/p>\n<p>  GPT-5.4 Is the Prompt Whisperer<\/p>\n<p>GPT-5.4 improved on 7 of 10 tasks when prompted for efficiency. The biggest wins were config-generation (+0.81 \u2014 went from 12 inline JSON blocks to a template loop), html-from-data (+0.71), and magic-strings (+0.38 \u2014 switched to an Enum). It&#8217;s the only model in the batch where the &#8220;write efficient code&#8221; instruction consistently produces different (and better) output.<\/p>\n<p>The cost is notable \u2014 $0.10 for 20 tasks is mid-range, not cheap, not expensive. But the efficiency gain is real.<\/p>\n<p>  Gemma 4 31B: The Quiet Winner<\/p>\n<p>Half of Gemma 4&#8217;s tasks were already &#8220;frugal&#8221; \u2014 naturally efficient without being told. It scored 92% correctness on both phases at just $0.003 total. That&#8217;s a 40x 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.<\/p>\n<p>  Cohere Command A: Prompting Backfires<\/p>\n<p>Cohere Command A had the highest unprompted efficiency in the batch (0.60) \u2014 it naturally writes concise code. But when told &#8220;write efficient code,&#8221; it ballooned output on several tasks. html-from-data went from a tight 45-token solution to a 600+-token monstrosity (-0.92 gap). The prompt made it overthink.<\/p>\n<p>Lesson: if a model is already efficient, don&#8217;t prompt it to be more efficient.<\/p>\n<p>  Qwen 3.6 Plus: Second Place, Slowest<\/p>\n<p>Qwen 3.6 Plus scored second in prompted efficiency (+0.17 improvement) but took 26 minutes for 20 tasks \u2014 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&#8217;re waiting for it. Batch workloads only.<\/p>\n<p>  The Kimi Surprise<\/p>\n<p>Kimi K2.6 had the lowest unprompted efficiency (0.34 \u2014 verbose, boilerplate-heavy code) but improved the most at the bottom end (+0.09). Still last place, but the prompt actually helped it compress \u2014 which is the opposite of the Cohere effect. Some models need the nudge.<\/p>\n<p>  Frugality: What Does It Mean?<\/p>\n<p>&#8220;Frugal&#8221; 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% \u2014 half their tasks were already efficient. GPT-5.4, DeepSeek Chat, and Kimi K2.6 were only 30% frugal \u2014 they needed the prompt to tighten up.<\/p>\n<p>  The Bigger Picture<\/p>\n<p>Group<br \/>\nModels<br \/>\nBehaviour<\/p>\n<p>Prompt-responsive<br \/>\nGPT-5.4, Qwen 3.6 Plus<br \/>\nEfficiency improves substantially with prompting<\/p>\n<p>Prompt-neutral<br \/>\nGemma 4 31B, DeepSeek Chat, Claude Sonnet 4, Gemini 2.5 Flash, Kimi K2.6<br \/>\nPrompt has little effect (\u00b10.04)<\/p>\n<p>Prompt-antagonistic<br \/>\nLFM 2 24B A2B, Mistral Large 2411, Cohere Command A<br \/>\nEfficiency drops when prompted<\/p>\n<p>The prompt-antagonistic group is the most interesting. These models know how to write efficient code (0.54-0.60 unprompted), but the explicit instruction triggers over-engineering \u2014 they add abstractions, comments, error handling, and other bloat that makes the output less efficient by the metric.<\/p>\n<p>If the prompt says &#8220;write efficient code&#8221; and the model responds by writing more tokens, something in the training signal is misaligned.<\/p>\n<p>  My Picks<\/p>\n<p>Best prompted efficiency: GPT-5.4 \u2014 0.63, $0.10 for 20 tasks. The only model where prompting reliably improves output.<\/p>\n<p>Best value overall: Gemma 4 31B \u2014 0.58 prompted, 92% correctness, $0.003. Absurd price\/performance.<\/p>\n<p>Best natural efficiency: Cohere Command A \u2014 0.60 unprompted. Don&#8217;t prompt it, just let it work.<\/p>\n<p>Most consistent: Claude Sonnet 4 \u2014 92% correctness on both phases, small +0.04 efficiency gain. Reliable.<\/p>\n<p>Skip if you&#8217;re in a hurry: Qwen 3.6 Plus \u2014 26 minutes for 20 tasks. Great efficiency gains, terrible latency.<\/p>\n<p>Watch list: Kimi K2.6 \u2014 low base efficiency but the prompt actually helps. Worth retesting with a better prompt.<\/p>\n<p>  Methodology<\/p>\n<p>Ten real-world coding tasks across CSS, JavaScript, Python, SQL, and bash \u2014 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).<\/p>\n<p>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). Correctness scored against expected output patterns.<\/p>\n<p>Total cost: $0.56 for 200 API calls (10 models \u00d7 10 tasks \u00d7 2 phases). Temperature: 0.1. Max tokens: 600.<\/p>\n<p>Full results: benchmarks.workswithagents.dev<\/p>\n<p><br \/>\n<br \/><a href=\"https:\/\/dev.to\/vystartasv\/we-asked-10-llms-to-write-efficient-code-only-4-got-better-47gf\">Source link <\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>By Vilius Vystartas | May 2026 Every LLM can write code that works. The question is: can they write code that&#8217;s efficient \u2014 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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":4533,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[676],"tags":[835,1635,761,765,762,763,764,1523,860,760],"class_list":["post-4532","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tech-ai","tag-ai","tag-benchmark","tag-coding","tag-community","tag-development","tag-engineering","tag-inclusive","tag-llm","tag-programming","tag-software"],"_links":{"self":[{"href":"https:\/\/daiilynews.cu.ma\/index.php?rest_route=\/wp\/v2\/posts\/4532","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/daiilynews.cu.ma\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/daiilynews.cu.ma\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/daiilynews.cu.ma\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/daiilynews.cu.ma\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4532"}],"version-history":[{"count":0,"href":"https:\/\/daiilynews.cu.ma\/index.php?rest_route=\/wp\/v2\/posts\/4532\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/daiilynews.cu.ma\/index.php?rest_route=\/wp\/v2\/media\/4533"}],"wp:attachment":[{"href":"https:\/\/daiilynews.cu.ma\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4532"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/daiilynews.cu.ma\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4532"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/daiilynews.cu.ma\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4532"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}