Coding assistants · Research feature

LLM Code Completion Energy Costs Vary by Task and Model Size

A study of 25 open-weight LLMs finds energy use in code completion depends on task type, context length, and model scale.

Adapted from research by Negar Alizadeh, Nishant Saurabh, Fernando Castor.

arXiv preprint revision · 2026-09-27 · Attribution & reuse
In this article
Editorial illustration of developer workstation.

Editor’s introduction

The study evaluated 25 open-weight large language models on two code completion tasks: repository-level next-line completion with varying context sizes on RepoBench, and fill-in-the-middle tasks in Python, Java, and Rust on McEval. It found energy consumption is driven by task structure—input context size and model scale dominate in long-context workloads, while output generation and active parameters are key in generation-heavy tasks. Smaller, quantized models often match the accuracy of larger models while using significantly less energy. The research shows that increasing model size or context length does not proportionally improve completion quality, and quantization improves energy efficiency with minimal accuracy loss. These results highlight that energy use in LLM-based code completion is not uniform and depends strongly on workload characteristics and model configuration.

Introduction

Since the emergence of large language models (LLMs) and their rapid advancement in software development tasks, these models have become increasingly popular among software companies and individual programmers, with 84% of developers using or planning to use AI tools. Furthermore, numerous IDEs now incorporate LLM-based code completion tools (e.g., GitHub Copilot, JetBrains AI Assistant, Gemini Code Assist, Claude Code, and Tabnine) and many AI-powered coding environments such as Cursor and Devin are emerging.

LLMs are known to be energy-intensive. Prior work has examined the energy consumption of language models with earlier work focusing mostly on the training phase and more recent papers also investigating the costs of inference. Training is orders of magnitude more expensive, but inference grows with scale and can represent the majority of the energy cost of LLMs for long-term energy use. Prior measurements report that approximately three-fifths of ML energy use is attributed to inference and two-fifths to training. Despite this, most previous work has focused on natural language tasks, with few studies investigating the energy efficiency of LLMs in software development. Existing studies of inference energy indicate that energy usage varies across tasks. This highlights the importance of evaluating LLM performance and energy efficiency not only for natural language tasks but also for other domains such as programming. Even within coding tasks, performance and energy consumption may vary across programming languages due to differences in syntax complexity, ecosystem maturity, and training data availability. For example, Python’s syntax is less verbose than Java’s, with the former being dynamically typed and the latter statically typed. Furthermore, Rust has a unique type system among mainstream programming languages and comparatively less training data.

This study investigates the energy use of LLMs in code completion tasks. Previous studies on LLM inference energy focused primarily on output-intensive tasks, such as code generation and bug fixing, and input tokens are often considered relatively inexpensive in comparison. However, in long-context software engineering workloads such as repository-level code completion, processing large input contexts can become a major energy bottleneck. In scenarios where input contexts consist of thousands of tokens while the output contains only a few lines, the relative contribution of input processing becomes significantly larger. This study aims to quantify the relative impact of input and output tokens across different code completion workloads. We focus our investigation on locally-deployable, open weight models. The ability to run these models locally enables us to obtain precise energy measurement while controlling for interference from external factors. The architecture of smaller models often mirrors that of larger ones and results are to some extent transferrable.

Execution Environment

To run LLMs locally, an LLM inference engine is required. Several open-source LLM inference engines have recently emerged to enable local deployment and inference of open-weight LLMs, including PrivateGPT (57.4K GitHub stars), GPT4All (77.4K), llamafile (25.5K), vLLM (87.6K), Ollama (177K) at the time of this study. We selected Ollama (v0.13.0) due to its popularity, as reflected by its GitHub star metric. It is particularly useful for its support of multiple quantization levels, enabling efficient execution on commodity hardware. Furthermore, its seamless model-switching capability and extensive API features make it well-suited for exploration and reproducible experiments. Additionally, its strong adoption among developers, as reported in the 2025 Stack Overflow Developer Survey, further reinforces the external validity of our tool selection.

To monitor GPU utilization and to measure power consumption, as suggested in previous studies, we use the Python interface (nvidia-ml-py v13.590.48) for the NVIDIA Management Library (NVML). For every running model, power usage is sampled every 100ms, and total energy consumption is estimated as the arithmetic mean of the recorded power samples multiplied by the elapsed execution time. While higher sampling frequencies yield a more detailed power profile, we adopt a 10Hz sampling rate, consistent with prior work, to avoid the runtime overhead associated with more frequent measurements. The reported power values represent net consumption, computed by subtracting the idle power of the GPU from the measured power. To measure GPU idle power, we executed the nvidia-smi command for 340 seconds, collecting 3400 samples at 100 ms intervals. 3400 collected observations provide a 98% confidence level that the true power consumption lies within ±2% of the observed values. The exact command we have used is provided in the replication package. The mean measured idle power of the GPU was 46.82 W.

