# Can We Make Code Green? Understanding Trade-Offs in LLMs vs. Human Code Optimizations

arXiv: https://arxiv.org/abs/2503.20126 · HTML: https://mlsanity.com/paper/2503.20126/

## Key facts

- Cited by 1 papers in the map (data through 14 Oct 2026).
- Builds on 17 of its 80 references that are in the map.
- First posted on arXiv 26 Mar 2025.

## Builds on (most cited first, 17 of 17)

- [GPT-4 Technical Report](https://mlsanity.com/paper/2303.08774/) (2023)
- [Quantifying the Carbon Emissions of Machine Learning](https://mlsanity.com/paper/1910.09700/) (2019)
- [Supersonic: Learning to Generate Source Code Optimizations in C/C++](https://mlsanity.com/paper/2309.14846/) (2023)
- [Analysis of ChatGPT on Source Code](https://mlsanity.com/paper/2306.00597/) (2023)
- [Efficiency is Not Enough: A Critical Perspective of Environmentally Sustainable AI](https://mlsanity.com/paper/2309.02065/) (2023)
- [Catalog of Energy Patterns for Mobile Applications](https://mlsanity.com/paper/1901.03302/) (2019)
- [A Controlled Experiment on the Energy Efficiency of the Source Code Generated by Code Llama](https://mlsanity.com/paper/2405.03616/) (2024)
- [EnergiBridge: Empowering Software Sustainability through Cross-Platform Energy Measurement](https://mlsanity.com/paper/2312.13897/) (2023)
- [Can Open-Source LLMs Compete with Commercial Models? Exploring the Few-Shot Performance of Current GPT Models in Biomedical Tasks](https://mlsanity.com/paper/2407.13511/) (2024)
- [Generating Energy-efficient code with LLMs](https://mlsanity.com/paper/2411.10599/) (2024)
- [Unveiling the Energy Vampires: A Methodology for Debugging Software Energy Consumption](https://mlsanity.com/paper/2412.10063/) (2024)
- [Do Energy-oriented Changes Hinder Maintainability?](https://mlsanity.com/paper/1908.08332/) (2019)
- [A Case for Sustainability and Environment Friendliness in Software Development and Architecture Decisions by Taking Energy-Efficient Design Decisions](https://mlsanity.com/paper/2311.01680/) (2023)
- [LLM Interactive Optimization of Open Source Python Libraries -- Case Studies and Generalization](https://mlsanity.com/paper/2312.14949/) (2023)
- [SLNET: A Redistributable Corpus of 3rd-party Simulink Models](https://mlsanity.com/paper/2203.17112/) (2022)
- [On the Energy Consumption of Different Dataframe Processing Libraries -- An Exploratory Study](https://mlsanity.com/paper/2209.05258/) (2022)
- [Energy Patterns for Web: An Exploratory Study](https://mlsanity.com/paper/2401.06482/) (2024)

## Built on by (most cited first, 1 of 1)

- [Energy-Aware Code Generation with LLMs: Benchmarking Small vs. Large Language Models for Sustainable AI Programming](https://mlsanity.com/paper/2508.08332/) (2025)

## Abstract (arXiv)

The rapid technological evolution has accelerated software development for various domains and use cases, contributing to a growing share of global carbon emissions. While recent large language models (LLMs) claim to assist developers in optimizing code for performance and energy efficiency, their efficacy in real-world scenarios remains under exploration. In this work, we explore the effectiveness of LLMs in reducing the environmental footprint of real-world projects, focusing on software written in Matlab-widely used in both academia and industry for scientific and engineering applications. We analyze energy-focused optimization on 400 scripts across 100 top GitHub repositories. We examine potential 2,176 optimizations recommended by leading LLMs, such as GPT-3, GPT-4, Llama, and Mixtral, and a senior Matlab developer, on energy consumption, memory usage, execution time consumption, and code correctness. The developer serves as a real-world baseline for comparing typical human and LLM-generated optimizations. Mapping these optimizations to 13 high-level themes, we found that LLMs propose a broad spectrum of improvements--beyond energy efficiency--including improving code readability and maintainability, memory management, error handling while the developer overlooked some parallel processing, error handling etc. However, our statistical tests reveal that the energy-focused optimizations unexpectedly negatively impacted memory usage, with no clear benefits regarding execution time or energy consumption. Our qualitative analysis of energy-time trade-offs revealed that some themes, such as vectorization preallocation, were among the common themes shaping these trade-offs. With LLMs becoming ubiquitous in modern software development, our study serves as a call to action: prioritizing the evaluation of common coding practices to identify the green ones.
