重新思考代码优化:学习判断代码效率
Rethinking Code Refinement: Learning to Judge Code Efficiency
AI总结:
针对代码优化后效率未必提升且逐次运行比对耗时的问题,提出基于代码语言模型的代码效率判断方法,可分类更优代码或预测提升幅度,经多语言多步骤验证有效。
摘要:
大语言模型(LLMs)在代码理解与生成方面已展现出令人瞩目的能力。基于这些能力,近期众多方法被提出以利用LLMs自动优化代码。然而,我们应当重新审视:经LLMs甚至人类优化后的代码,其效率并非总能高于原始版本。另一方面,每次都运行两个不同版本的代码并进行比较并不理想,且十分耗时。因此,在本研究中,我们提出了一种基于代码语言模型的新方法,该模型经训练后可判断两段不同代码(由人类和机器生成)之间的效率差异,方式为分类出更优的代码或预测相对提升幅度。我们在多种编程语言、多个优化步骤上验证了该方法,结果表明所提方法能够有效区分效率更高和更低的代码版本。
英文摘要:
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.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。