An exploration of prompting LLMs to generate energy-efficient code

Open Access
Authors
Publication date 2025
Book title GREENS 2025 : 2025 IEEE/ACM 9th International Workshop on Green and Sustainable Software
Book subtitle Ottawa, Ontario, Canada, 29 April 2025 : proceedings
ISBN
  • 9798331538163
ISBN (electronic)
  • 9798331538156
Event 9th IEEE/ACM International Workshop on Green and Sustainable Software, GREENS 2025
Pages (from-to) 31-38
Number of pages 8
Publisher Los Alamitos, California: IEEE Computer Society
Organisations
  • Faculty of Science (FNWI) - Informatics Institute (IVI)
Abstract

The increasing electricity demands of personal computers, communication networks, and data centers contribute to higher atmospheric greenhouse gas emissions, which in turn lead to global warming and climate change. Therefore the energy consumption of code must be minimised. Large language models can generate code, so we study the influence of prompting for energy-efficient code by examining the energy consumption of the generated code. We use three different Python code problems of varying difficulty levels. Prompt modification is done by adding the sentence "Give me an energy-optimised solution for this problem"or by providing two Python coding best practices. The large language models used are Code Llama-70b, Code Llama-70b-Instruct, Code Llama-70b-Python, DeepSeek-Coder-33b-base, and DeepSeek-Coder-33b-instruct. We find a decrease in energy consumption for a specific combination of prompt optimisation, LLM, and Python code problem. However, no single optimisation prompt consistently decreases energy consumption for the same LLM across the different Python code problems.

Document type Conference contribution
Language English
Published at
Other links
Downloads
Permalink to this page
Back