Source: Research paper titled 'Green Code or Costly Code? Evaluating the Energy Costs of Iterative LLM-Based Code Optimizations' (arXiv:2610.32891), accepted at the 49th IEEE/ACM International Conference on Software Engineering (ICSE 2027).
Software developers and agentic workflows increasingly rely on iterative LLM self-refinement loops to optimize Python code for raw execution speed. This widespread practice implicitly assumes that reducing wall-clock runtime directly correlates with reduced electricity consumption. To challenge this assumption empirically, researchers Sadra Emami, Benjamin Weigell, Mohammad Reza Mousavi, Gunel Jahangirova, Hugo Araujo, and Bernhard Bauer designed a controlled study using per-process, hardware-level power meters across all 1,000 algorithmic tasks in the EffiBench benchmark.
The experimental setup evaluated 11 open-source foundation models across four distinct decoding configurations. Generating optimized code required between 0.79 and 8.68 megajoules (MJ) of inference energy across model-variant pairs—roughly equivalent to the electricity consumed by 250 to 2,800 GPT-4.1 queries. The researchers found that decoding parameters played a massive role during the generation phase: strictly limiting the maximum number of output tokens produced up to a 69% reduction in inference energy without degrading code correctness.
However, measuring execution-time energy revealed startling inefficiencies in the generated software. In 42 of the 44 evaluated configurations, the code produced by LLM self-refinement consumed more energy per problem than canonical human reference implementations, with energy overheads ranging from +4% to +886%. While LLMs frequently introduced algorithmic refactorings that appeared superficially faster in synthetic microbenchmarks, they frequently triggered heavy CPU memory thrashing and cache misses that dramatically increased hardware power draw.
In the two rare configurations where LLM-optimized code achieved genuine runtime energy reductions, the margin of improvement was minuscule. Calculating the net energy return on investment (ROI) revealed that the generated code would need to be executed between 10^6 and 10^7 times in production before cumulative runtime savings balanced out the initial energy expended during LLM inference.
From an architectural standpoint, the findings highlight Mixture-of-Experts (MoE) designs as the most impactful lever for sustainable computing. MoE architectures consumed significantly less inference energy than equivalently sized dense models while achieving equivalent or superior functional correctness, proving that model selection outweighs prompt tuning in green computing.