arXiv:2610.32891cs.SEOct 2026

Manuscript Offprint

arXiv:2610.32891

Green Code or Costly Code? Evaluating the Energy Costs of Iterative LLM-Based Code Optimizations

Sadra Emami, Benjamin Weigell, Mohammad Reza Mousavi, Gunel Jahangirova, Hugo Araujo, Bernhard Bauer

1 st^{st} Sadra Emami

University of Augsburg

Augsburg, Germany

sadra.emami@uni-a.de

2 nd^{nd} Benjamin Weigell

University of Augsburg

Augsburg, Germany

benjamin.weigell@uni-a.de

4 th^{th} Gunel Jahangirova

King's College London

London, United Kingdom

gunel.jahangirova@kcl.ac.uk

3 rd^{rd} Mohammad Reza Mousavi

King's College London

London, United Kingdom

mohammad.mousavi@kcl.ac.uk

5 th^{th} Hugo Araujo

King's College London

London, United Kingdom

hugo.araujo@kcl.ac.uk

6 th^{th} Bernhard Bauer

University of Augsburg

Augsburg, Germany

bernhard.bauer@uni-a.de

Abstract— Large Language Models (LLMs) are increasingly used to optimize code for performance. This practice often assumes that improvements in execution speed naturally translate into overall lower energy consumption. We challenge this assumption empirically by measuring whether performance-optimized code produced by LLM self-refinement pipelines is also energy-efficient relative to canonical human reference solutions, and whether the energy cost of the optimization process can be offset by subsequent execution-time savings. We evaluate 11 open-source models across four decoding configurations on all 1,000 problems of EffiBench, a state-of-the-art performance benchmark, while collecting per-process, hardware-level energy measurements throughout. Inference energy spans 0.79–8.68 MJ across model-variant pairs, which is roughly equivalent to the energy of 250–2800 GPT-4.1 queries. Limiting the maximum number of output tokens has the largest impact, reducing energy use by up to 69% compared to the default configuration. On the execution side, 42 of 44 configurations produce code that consumes more energy per problem than the canonical human reference, with overheads ranging from +4% to +886%. The two exceptions achieve only marginal gains, with break-even points on the order of 106−10710^{6}-10^{7} executions. Mixture-of-Experts architectures consume substantially less inference energy than equivalently-sized dense models without sacrificing correctness, making architectural choice a more consequential sustainability lever than decoding parameters. Performance optimization and energy efficiency are not always aligned goals: LLM self-refinement consistently produces faster-seeking but energy-heavier code relative to what a human engineer would write. All artifacts are available at https://doi.org/10.5281/zenodo.23598170.

Index Terms—large language models, energy consumption, green software engineering, code efficiency, code optimization, break-even analysis

I. INTRODUCTION

Recent studies indicate that developers routinely integrate Large Language Models (LLMs) into their daily coding workflows [1], [2]. Beyond code generation, LLMs are used to iteratively refine code to reduce execution time and memory usage, tasks that previously required expert manual effort [3]. This growing practice implicitly assumes that performance improvements also translate into environmental benefits: that faster code is greener code. However, each optimization interaction carries two distinct energy costs: the inference energy consumed when the model produces code [4], [5], and the execution energy consumed when that code is later run [6]. Both costs are largely invisible to the developer, yet together determine whether an optimization yields a net energy benefit. However, it remains unclear whether the execution-time savings can offset the energy required to generate the optimization, or whether LLM-optimized code is more energy-efficient than code written by human developers [7], [8].

Coignion et al. [9] introduce the Break-Even Point (BEP), defined as the number of executions at which cumulative execution savings offset generation cost, and find that this point ranges from under 100 to over 200,000 executions depending on the large language model and the method that is being optimized. However, their analysis measures savings relative to each model's own unoptimized output rather than a canonical human-written solution. This distinction is important because a model can greatly improve upon its own baseline while still producing code that is less efficient than a competent human solution. As a result, it remains unclear whether LLM-optimized code is actually competitive with what a competent human engineer would produce.

We investigate this question by evaluating the energy consumption of LLM-based code optimization end-to-end. We use EffiLearner [3], a state-of-the-art iterative self-refinement pipeline for code performance optimization, to generate optimized solutions. We evaluate these solutions against the canonical human-written reference implementations in EffiBench [10], a benchmark of 1,000 LeetCode problems paired with top-rated human solutions. We evaluate only open-source models deployed on-premise. Such deployments are increasingly adopted in privacy-sensitive environments, while also allowing us to instrument the underlying hardware and obtain precise, hardware-level measurements of inference energy rather than relying on estimates or provider-reported statistics.

Accepted at the 49th IEEE/ACM International Conference on Software Engineering (ICSE 2027).

Addressing the practical value of LLM-based optimization requires examining three different aspects. First, the optimization process itself incurs an energy cost that must be quantified. Second, this cost may vary substantially across models and decoding strategies, potentially changing the trade-off between optimization quality and energy consumption. Finally, the generation investment is worthwhile only if the resulting code consumes less execution energy than a strong human-written baseline, allowing the initial energy cost to be recovered over repeated executions. These considerations motivate the following research questions:

• RQ1. What is the energy cost of generating performance-optimized code using LLMs?

• RQ2. How does the energy cost of generating optimized code vary across open-source LLMs and decoding configurations?

– RQ2a. How do decoding parameters (temperature, context window, maximum output tokens) affect energy consumption across models?

– RQ2b. Which model-configuration pairs offer the most favorable trade-off between inference energy and optimization quality?

• RQ3. Does performance-optimized code consume less execution energy than canonical human reference solutions, and if so, at what number of executions does the generation investment break even?

References (35)