All experiments were conducted on a cluster equipped with an NVIDIA A100 80GB PCIe GPU configured in “High Performance” mode, two AMD 7313 CPUs running at 3 GHz with 1 TB of system memory and 32 MB cache, and AlmaLinux 8.10 (64-bit) operating system configured with the “Performance” CPU governor. Each experiment was repeated three times to mitigate transient fluctuations, and the reported values represent the average across the three runs. No other jobs were allowed to run on the GPU during the experiments.

Dataset

Repobench is designed for repository-level auto code completion. We used the code completion subset, which focuses on next-line prediction using three distinct settings: Cross-File-First simulates predicting code that hasn’t yet appeared in the current file. This is the hardest task that requires LLMs to know about the external files. In Cross-File-Random cases, a random and non-first occurrence of a cross-file line is masked, so the code has already been partially introduced in the file, allowing the LLMs to leverage prior in-file context. Finally, the In-File split contains cases within a single file, where an in-file line unrelated to cross-file modules is masked. Compared to other repository-level benchmarks for code completion, Repobench supports a wide range of context sizes, varying from 2000 to 128000 input tokens. This makes it particularly suitable for our study, as it allows us to better investigate the effect of input length on energy consumption. Considering the limitations imposed by the context length of the LLMs under examination, we were only able to carry out experiments on the data with a maximum of 32000 as their context limit. Then, for each context level, 100 samples were extracted for each split (300), resulting in 2100 code completion problems. McEval is a multilingual code evaluation benchmark, covering 40 languages. Its code completion task can be categorized into single-line completion, multi-line completion, and span completion. In single-line completion, only one line of code is masked, whereas in the other two settings multiple lines are masked. In multi-line completion, the masked lines are dispersed throughout the code, while in span completion they appear consecutively as a single block. To evaluate LLM performance for FIM purposes across different programming languages, we selected Python because it is the most widely used language for machine learning development, Java as a representative of popular compiled languages, and Rust as a less common but still mainstream language, reflecting scenarios where training data is relatively limited. The selected McEval subsets contain 340 Python, 355 Java, and 343 Rust completion tasks. While other languages such as C# or C++, could also be included, we deliberately limited our selection to these three for practical reasons. This choice can be acknowledged as a potential threat to validity.

Performance metrics

For the generated code in the McEval dataset, we utilized the Docker container prepared by the dataset authors to compute Pass@1 accuracy based on the provided test cases. This metric corresponds to the Plausible@1 criterion recommended in recent LLM evaluation guidelines. Since McEval consists of relatively small and self-contained examples, it is feasible to execute the generated code and verify correctness through automated testing. All necessary environments are preinstalled in the Docker image, and the correctness is assessed by executing the generated code against the provided tests. This approach is better suited for this use case, where no cross-file repository context is involved, ensuring that the evaluation reflects functional correctness rather than syntactic similarity.

In contrast, applying execution-based evaluation to RepoBench would require resolving repository dependencies and building complete software systems, which would substantially limit the scale and reproducibility of this study. Therefore, for RepoBench, we rely on similarity-based metrics instead. This approach is better suited for the repository-level setting while still allowing us to evaluate how well the generated code aligns with the expected implementation and project-wide conventions.

RQ2: What is the relative influence of input and output token counts on total energy consumption, and how do these drivers interact with model sc

The interaction between input tokens and active parameter count is also statistically significant, indicating that the energy impact of increasing context size becomes larger for bigger models. Similarly, the interaction between input and output tokens is significant, suggesting that generation becomes more expensive when conditioned on larger contexts. However, the interaction between output tokens and parameter count is not statistically significant, likely because the variation in generated output length is relatively limited in RepoBench compared to the variation in input size.

Bit width also has a statistically significant effect on energy consumption. Compared to the Q4 baseline, Q8 and FP16 variants require additional energy, confirming that quantization (lower bit width) can improve energy efficiency even after controlling for token counts and parameter count. Moreover, the programming language variable is statistically significant, suggesting that language-specific characteristics such as tokenization patterns and repository structure may influence energy consumption in long-context workloads.

The interaction between output tokens and parameter count is highly significant in McEval, indicating that generating longer outputs becomes increasingly expensive for larger models. In contrast, the interactions involving input tokens are not statistically significant, which aligns with the relatively limited variation in prompt length in this benchmark. Quantization effects remain statistically significant, with FP16 models showing substantially higher energy consumption than Q4 variants. However, unlike RepoBench, the programming language variables are not statistically significant after controlling for token counts and parameter count, suggesting that language-specific effects become less influential when the workload is dominated by generation rather than long-context processing. The regression behavior closely matches the intended workload characteristics of the two benchmarks.

Recent research on LLMs for software engineering (SE) focuses on improving code completion accuracy, while the inference energy footprints remain underexplored. A systematic review shows that 76% of Green AI literature was published recently and nearly half of these primary studies focus only on the training phase. Most remaining inference benchmarks are algorithm-agnostic or use image datasets. This leaves open questions about how inference energy scales across programming languages, context windows, and model precisions.

