arXiv:2410.22375cs.SEcs.AI2024-10EMNLP被引 2

用语言模型自动判断代码优劣,避免盲目优化。

Rethinking Code Refinement: Learning to Judge Code Efficiency

  • 训练模型直接对比两段代码效率,无需实际运行测试。
  • 在多语言、多轮优化中准确识别更高效的代码版本。
  • 适合需要快速评估代码性能的开发者与自动化工具。

大型语言模型(LLMs)在理解与生成代码方面表现出色,因此许多方法尝试用LLM自动优化代码。然而,我们应重新思考:由LLM甚至人类生成的优化代码并不总是比原版更高效。每次运行两个版本代码进行对比既不理想也耗时。为此,本文提出一种基于代码语言模型的新方法,该模型可判断两段不同代码(来自人类或机器)之间的效率优劣,通过分类出更优版本或预测相对改进程度实现。我们在多种编程语言和多轮代码优化场景下验证了该方法的有效性,结果表明其能有效区分代码效率高低。

原文摘要 · Abstract (English)

Large Language Models (LLMs) have demonstrated impressive capabilities in understanding and generating codes. Due to these capabilities, many recent methods are proposed to automatically refine the codes with LLMs. However, we should rethink that the refined codes (from LLMs and even humans) are not always more efficient than their original versions. On the other hand, running two different versions of codes and comparing them every time is not ideal and time-consuming. Therefore, in this work, we propose a novel method based on the code language model that is trained to judge the efficiency between two different codes (generated across humans and machines) by either classifying the superior one or predicting the relative improvement. We validate our method on multiple programming languages with multiple refinement steps, demonstrating that the proposed method can effectively distinguish between more and less efficient versions of code.

代码优化大模型效率评估

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。