Improving the Energy-Efficiency of the Code Generated by LLMs through Effective Prompting
Organizations: University at Buffalo, Buffalo, NY, USA · National Center for Supercomputing Applications, Urbana, IL, USA · IBM Research, Yorktown Heights, NY, USA
Abstract
As AI-assisted programming becomes increasingly mainstream, the environmental impact of AI-generated software has emerged as an important consideration. This motivates evaluating LLM-generated code beyond functional correctness by considering execution efficiency and energy consumption. However, despite substantial advances in code generation, frontier LLMs are rarely evaluated based on the energy efficiency of the code they produce. In this work, we conduct a comprehensive evaluation of 21 prompting strategies for energy-efficient code generation and identify 8 strategies for evaluation across 10 widely used open-weight and proprietary LLMs. We evaluate their effectiveness for both Python and C++ code generation relative to a baseline prompt. Across the evaluated models, the selected prompting strategies achieved energy reductions of up to 25% for Python and 17% for C++ code generation. At the model level, Python energy reductions reached up to 50% for Granite-4.0-H-Small, 39% for Claude 4.5 Haiku, and 28% for MiniMax M3, while C++ reductions reached up to 57% for Granite-4.0-H-Small and 6.4% for Qwen3-Coder-480B-A35B-Instruct. These results demonstrate that prompting strategies can substantially influence the energy consumption of LLM-generated code, although their effectiveness varies across models and programming languages. Our findings highlight the importance of incorporating energy efficiency into the evaluation and optimization of LLM-based code generation and provide practical insights into designing prompts for more sustainable AI-assisted programming.
Figures & tables
| Model Details | Model Configuration | |||||||
|---|---|---|---|---|---|---|---|---|
| Model Name | Model Weights | Knowledge Cut-off | API Provider | API Type Used | Temp. | Top_p | Top_k | Reasoning / Thinking Configuration |
| Claude 4.5 Haiku | Closed | Feb. 2025 | Anthropic | Batch | ∗ 1 | ∗ 1 | ∗ 0 | ∗ Thinking: Disabled |
| Gemini 3.8 Flash | Closed | Mar. 2026 | Google Vertex AI | Batch | N/A | N/A | N/A | ∗ Thinking Level: Medium |
| GPT-5.6 Terra | Closed | Feb. 2026 | OpenAI | Batch | N/A | N/A | N/A | ∗ Reasoning Effort: Medium |
| GPT-OSS-120B (116.8B total / 5.1B active) | Open | Jun. 2024 | Fireworks AI | Batch | 1 | 1 | ∗ 0 | Reasoning Effort: High |
| Gemma 4 26B A4B IT (25.2B total / 3.8B active) | Open | Jan. 2026 | Fireworks AI | Batch | 1 | 0.95 | 64 | Thinking: Enabled |
| Prompt Number | Conversation Type | Source | Prompt Type | Change Scope | Additions Made to EffiBench Prompt |
|---|---|---|---|---|---|
| Prompt 0 (EffiBench Prompt) | SingleTurn | [ 14 ] | Zero-Shot | - | - |
| Prompt 1 | SingleTurn | [ 11 ] [ 13 ] [ 27 ] [ 28 ] | Zero-Shot | User Prompt | Energy-Efficiency Keyword |
| Prompt 2 | Single-Turn | - | Zero-Shot | User Prompt | Energy-Efficiency Keyword and Definition |
| Prompt 3 | Single-Turn | - | Few-Shot | User Prompt | Energy-Efficiency Keyword, General Efficiency Guidelines |
| Prompt 4 | Single-Turn | - | Persona-Based + Zero-Shot | User Prompt | General Efficiency Guidelines, Language-Specific Efficient Practices |
| Prompt 5 | Single-Turn | - | Persona-Based + Zero-Shot | System Prompt | Expert Competitive Programmer Persona, Energy-Efficiency Definition |
| Algorithms | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Difficulty | Backtracking | BFS | Binary Search | Bit Manip. | DFS | Divide & Conquer | DP | Greedy | Sliding Window | Sorting | Two Pointers | Total |
| Easy | 1 | 0 | 13 | 21 | 0 | 2 | 7 | 25 | 7 | 47 | 24 | 110 |
| Medium | 17 | 21 | 48 | 33 | 24 | 3 | 96 | 98 | 31 | 83 | 33 | 333 |
| Hard | 3 | 6 | 24 | 7 | 2 | 4 | 45 | 18 | 8 | 17 | 0 | 94 |
| Total | 21 | 27 | 85 | 61 | 26 | 9 | 148 | 141 | 46 | 147 | 57 | 537 |
| Algorithms | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Difficulty | Backtracking | BFS | Binary Search | Bit Manip. | DFS | Divide & Conquer | DP | Greedy | Sliding Window | Sorting | Two Pointers | Total |
| Easy | 1 | 0 | 20 | 19 | 0 | 1 | 5 | 31 | 4 | 56 | 26 | 121 |
| Medium | 9 | 9 | 55 | 40 | 13 | 3 | 105 | 132 | 37 | 97 | 43 | 373 |
| Hard | 0 | 7 | 22 | 11 | 2 | 1 | 66 | 15 | 8 | 21 | 1 | 113 |
| Total | 10 | 16 | 97 | 70 | 15 | 5 | 176 | 178 | 49 | 174 | 70 | 607 |
LLM Code Generation
Large language model code generation studies how models translate instructions and context into executable programs and how to make them reliable.
See all 308 papers