Introduction
In the current landscape of Large Language Model (LLM) evaluation, functional correctness—often measured by metrics like pass@k—is the primary benchmark for success. However, this focus on whether code simply "passes the tests" overlooks a critical dimension of software engineering: dynamic stability. Two programs may produce the same output for a given input, yet their underlying algorithmic strategies and runtime behaviors can differ drastically. For instance, one solution might employ an efficient $O(n \log n)$ sorting algorithm while another relies on a $O(n^2)$ approach; both are functionally correct, but the latter introduces significant "algorithmic debt" that could lead to system failure under production loads.
This research introduces a framework to quantify the consistency of the underlying logic and performance of LLM-generated code. The authors reveal a "penalty of instability": while increasing sampling temperature helps models discover more correct solutions, it simultaneously makes those solutions significantly more unpredictable and inefficient.
Methodology
The proposed framework moves beyond surface-level syntax (like CodeBLEU) to analyze opcodes—the low-level, platform-independent instructions executed by the Python interpreter. By analyzing these traces, the researchers can determine what the code actually does during execution.
Three primary metrics are introduced to quantify stability:
- Static Canonical Trace Divergence (SCTD): Measures the diversity of algorithmic structures across multiple generated solutions by analyzing compiled Python bytecode.
- Dynamic Canonical Trace Divergence (DCTD): Quantifies the variance in runtime behavior by tracing opcode frequency while the code executes against a test suite.
- Behavioral Expression Factor (BEF): The ratio of SCTD to DCTD. A high BEF indicates "functional redundancy" (multiple ways to achieve the same behavior), while a low BEF indicates "runtime instability" (minor code changes causing massive performance swings).
To ensure these metrics are comparable, the authors utilize statistical distances such as Jensen-Shannon Divergence (JSD), bounding the results between 0 (perfect stability) and 1 (maximal chaos).
Experimental Setup
The study evaluates 11 state-of-the-art LLMs, including GPT-4o, Claude 3.7, and DeepSeek-R1. These models were tested across two major benchmarks:
- BigO(Bench): A dataset specifically designed to evaluate algorithmic complexity and runtime behavior.
- CodeContests: A challenging competitive programming dataset featuring varying difficulty levels and extensive private test suites to ensure rigorous evaluation.
Results and Discussion
The most significant finding is the direct trade-off between diversity and stability. As sampling temperature increases, the stability of functionally correct solutions degrades. This suggests that "correct" solutions in an LLM's latent space are not located on broad, stable plateaus, but rather on narrow "ridges" surrounded by regions of high complexity or failure.
Key observations from the data include:
- Baseline Divergence: Even for correct code, LLMs typically exhibit a static divergence (SCTD) of 3–5% and a dynamic divergence (DCTD) of approximately 1%.
- The Danger of Outliers: While averages remain low, certain problems showed SCTD as high as 20% and DCTD as high as 15%. These outliers represent significant risks for production environments where predictable performance is mandatory.
- Model Comparison: Top-tier models like Claude-3.7-Sonnet and GPT-4o generally demonstrated superior stability compared to smaller open-source models, though all models were susceptible to the temperature-based penalty.
- Orthogonality to Syntax: The researchers found a very low correlation between these stability metrics and traditional metrics like AST-similarity. This confirms that code can look similar while behaving entirely differently at runtime.
Conclusion
As LLMs transition from simple coding assistants to autonomous agents building complex systems, the lack of visibility into algorithmic debt becomes a critical liability. This study demonstrates that functional correctness is an insufficient metric for production-grade code.
Future work should focus on "stability-aware" training objectives, teaching models to prefer efficient computational patterns through execution feedback during the fine-tuning process. Additionally, expanding this analysis to compiled languages like C++ or Rust will be essential to understanding the broader implications of LLM-driven software development.
Summary updated