Abstract
Measuring the efficiency of code generated by Large Language Models (LLMs) requires test cases that expose algorithmic bottlenecks. Traditional correctness tests or simple large-scale inputs often fail to trigger these nuanced performance issues. We introduce WEDGE, a framework that decomposes the task of generating stress tests into local performance reasoning (handled by an LLM) and global input search (handled by a coverage-guided fuzzer). By synthesizing "performance-characterizing constraints," WEDGE generates highly effective test cases. Our benchmark, PERFFORGE, demonstrates that WEDGE-generated tests cause significantly greater slowdowns than existing methods, ultimately helping LLMs produce more optimized code.
Introduction
As LLMs are increasingly deployed for code generation and optimization, the need for robust performance evaluation becomes critical. Standard benchmarks typically rely on correctness tests, which ensure the code works but do not necessarily stress its efficiency. Naive attempts to generate performance-stressing inputs often focus solely on increasing input size. However, many performance bottlenecks are structural rather than purely size-dependent—for instance, a specific data distribution that triggers worst-case complexity in a sorting or search algorithm.
Directly asking an LLM to generate these worst-case inputs is often unsuccessful because it requires reasoning across the entire program's logic to the raw input format. WEDGE addresses this by leveraging the LLM's strength in local code analysis while using a fuzzer to navigate the input space.
The WEDGE Framework
WEDGE operates through a three-stage pipeline designed to bridge the gap between high-level code reasoning and low-level input generation.
- Contrastive Execution Profiling: The process begins by running the target program on existing tests to identify pairs of "fast" and "slow" inputs of comparable sizes. Profiling these runs highlights specific lines of code that are disproportionately executed during slow runs.
- Constraint Synthesis: An LLM is prompted with the code and the contrastive profile data. It identifies the root cause of the slowdown and generates a C++ checker function—a "performance-characterizing constraint" (PC-constraint). This checker is then instrumented into the original code.
- Constraint-Guided Fuzzing: The instrumented code is fed into a coverage-guided fuzzer (AFL++). The fuzzer's natural objective to maximize code coverage drives it to find inputs that trigger the newly added checker branches. To improve efficiency, the LLM also generates a custom, constraint-aware input mutator.
Experimental Evaluation and Results
The authors evaluated WEDGE using a subset of the CodeContests dataset, comprising 154 problems and over 33,000 C++ programs. The resulting stress tests are released as the PERFFORGE benchmark.
Key findings include:
- Superior Stress Testing: Tests generated by WEDGE resulted in an average of 84.5% more CPU instructions compared to state-of-the-art LLM test generators like EvalPerf.
- Significant Slowdowns: Compared to standard correctness tests, WEDGE's inputs introduced an average slowdown of 363x.
- Feedback-Driven Optimization: Using WEDGE's tests as execution feedback for an iterative LLM code optimizer improved the resulting code's efficiency by 24%, a 10 percentage point gain over using default tests.
Conclusion
WEDGE demonstrates that the key to effective performance testing lies in identifying structural algorithmic weaknesses rather than just increasing input volume. By combining LLM-based reasoning with coverage-guided fuzzing, WEDGE provides a scalable way to generate high-quality stress tests. While the framework currently faces challenges with computational overhead and very large inputs, it establishes a powerful new paradigm for evaluating and improving the efficiency of AI-generated code.
Summary updated