arXiv:2610.02571cs.SEOct 2026Cited by 1 paper on PaperVantage

Manuscript Offprint

arXiv:2610.02571

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

Ritika Rekhi, Bing Zhang, Md Arman Islam, Jaya Krishna Pasham, Yeswanth Chitturi, Akshay Paramesha, Isha Valiveti, Asif Imran, Bekir Turkkan, Tevfik Kosar

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Ritika Rekhi†, Bing Zhang‡, Md Arman Islam†, Jaya Krishna Pasham†, Yeswanth Chitturi†, Akshay Paramesha†, Isha Valiveti†, Asif Imran†, Bekir Turkkan§, Tevfik Kosar†

†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 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.

Index Terms—Sustainable AI, Large Language Models, Energy-Efficiency, Prompt Engineering

I. INTRODUCTION

The rapid transition of software development to Large Language Models (LLMs), along with the increasing role of LLMs in the day-to-day workflows of developers, has created new challenges regarding the amount of energy required to execute code produced by LLMs. While earlier generations of coding assistants were able to assist developers with only a single line of code at a time, today's agentic AI coding assistants complete entire projects with minimal human input. As a result, AI-assisted development has become a common practice, with 84% of surveyed developers now using or planning to use AI tools, while 51% of professional developers use them daily [1].

A recent analysis of more than 30 million GitHub commits by around 160,000 developers found that AI wrote roughly 29% of the Python functions contributed by U.S. developers by the end of 2024 [2], with developers in 2026 reporting that about 51.9% of their code was AI-generated [3]. The energy costs associated with AI-created code are quite high. In 2025, the world's data centers consumed roughly 485 TWh of electricity, a 17% increase over the previous year. This represents around 1.5% of all of the world's electrical needs. However, it is expected to grow to nearly twice that size by 2030, reaching 950 TWh [4]. In fact, U.S. based research estimates that data centers could consume about 649 TWh by 2030, accounting for 11.8% of total U.S. electricity, and as much as 15.3% under higher-demand estimates [5]. Additionally, it is estimated that globally, the IT sector is responsible for roughly 1.5% to 4% of global greenhouse gas emissions [6], [7], comparable to the emissions of the airline industry worldwide [8].

The energy efficiency of LLM-generated code is often much lower than that of human-written solutions, and in some cases LLM-generated code can consume up to 450 times more energy than human-generated canonical solutions [9]. One key reason is that LLMs frequently use heavier algorithms, additional data structures, and recursive logic, which involve unnecessary computations. This is not a one-time cost, as the energy consumed by code recurs every time it runs. This runtime energy adds to the electricity demand of data centers and the load on already strained power grids. Hence, making LLM-generated code more efficient matters as much for sustainability as it does for performance.

Larger models and higher pass rates did not correlate with more efficient code execution [10]. Given the high cost of retraining a pretrained model for energy awareness, prompting provides an alternative method. It is applicable to any model and incurs virtually no cost. However, despite considerable research effort, the current body of evidence on whether prompts reduce energy expenditure is mixed, and nearly all evidence has focused solely on Python [11]–[13].

To investigate whether prompt-based design can improve the energy efficiency of LLM-generated code and whether these improvements persist across programming languages, we analyzed the impact of 21 different prompting techniques on the energy efficiency of Python and C++ code generated by 10 popular open-weight and proprietary LLMs. As the dataset, we used 878 benchmark problems from EffiBench [14]. We extended EffiBench dataset with an execution and validation pipeline for C++ code. From these experiments, we identified the best eight prompt designs that produced the greatest improvements in energy efficiency and selected them for further analysis.

In summary, the paper makes the following contributions:

  1. We conduct a comprehensive evaluation of 21 prompt engineering strategies for energy-efficient code generation using a stratified subset of 110 problems from the extended EffiBench dataset. The evaluated prompts span both single-turn and multi-turn interactions and combine role-based prompting, few-shot learning, and chain-of-thought reasoning with targeted modifications, including explicit energy-efficiency instructions, coding guidelines, and energy-oriented code examples. This systematic design enables us to isolate and identify prompt characteristics that most effectively improve the energy efficiency of LLM-generated code.

  2. From our initial analysis, we identify 8 prompting strategies that consistently improve the energy-efficiency of generated code and evaluate them using 878 problems across 10 popular open-weight and proprietary LLMs.

  3. We develop a reproducible methodology for accurately measuring the energy consumption of LLM-generated code. Our evaluation framework incorporates language-specific execution environments, standardized benchmarking procedures, and carefully designed baseline and cool-off intervals to minimize measurement noise and enable fair comparisons of prompting strategies.

References (29)