arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2508.11468cs.SE
收藏

TRACE: 评估基于LLM的代码翻译的执行效率

TRACE: Evaluating Execution Efficiency of LLM-Based Code Translation

Key Lab of HCST (PKU), MOE(北京大学智能语言研究实验室(教育部);计算机科学与技术系);SCS, Peking University(中国科学院软件研究所);Institute of Software, Chinese Academy of Sciences(新加坡国立大学);National University of Singapore(伦敦国王学院);King’s College London(北京大学深圳研究生院电子与计算机工程学院);School of Electronic and Computer Engineering, PKU Shenzhen Graduate School

Zhihao Gong, Zeyu Sun, Dong Huang, Qingyuan Liang, Jie M. Zhang, Dan Hao

AI总结:

本文提出TRACE基准,评估LLM翻译代码的执行效率,发现正确性不等于效率,23.5%的正确翻译存在显著低效,提示需更关注效率评估。

摘要:

尽管大型语言模型(LLM)显著提升了代码翻译的功能正确性,但执行效率这一关键维度却被忽视。我们提出了TRACE,首个专门评估LLM翻译代码效率的基准。TRACE包含1000个关键效率任务,涵盖C++、Java和Python,每个任务均附带压力测试以揭示常被小规模测试忽略的效率退化。使用TRACE,我们对28个代表性LLM进行了广泛评估,揭示了几个关键发现:1)正确性不是效率的可靠代理:正确性领先者Claude-4-think仅达到中等时间效率,被较小的开源LLM如Qwen2.5-Coder-14B-Instruct超越。2)低效既普遍又具模式:23.5%的正确翻译表现出显著低效,分布于算法故障(11.9%)、语言构造不匹配(66.4%)和资源管理不当(21.7%)。3)推理时间提示策略仅带来小幅提升,表明当前LLM缺乏内在效率意识。我们的结果确立了效率作为代码翻译的关键维度,并将TRACE定位为以效率为导向评估的原理基础。

英文摘要:

While Large Language Models (LLMs) have substantially improved the functional correctness of code translation, the critical dimension of execution efficiency remains overlooked. We present \textbf{\textsc{Trace}}, the first benchmark to explicitly assess efficiency in LLM-translated code. \textsc{Trace} includes 1,000 efficiency-critical tasks across C++, Java, and Python, each augmented with stress tests that reveal efficiency disparities often overlooked by small-scale tests. Using \textsc{Trace}, we conduct an extensive evaluation of 28 representative LLMs and highlight several key insights: 1) Correctness and efficiency are often misaligned: the correctness leader Claude-Sonnet-4-Think achieves only moderate time efficiency, outperformed by smaller open-source LLMs such as Qwen2.5-Coder-14B-Instruct. 2) Inefficiency is both prevalent and patterned: 23.5\% of correct translations suffer from notable inefficiency, mainly arising from algorithm implementation discrepancy (11.9\%), language construct mismatch (66.4\%), and resource management inefficiency (21.7\%). 3) Inference-time prompt strategies bring only modest improvements, indicating that simple prompting alone is insufficient to improve translation efficiency. Together, our results establish execution efficiency as an essential dimension of code translation and position \textsc{Trace} as a principled foundation for efficiency-oriented evaluation.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