Can LLMs Generate Green Code - A Comprehensive Study Through LeetCode

This paper presents a comprehensive analysis of code generated by Large Language Models (LLMs) in terms of energy consumption and speed, moving beyond traditional accuracy metrics. We evaluate eight state-of-the-art models, including ChatGPT-3.5, ChatGPT-4o, CodeGemma:7b, WizardCoder:33b, Llama3:8b, Phind-CodeLlama:34b-v2, Nous-Hermes2:10.7b, and Mistral:7b, using RuntimeRatio and EnergyRatio metrics on LeetCode<sup xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:xlink="http://www.w3.org/1999/xlink">1</sup> questions. To evaluate LLMs’ understanding on energy efficient concepts, we propose a three-step prompting methodology to test models on coding with runtime and energy efficiency in mind. In an overwhelming majority of cases, LLMs perform worse than the human solution in both code runtime and energy consumption. In cases where models do perform well, it is often because they are aware of the question online, and produce responses similar or identical to famous solutions. Our comparative analysis of the efficient prompt and chain of thought prompt methods to the base prompt emphasize that models are inconsistent with producing quicker and more efficient code when directly asked to assemble energy efficient code. Our findings highlight that LLMs currently lack understanding in energy efficiency in terms of code generation, pushing a need for efforts to add green computing ideas and energy efficiency for future training and fine-tuning.

Authors

Institutions

Publication Details

Published
2024-11-02
DOI
https://doi.org/10.1109/igsc64514.2024.00017
Citations
5
Primary Topic
Power Systems and Technologies
Type
article
Field-Weighted Citation Impact
1.04
Controls
|||
ALL TIME
JAN
FEB
MAR
APR
MAY
JUN
JUL
AUG
SEP
OCT
article

Can LLMs Generate Green Code - A Comprehensive Study Through LeetCode

Ziliang Zong, Dayuan Chen, Noe Soto, Jonas F. Tuttle et al.
5 citations
Power Systems and Technologies
1.04
article

Can LLMs Generate Green Code - A Comprehensive Study Through LeetCode

Ziliang Zong, Dayuan Chen, Noe Soto, Jonas F. Tuttle, Amina Nasrin
article en
5 citations

Abstract

This paper presents a comprehensive analysis of code generated by Large Language Models (LLMs) in terms of energy consumption and speed, moving beyond traditional accuracy metrics. We evaluate eight state-of-the-art models, including ChatGPT-3.5, ChatGPT-4o, CodeGemma:7b, WizardCoder:33b, Llama3:8b, Phind-CodeLlama:34b-v2, Nous-Hermes2:10.7b, and Mistral:7b, using RuntimeRatio and EnergyRatio metrics on LeetCode<sup xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:xlink="http://www.w3.org/1999/xlink">1</sup> questions. To evaluate LLMs’ understanding on energy efficient concepts, we propose a three-step prompting methodology to test models on coding with runtime and energy efficiency in mind. In an overwhelming majority of cases, LLMs perform worse than the human solution in both code runtime and energy consumption. In cases where models do perform well, it is often because they are aware of the question online, and produce responses similar or identical to famous solutions. Our comparative analysis of the efficient prompt and chain of thought prompt methods to the base prompt emphasize that models are inconsistent with producing quicker and more efficient code when directly asked to assemble energy efficient code. Our findings highlight that LLMs currently lack understanding in energy efficiency in terms of code generation, pushing a need for efforts to add green computing ideas and energy efficiency for future training and fine-tuning.

Texas State University (US)
Openalex Percentile: Top 22%
Power Systems and Technologies
1.04
AI Navigator

Ask Laika to Summarize, Analyze, and Connect papers live on the map.

Summarize Papers & Methodologies

Extract key findings, datasets, and comparative methods across publications.

Benchmark Rankings & Visual Analytics

Rank top research institutions, authors, funders, topics, and journals by Field-Weighted Citation Impact (FWCI) and paper volume with instant charts.

Connect Distant Disciplines

Bridge topological clusters on the map to find hidden collaborative intersections.