Saved in:
Bibliographic Details
Main Authors: Ashraf, Humza, Danish, Syed Muhammad, Rahman, Shadikur, Sattar, Zeeshan
Format: Preprint
Published: 2025
Subjects:
Online Access:https://arxiv.org/abs/2509.09947
Tags: Add Tag
No Tags, Be the first to tag this record!
_version_ 1866916994324889600
author Ashraf, Humza
Danish, Syed Muhammad
Rahman, Shadikur
Sattar, Zeeshan
author_facet Ashraf, Humza
Danish, Syed Muhammad
Rahman, Shadikur
Sattar, Zeeshan
contents There is a growing concern about the environmental impact of large language models (LLMs) in software development, particularly due to their high energy use and carbon footprint. Small Language Models (SLMs) offer a more sustainable alternative, requiring fewer computational resources while remaining effective for fundamental programming tasks. In this study, we investigate whether prompt engineering can improve the energy efficiency of SLMs in code generation. We evaluate four open-source SLMs, StableCode-Instruct-3B, Qwen2.5-Coder-3B-Instruct, CodeLlama-7B-Instruct, and Phi-3-Mini-4K-Instruct, across 150 Python problems from LeetCode, evenly distributed into easy, medium, and hard categories. Each model is tested under four prompting strategies: role prompting, zero-shot, few-shot, and chain-of-thought (CoT). For every generated solution, we measure runtime, memory usage, and energy consumption, comparing the results with a human-written baseline. Our findings show that CoT prompting provides consistent energy savings for Qwen2.5-Coder and StableCode-3B, while CodeLlama-7B and Phi-3-Mini-4K fail to outperform the baseline under any prompting strategy. These results highlight that the benefits of prompting are model-dependent and that carefully designed prompts can guide SLMs toward greener software development.
format Preprint
id arxiv_https___arxiv_org_abs_2509_09947
institution arXiv
publishDate 2025
record_format arxiv
spellingShingle Toward Green Code: Prompting Small Language Models for Energy-Efficient Code Generation
Ashraf, Humza
Danish, Syed Muhammad
Rahman, Shadikur
Sattar, Zeeshan
Software Engineering
There is a growing concern about the environmental impact of large language models (LLMs) in software development, particularly due to their high energy use and carbon footprint. Small Language Models (SLMs) offer a more sustainable alternative, requiring fewer computational resources while remaining effective for fundamental programming tasks. In this study, we investigate whether prompt engineering can improve the energy efficiency of SLMs in code generation. We evaluate four open-source SLMs, StableCode-Instruct-3B, Qwen2.5-Coder-3B-Instruct, CodeLlama-7B-Instruct, and Phi-3-Mini-4K-Instruct, across 150 Python problems from LeetCode, evenly distributed into easy, medium, and hard categories. Each model is tested under four prompting strategies: role prompting, zero-shot, few-shot, and chain-of-thought (CoT). For every generated solution, we measure runtime, memory usage, and energy consumption, comparing the results with a human-written baseline. Our findings show that CoT prompting provides consistent energy savings for Qwen2.5-Coder and StableCode-3B, while CodeLlama-7B and Phi-3-Mini-4K fail to outperform the baseline under any prompting strategy. These results highlight that the benefits of prompting are model-dependent and that carefully designed prompts can guide SLMs toward greener software development.
title Toward Green Code: Prompting Small Language Models for Energy-Efficient Code Generation
topic Software Engineering
url https://arxiv.org/abs/2509.09947