Improving the Energy-Efficiency of the Code Generated by LLMs through Effective Prompting

📅 2026-10-01
📈 Citations: 0
✨ Influential: 0
📄 PDF
🤖 AI Summary
This study addresses the high energy consumption of code generated by large language models (LLMs) and the lack of systematic energy efficiency evaluations by presenting the first comprehensive quantification of how prompt engineering affects the energy usage of LLM-generated code. Through extensive benchmarking and multi-model comparisons, this work systematically evaluates the execution efficiency and energy consumption differences of Python and C++ code produced under various prompting strategies. The results demonstrate that optimized prompt strategies can reduce the energy consumption of generated Python and C++ code by 25% and 17%, respectively, with certain models achieving reductions exceeding 50%. These findings reveal significant energy efficiency disparities across different models and programming languages, providing empirical evidence to advance green AI practices in automated code generation.
📝 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 56% for Granite-4.0-H-Small and 7% 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.
Problem

Research questions and friction points this paper is trying to address.

Energy Efficiency
Code Generation
Large Language Models
Prompting Strategies
Sustainable AI
Innovation

Methods, ideas, or system contributions that make the work stand out.

Energy-Efficient Code Generation
Prompting Strategies
Large Language Models
Green AI
Software Sustainability
💼 Related Jobs
No related jobs found.
R
Ritika Rekhi
University at Buffalo, Buffalo, NY, USA
B
Bing Zhang
National Center for Supercomputing Applications, Urbana, IL, USA
M
Md Arman Islam
University at Buffalo, Buffalo, NY, USA
J
Jaya Krishna Pasham
University at Buffalo, Buffalo, NY, USA
Y
Yeswanth Chitturi
University at Buffalo, Buffalo, NY, USA
A
Akshay Paramesha
University at Buffalo, Buffalo, NY, USA
I
Isha Valiveti
University at Buffalo, Buffalo, NY, USA
Asif Imran
Asif Imran
University at Buffalo
software engineeringsoftware securitymachine learning
B
Bekir Turkkan
IBM Research, Yorktown Heights, NY, USA
Tevfik Kosar
Tevfik Kosar
Professor, University at Buffalo (SUNY)
Distributed systemsgreen and sustainable computingAI/ML for systems