NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Evaluating Language Models for Efficient Code Generation

Jiawei Liu, Songrun Xie, Junhao Wang, Yuxiang Wei, Yifeng Ding, Lingming Zhang

TL;DR

This paper introduces Differential Performance Evaluation (DPE), a novel framework and benchmark (EVALPERF) for reliably assessing the code efficiency of Large Language Models (LLMs). DPE addresses the limitations of existing benchmarks by generating computationally demanding test cases and using a more insightful metric than simple speedup, revealing surprising findings about LLM efficiency.

What Problem Does This Paper Address?

The increasing prevalence of LLMs in code generation necessitates robust evaluation methods. While functional correctness has been extensively studied, code efficiency remains a critical but underexplored aspect. Existing benchmarks often fall short because they:

  • Use simplistic test inputs: These don't stress the computational demands of generated code, making efficiency differences negligible.
  • Lack effective compound metrics: Simple metrics like average speedup can be misleading due to the wide variation in performance across different tasks.

This gap makes it difficult to truly understand and improve the efficiency of LLM-generated code, which is crucial for building high-quality, scalable, and cost-effective software.

Methods

The paper proposes Differential Performance Evaluation (DPE), a two-phase framework:

  1. Dataset Curation (EVALPERF):
    • Valid Solution Curation: Collects correct code solutions from various LLMs for existing programming tasks.
  2. Synthesizing a Synthesizer (SAS): A novel technique that prompts LLMs to generate "test generators." These generators, in turn, produce computationally expensive test inputs tailored to stress code efficiency. This is a key innovation, as directly generating complex inputs is challenging.
  3. Performance-Exercising Task Selection: Filters tasks to ensure they are computationally demanding and exhibit performance variation.
  4. Adaptive Performance Clustering: Groups validated solutions by their efficiency characteristics to create reference points.
  5. Code Efficiency Evaluation:
    • Profiling: New LLM-generated solutions are profiled (using hardware performance counters for instruction count) on the generated performance-exercising inputs.
  6. Differential Performance Score (DPS): The efficiency of a new solution is scored by comparing its performance against the clustered reference solutions. The score represents the percentile of reference solutions that are slower than the evaluated solution, providing a more stable and interpretable metric than raw speedup.

Datasets

  • Existing Benchmarks: HumanEval and MBPP were used as the source for programming tasks.
  • New Benchmark: EVALPERF: Created using the DPE framework, EVALPERF consists of 121 performance-challenging coding tasks with computationally expensive test inputs.

Key Insights and Ideas

  • The "Scaling Law" Doesn't Hold for Efficiency: While larger models generally improve correctness, the paper finds that code efficiency doesn't consistently scale with model size. This is a surprising finding that challenges conventional wisdom in LLM development.
  • General Instruction Tuning Boosts Efficiency: Surprisingly, instruction tuning, even when not explicitly optimized for efficiency, significantly improves both code correctness and efficiency. This suggests that instruction tuning might implicitly teach models better coding practices.
  • Prompting for Efficiency is Hard: Specialized prompts designed to encourage efficient code generation ("perf-instruct," "perf-CoT") did not consistently outperform basic instruction-tuned models. This indicates LLMs still struggle to reliably follow such nuanced instructions.
  • Hardware Performance Counters are Key: Using hardware performance counters (like instruction counts) provides a more stable and reproducible measure of performance compared to physical runtime, especially in noisy environments.
  • EVALPERF is Reliable and Cross-Platform: The new benchmark and evaluation methodology demonstrate consistent results across different hardware configurations, highlighting its robustness.

Key Results

  • EVALPERF Benchmark: Created with 121 performance-challenging tasks, significantly improving the computational demand of test inputs compared to existing methods (e.g., 4.8x improvement in retained tasks over EvalPlus).
  • Instruction Tuning Impact: Instruction-tuned models showed notable improvements in DPS (e.g., DeepSeekCoder-6.7B improved by 19% over its base model).
  • Model Size vs. Efficiency: While larger models often improve correctness, efficiency gains were inconsistent. In some cases, larger models even showed performance degradation.
  • Prompting Effectiveness: Performance-specific prompts showed minimal consistent gains in efficiency and sometimes led to correctness degradation.
  • Cross-Platform Consistency: EVALPERF exhibited very consistent results across different test beds, with a maximum coefficient of variation of only 0.4%.

Limitations and Future Work

  • Limitations:
    • The paper acknowledges that DPS is not "free" as it requires collecting reference solutions with diverse efficiency levels.
  • While hardware counters are generally reliable, they might still vary slightly across platforms due to underlying hardware and software settings. However, the DPE framework's relative scoring mitigates this.
  • Future Work:
    • The authors plan to continuously extend EVALPERF with more coding tasks.
  • Further research is needed to understand and improve the explicit optimization of code efficiency in LLMs, especially concerning the scaling law and instruction following for efficiency.

Summary updated

BibTeX
@inproceedings{liu2024evaluating,
  author = {Jiawei Liu and Songrun Xie and Junhao Wang and Yuxiang Wei and Yifeng Ding and LINGMING ZHANG},
  title = {{Evaluating Language Models for Efficient Code Generation}},
  booktitle = {COLM},
  year = {2024},
  url = {https://openreview.net/forum?id=IBCBMeAhmC},
}
Figure