A Controlled Experiment on the Energy Efficiency of the Source Code Generated by Code Llama
摘要
Context. Large Language Models (LLMs) are now crucial for developers to increase productivity and reduce software development time and cost. Code Llama, an LLM from Meta, is one of the most recent LLM tools. However, currently there is no objective assessment of the energy efficiency of the source code generated by Code Llama. Goal. In this paper, we present an empirical study that assesses the energy efficiency of the source code generated by Code Llama with respect to human-written source code. Method. We design an experiment involving three human-written programming problems implemented in C++, JavaScript, and Python. We ask Code Llama to generate the code of the problems using different prompts and temperatures, which sets the predictability of the output of an LLM. Therefore, we execute both implementations and profile their energy efficiency. Results. Our study shows that the energy efficiency of the code generated by Code Llama varies according to the chosen programming language and code characteristics. Human implementations tend to be more energy efficient overall, with generated JavaScript code outperforming its human counterpart. In addition, explicitly asking Code Llama to generate energy-efficient code results in an equal or worse energy efficiency, and using different temperatures does not seem to affect the energy efficiency of generated code. Conclusions. According to our results, code generated using Code Llama does not guarantee energy efficiency, even when prompted to do so. Therefore, software developers should evaluate the energy efficiency of generated code before integrating it into the software system under development.