Abstract
Evaluating Large Language Models (LLMs) on code generation requires execution-based benchmarks to ensure functional correctness. However, existing benchmarks are either limited to simple algorithmic puzzles or suffer from significant selection bias due to the manual effort required for environment setup. We introduce CodeBenchGen, a framework that automates the transformation of "wild" code fragments into rigorous, execution-based benchmarks using LLMs. By automating sandboxing and test generation, we produced Exec-CSN, a dataset of 1,931 examples across 367 repositories. Our results indicate that real-world code remains a significant challenge for current models, with GPT-4 achieving a Pass@1 score of only 37.21%.
Introduction
The evaluation of AI-driven code generation has historically faced a trade-off between scale and rigor. Static metrics like BLEU or CodeBLEU fail to capture functional correctness, while execution-based benchmarks like HumanEval are often restricted to isolated, competitive-programming style problems. To bridge this gap, researchers from Carnegie Mellon and Shanghai Jiao Tong University developed CodeBenchGen, a system designed to scale execution-based evaluation to real-world software repositories.
The Problem: Scalability and Bias
Traditional methods for creating execution-based benchmarks rely on manual curation or mining mature repositories with existing test suites. Manual curation is not scalable, while repository mining introduces a "success bias," where benchmarks only reflect highly maintained projects. Previous efforts like RepoEval often filter out over 90% of potential repositories due to complex environment dependencies.
CodeBenchGen addresses these issues by using LLMs to handle the "hard part" of benchmarking: setting up isolated environments and generating comprehensive test cases for arbitrary code fragments.
Methodology: The CodeBenchGen Pipeline
The CodeBenchGen framework operates through a four-stage pipeline, primarily powered by GPT-4, to ensure that raw code fragments are converted into functional evaluation units.
- Sandboxing: The system identifies dependencies and "sandboxes" the code by mocking external API calls, creating dummy local files, and resolving imports to allow execution in isolation.
- Test Generation: The LLM generates at least three test cases with multiple assertions to verify the target code's functionality.
- Iterative Execution and Debugging: The system executes the ground-truth code against the generated tests. If failures occur, the LLM iteratively debugs the environment, context, or tests until they pass. This ensures the benchmark's "correct" answer is actually functional.
- Post-processing: The system finalizes the example by generating natural language instructions and I/O specifications for model prompting.
The Exec-CSN Dataset
Using this pipeline, the authors created Exec-CSN, derived from the popular CodeSearchNet dataset. Exec-CSN comprises 1,931 examples from 367 GitHub repositories, covering 293 unique libraries and 668 repository topics. Notably, CodeBenchGen successfully converted 90% of the repositories it processed, a massive improvement over the <5.4% retention rate of previous rule-based filtering methods. Analysis shows that the sandboxed code maintains high fidelity to the original source, with an 83% Jaccard similarity in variable names.
Results and Analysis
The researchers evaluated 12 prominent LLMs on Exec-CSN. Key findings include:
- Performance Gap: GPT-4 led the field with a 37.21% Pass@1 score, yet this remains significantly lower than the 81.3% success rate achieved by human experts (CS graduate students).
- Iterative Failure: Unlike humans, who use error messages to pivot their strategies, LLMs often repeat the same mistakes when given multiple attempts to fix failing code.
- Alignment Constraints: Some models, such as CodeLlama-70B, showed lower performance due to over-active safety alignment, refusing to complete tasks it misidentified as "homework help" or "dangerous."
Conclusion
CodeBenchGen demonstrates that LLMs can effectively serve as "benchmark architects," automating the complex software engineering tasks required for rigorous evaluation. By enabling the creation of diverse, execution-based benchmarks from raw source code, this framework provides a more realistic lens through which to view the current capabilities and limitations of AI coders. Future work will focus on supporting complex I/O and interactive debugging environments for models during evaluation.
Summary updated