COFFE: A Code Efficiency Benchmark for Code Generation
Yun Peng, Jun Wan, Yichen Li, Xiaoxue Ren
TL;DR
COFFE introduces a time-efficiency benchmark for LLM-generated code by integrating STGen-stressed test cases with a CPU-instruction-based metric, Efficient@k, to jointly evaluate correctness and speed. The methodology combines curated data from multiple correctness benchmarks, contract-guided stress-test generation, and a three-phase STGen pipeline to produce high-quality, long-input test cases. Empirical results show CPU instruction count is a far more stable and linearly correlated proxy for time than execution time, and STGen markedly improves the ability to distinguish time efficiency across code solutions. Across 14 open-source and 4 closed-source LLMs, current models largely excel at correctness but struggle to produce time-efficient implementations, with larger models offering limited gains in efficient code generation, especially for file-level tasks.
Abstract
Code generation has largely improved development efficiency in the era of large language models (LLMs). With the ability to follow instructions, current LLMs can be prompted to generate code solutions given detailed descriptions in natural language. Many research efforts are being devoted to improving the correctness of LLM-generated code, and many benchmarks are proposed to evaluate the correctness comprehensively. Despite the focus on correctness, the time efficiency of LLM-generated code solutions is under-explored. Current correctness benchmarks are not suitable for time efficiency evaluation since their test cases cannot well distinguish the time efficiency of different code solutions. Besides, the current execution time measurement is not stable and comprehensive, threatening the validity of the time efficiency evaluation. To address the challenges in the time efficiency evaluation of code generation, we propose COFFE, a code generation benchmark for evaluating the time efficiency of LLM-generated code solutions. COFFE contains 398 and 358 problems for function-level and file-level code generation, respectively. To improve the distinguishability, we design a novel stressful test case generation approach with contracts and two new formats of test cases to improve the accuracy of generation. For the time evaluation metric, we propose efficienct@k based on CPU instruction count to ensure a stable and solid comparison between different solutions. We evaluate 14 popular LLMs on COFFE and identify four findings. Based on the findings, we draw some implications for LLM researchers and software practitioners to facilitate future research and usage of LLMs in code generation.