Several studies have investigated LLM-based code completion from an accuracy perspective, including efficient training strategies for fill-in-the-middle (FIM) models, syntax-aware infilling benchmarks, practical IDE-based evaluation settings, alignment techniques for improving code generation quality, and empirical analyses of LLM-generated software quality. These studies provide valuable insights into code completion performance and software quality, but they do not primarily analyze the energy cost of inference.

Repository-level code completion has also received increasing attention, since real-world code completion often depends on information across multiple files. Recent studies emphasize long-context reasoning and cross-file dependency modeling through retrieval augmentation and contextual integration strategies. Zhang et al. proposed RepoCoder, which combines retrieval and generation for repository-level code completion, while Ding et al. studied code completion by jointly modeling in-file and cross-file context. Recent work extends repository-level completion to specific domains, such as RTL code completion, and API-centric repository-level code completion. These studies emphasize repository context and retrieval, but they mainly evaluate completion quality rather than the energy implications of processing larger contexts.

Threats to Validity

A potential threat to internal validity relates to the occasional incomplete responses returned by the Ollama API. In a small number of cases (typically one or two prompts per model), the model failed to return a complete generation and skipped the query. This issue became more noticeable in RepoBench under large context sizes (e.g., beyond 16K tokens), where missing a single long-running prompt could noticeably reduce the measured elapsed time and energy consumption, potentially making some FP16 models appear more energy-efficient than lower-bit quantized variants. To mitigate this issue, we manually inspected the results and excluded incomplete executions when computing the energy cost per generated token. Another threat to internal validity arises from the limited number of repetitions per experimental configuration. Each setup was executed three times to capture transient runtime variability while keeping the overall computational cost manageable. Increasing the number of repetitions could further improve statistical confidence, but would significantly increase the required execution time and resource usage. Nevertheless, since each run processes hundreds of prompts over several minutes and GPU power is sampled at 10Hz, the measurements exhibit relatively stable utilization patterns, reducing the impact of transient fluctuations. Another threat concerns the approximation used for energy estimation. Total energy consumption was computed using the arithmetic mean of the sampled GPU power values multiplied by the elapsed execution time, rather than performing numerical integration over the full power trace. To assess the impact of this approximation, we conducted an additional validation experiment on the Java subset of RepoBench. The observed discrepancy between the two approaches remained small, with an average difference of 0.46% and a maximum deviation of 2.3%. Finally, energy was measured using a software-based GPU power profiler rather than external hardware instruments, which may affect measurement precision. However, the same procedure was applied consistently across all configurations.

A potential threat to external validity of our study concerns the selection of programming languages. Although Python, Java, and Rust cover dynamically typed, statically typed, and relatively lower-resource mainstream languages, the results may not generalize to all programming ecosystems or domain-specific languages. Another potential threat to external validity is that the measurements on the A100 platform are limited to GPU power obtained through NVML, since privileged access required for CPU-side energy measurements was unavailable on the cluster. Consequently, the reported energy values do not include the contribution of CPU, DRAM, or PCIe communication overheads. Although this may lead to an underestimation of total system-level energy consumption, all experiments were conducted under identical hardware configurations and comparable data transfer conditions, which helps preserve the validity of fair comparisons across models and workloads.

A potential threat to conclusion validity concerns regression assumptions. Diagnostic Q-Q plots exhibit deviations from normality in the residual tails. Alternative specifications using a log-transformed outcome and Gamma regression did not consistently improve the diagnostics. Therefore, we acknowledge these deviations as a limitation of the analysis.

Conclusion

This study investigated the trade-off between accuracy and energy consumption in LLM-based code completion across different programming languages, context sizes, and completion workloads. Using RepoBench and McEval, we evaluated a total of 25 open-weight LLMs under long-context repository-level completion and generation-heavy fill-in-the-middle completion scenarios. Our results show that the dominant drivers of energy consumption depend strongly on the characteristics of the completion task. In long-context workloads such as RepoBench, energy consumption is primarily influenced by input context size and its interaction with model scale. In contrast, generation-heavy workloads such as McEval are mainly driven by output generation and its interaction with active parameter count. These findings indicate that different software engineering tasks stress different components of LLM inference. We further observed that output generation is substantially more energy-intensive per token than prompt processing. In addition, increasing context size consistently raised the energy cost per generated token, while the corresponding improvements in completion quality were often limited and highly model-dependent. Across both benchmarks, smaller and heavily quantized models frequently achieved Pareto-optimal trade-offs, often providing accuracy comparable to larger full precision models while consuming substantially less energy. Moreover, model rankings in terms of energy efficiency were not stable across context sizes, suggesting that certain model families scale more efficiently under long-context workloads. Overall, our findings demonstrate that larger models and longer contexts do not necessarily provide proportionally better completion quality, emphasizing the importance of energy-aware model selection and deployment strategies for AI-assisted software engineering tools.

Future work could complement our regression analysis with controlled ablation studies that vary one factor at a time while keeping others fixed, enabling a more precise understanding of how context length, output length, quantization, and model scale influence energy consumption. In addition, extending this analysis to emerging agentic workflows involving iterative multi-turn interactions, self-correction, and tool usage would help better understand the sustainability challenges of large-scale AI-assisted software engineering systems.