Skip to main content
QUICK REVIEW

[论文解读] EffiBench: Benchmarking the Efficiency of Automatically Generated Code

Dong Huang, Yuhao Qing|arXiv (Cornell University)|Feb 3, 2024
Software Testing and Debugging Techniques被引用 4
一句话总结

本论文提出了EffiBench,一个包含1,000个来自LeetCode的效率关键型编程问题的基准测试集,每个问题均配有由人类编写的基准解决方案。该研究使用执行时间和内存使用量等指标,评估了21个大型语言模型在代码效率方面的表现,发现GPT-4-turbo生成的代码效率最高——平均仅比基准解决方案慢1.69倍,显著优于其他模型。

ABSTRACT

Code generation models have increasingly become integral to aiding software development. Although current research has thoroughly examined the correctness of the code produced by code generation models, a vital aspect that plays a pivotal role in green computing and sustainability efforts has often been neglected. This paper presents EffiBench, a benchmark with 1,000 efficiency-critical coding problems to assess the efficiency of code generated by code generation models. EffiBench contains a diverse set of LeetCode coding problems. Each problem is paired with an executable human-written canonical solution, which obtains the SOTA efficiency on the LeetCode solution leaderboard. With EffiBench, we empirically examine the ability of 42 large language models (35 open-source and 7 closed-source) to generate efficient code. Our evaluation results demonstrate that the efficiency of the code generated by LLMs is generally worse than the efficiency of human-written canonical solutions. For example, GPT-4 generated code has an average extbf{3.12} times execution time that of the human-written canonical solutions. In the most extreme cases, the execution time and total memory usage of GPT-4 generated code are extbf{13.89} and extbf{43.92} times that of the canonical solutions. The source code of EffiBench is released on https://github.com/huangd1999/EffiBench. We also provide the LeaderBoard at https://huggingface.co/spaces/EffiBench/effibench-leaderboard.

研究动机与目标

  • 解决现有代码生成评估框架中缺乏针对代码效率的基准测试的问题。
  • 识别当前基准测试中过度侧重正确性,而忽视执行时间与内存使用等性能指标的缺陷。
  • 提供一个标准化、自动化的评估框架,用于衡量大型语言模型生成代码的实际效率。
  • 实现对多样化大型语言模型(包括开源与闭源模型)之间效率的系统性比较。
  • 揭示在实际计算工作负载中,大型语言模型生成的代码与人工优化解决方案之间的性能差距。

提出的方法

  • 从LeetCode中选取1,000个对时间与空间复杂度有最优要求的效率关键型编程问题。
  • 为每个问题配对一个可执行的、由人类编写的基准解决方案,该方案在LeetCode上获得了最高的效率评分。
  • 通过多次运行测量执行时间(ET)、归一化执行时间(NET)、最大内存使用量(MU)、归一化最大内存使用量(NMU)、总内存使用量(TMU)以及归一化总内存使用量(NTMU)。
  • 使用自动化执行与性能分析收集性能指标,避免依赖理论时间复杂度分析。
  • 将性能指标相对于基准解决方案进行归一化,以实现跨模型比较。
  • 在一致的输入提示与执行环境中,对21个大型语言模型(13个开源,8个闭源)进行相同基准测试的评估。
(a) Execution time distribution for GPT-3.5 Turbo.
(a) Execution time distribution for GPT-3.5 Turbo.

实验结果

研究问题

  • RQ1不同大型语言模型在生成高效代码方面与人工优化解决方案相比表现如何?
  • RQ2大型语言模型生成代码的效率在多大程度上与理论时间与空间复杂度相关?
  • RQ3在一系列多样化的效率关键型问题中,哪个模型在执行时间与内存使用方面生成的代码最高效?
  • RQ4大型语言模型生成代码的性能指标在多次运行中是否一致?执行时间与内存使用量的变异性如何?
  • RQ5基于运行时的自动化指标能否比理论时间复杂度标注更准确、更客观地评估代码效率?

主要发现

  • 在所有评估模型中,GPT-4-turbo生成的代码效率最高,其平均归一化执行时间(NET)为基准解决方案的1.69倍。
  • GPT-4-turbo生成代码的最坏情况执行时间比基准解决方案慢45.49倍,表明在边界情况下的性能存在显著波动。
  • GPT-3.5-turbo-1106在所有模型中取得了最高的pass@1率(53.1%),但其NET(2.91)仍显著劣于GPT-4-turbo的1.69。
  • PaLM-2-chat-bison与Gemini-pro生成的代码内存使用量显著偏高(分别为91.90 MB与71.95 MB),其NMU值分别为3.35与2.72,表明内存效率较差。
  • Claude-instant-1与GPT-4在执行时间上表现出较高变异性,标准差分别为0.01秒与0.01秒,但其NET值(3.80与2.27)仍显著劣于GPT-4-turbo。
  • 基准解决方案始终优于所有大型语言模型生成的代码,其中GPT-4-turbo表现最接近——平均仅慢1.69倍,表明在实际效率方面仍存在持续差距。
(b) Normalized execution time distribution.
(b) Normalized execution time distribution.

更好的研究,从现在开始

从阅读论文到最终审阅,大幅缩短您的研究时间。

无需绑定信用卡

本解读由 AI 生成,并经人工编辑审核。