While Large Language Models (LLMs) have become remarkably adept at passing functional correctness benchmarks like HumanEval—proving they can write code that works—their ability to write efficient code has been largely ignored. For real-world applications where latency, throughput, and energy consumption matter, correctness is only half the battle.
Existing efficiency evaluations suffer from critical flaws. They often fail to properly handle "right-censored" data (when a program times out, its true execution time is unknown), compare LLM outputs to suboptimal "canonical" reference solutions, and rely on weak test cases that cannot differentiate between an $O(n)$ algorithm and an $O(n^2)$ one. Furthermore, they do not account for how efficiency scales when a model generates multiple attempts.
To address this gap, researchers have introduced ENAMEL (EfficeNcy AutoMatic EvaLuator), a rigorous, high-standard benchmark designed to evaluate the efficiency of LLM-generated code.
Introducing ENAMEL and the eff@k Metric
ENAMEL introduces several technical innovations to rigorously test code efficiency:
- The
eff@kMetric: Generalizing the well-knownpass@kmetric,eff@kmeasures the expected maximum efficiency score among $k$ independent code samples. To make this estimation stable and unbiased, the authors derived a new estimator using Rao-Blackwellization. - Level-Based Evaluation: Instead of a single set of tests, each problem features multiple "levels" of test cases with exponentially increasing input scales. This allows the benchmark to clearly distinguish between different computational complexities.
- Expert-Level References: A human expert designed "gold standard" solutions using the best-known algorithms and implementation-level optimizations, setting a much higher bar than standard canonical solutions.
- Strong Test Case Generators: Expert-curated generators create "worst-case" inputs specifically targeting suboptimal algorithms and corner cases.
The benchmark consists of 142 carefully selected problems from HumanEval and HumanEval+, excluding trivial $O(1)$ tasks.
Key Insights: Correctness $\neq$ Efficiency
A major finding from ENAMEL is that a model can have a high pass@1 score (correctness) but a very low eff@1 score (efficiency). For example, a model might correctly solve a primality test using $O(n)$ trial division, while an expert would use a much faster probabilistic test.
The study reveals that LLMs are often "algorithmically blind." They struggle significantly with algorithm design, rarely utilizing advanced techniques like Suffix Automata or $O(\log n)$ matrix exponentiation unless explicitly guided. Even when the underlying algorithm is correct, LLMs frequently miss language-specific optimizations (like using Python’s str.translate instead of manual loops) that can yield massive speedups.
Furthermore, ENAMEL's rigorous testing exposed flaws in existing benchmarks: 11 canonical solutions in HumanEval and 4 in HumanEval+ were found to be incorrect when subjected to stronger edge-case testing.
Evaluating 30 LLMs: A Wake-Up Call
The researchers evaluated 30 popular LLMs, and the results highlight a significant capability gap in current AI models.
- GPT-4 Turbo Leads, But Falls Short of Experts: While GPT-4 Turbo performed best, it only achieved an
eff@1of 0.470. This means its generated code is, on average, less than half as efficient as an expert's solution. - Widespread Inefficiency: Most evaluated LLMs could not even reach an
eff@1of 0.3. - Scaling $k$ Doesn't Fix Efficiency: The
eff@kscore is consistently lower thanpass@k. As models are allowed more attempts ($k$), they are more likely to find a correct answer, but not necessarily the most efficient one. - Prompt Engineering is Limited: Simply prompting a model to "generate the most efficient algorithm" provided only marginal improvements, suggesting a fundamental lack of algorithmic reasoning capabilities rather than just a misalignment of instructions.
Limitations and Future Directions
While ENAMEL sets a new standard for evaluating code generation, it has limitations. The benchmark currently focuses on standalone functions rather than complex, multi-file software systems. Additionally, it primarily evaluates time efficiency; measuring space (memory) efficiency is a critical next step, especially given common time-space trade-offs in programming.
Creating expert-level benchmarks is highly labor-intensive. Future work may involve collaborating with competitive programming platforms to scale up the dataset. Finally, while the reference solutions are designed by experts, proving they are the absolute mathematical optimum for every problem remains a theoretical challenge. Nonetheless, ENAMEL clearly demonstrates that for LLMs to become true expert programmers, they must learn not just to write code that works, but code that works efficiently.
Summary updated