Skip to main content
QUICK REVIEW

[论文解读] GitHub Copilot: the perfect Code compLeeter?

Ilja Siroš, Dave Singelée|arXiv (Cornell University)|Jun 17, 2024
Distributed and Parallel Computing Systems被引用 4
一句话总结

本论文通过自动化框架,在 1,760 个 LeetCode 问题上评估了 GitHub Copilot 在 Java、C++、Python3 和 Rust 四种编程语言中的代码生成质量。研究发现,Copilot 在 Java 和 C++ 中最为可靠,生成的代码效率高于平均人类提交,但在 Python3 和 Rust 中存在正确性和一致性问题,且其排名靠前的建议并不总是最优解。

ABSTRACT

This paper aims to evaluate GitHub Copilot's generated code quality based on the LeetCode problem set using a custom automated framework. We evaluate the results of Copilot for 4 programming languages: Java, C++, Python3 and Rust. We aim to evaluate Copilot's reliability in the code generation stage, the correctness of the generated code and its dependency on the programming language, problem's difficulty level and problem's topic. In addition to that, we evaluate code's time and memory efficiency and compare it to the average human results. In total, we generate solutions for 1760 problems for each programming language and evaluate all the Copilot's suggestions for each problem, resulting in over 50000 submissions to LeetCode spread over a 2-month period. We found that Copilot successfully solved most of the problems. However, Copilot was rather more successful in generating code in Java and C++ than in Python3 and Rust. Moreover, in case of Python3 Copilot proved to be rather unreliable in the code generation phase. We also discovered that Copilot's top-ranked suggestions are not always the best. In addition, we analysed how the topic of the problem impacts the correctness rate. Finally, based on statistics information from LeetCode, we can conclude that Copilot generates more efficient code than an average human.

研究动机与目标

  • 系统评估 GitHub Copilot 在生成编程问题代码时的可靠性、正确性和效率。
  • 研究代码质量在不同编程语言、问题难度、主题和建议排名之间的差异。
  • 将 Copilot 生成的代码性能与 LeetCode 上平均人类提交的代码在时间和内存效率方面进行对比。
  • 评估提示上下文和潜在复现(训练数据重复)对 Copilot 输出的影响。
  • 利用 LeetCode 作为测试平台,提供一个可复现的自动化基准,用于评估 AI 生成的代码。

提出的方法

  • 使用自动化框架为四种编程语言中所有公开的、单函数 LeetCode 问题生成并测试 Copilot 的建议。
  • 针对每个问题,多次查询 Copilot 以收集所有建议的解决方案,随后将这些方案提交至 LeetCode 的自动化测试套件。
  • 正确性由 LeetCode 的测试结果判定;效率通过 LeetCode 提供的运行时间和内存消耗指标进行测量。
  • 通过统计分析比较 Copilot 在不同编程语言、问题难度等级(简单/中等/困难)和问题主题上的表现。
  • 复现检测通过在 Copilot 输出中搜索 LeetCode 链接来实现,以识别可能来自训练数据的泄露。
  • 结果汇总了每种语言 1,760 个问题,总计在两个月内提交超过 50,000 次。
Figure 1: Example of a LeetCode problem. On the left part of the figure, the problem description is shown and some examples are mentioned together with the constraints imposed on the solution by LeetCode. The right part of the figure shows the solution template for the chosen programming language, c
Figure 1: Example of a LeetCode problem. On the left part of the figure, the problem description is shown and some examples are mentioned together with the constraints imposed on the solution by LeetCode. The right part of the figure shows the solution template for the chosen programming language, c

实验结果

研究问题

  • RQ1RQ1:Copilot 在代码生成阶段的可靠性如何?其建议数量和失败率在不同编程语言中如何变化?
  • RQ2RQ2:Copilot 建议的正确性如何受编程语言、问题难度、建议排名和问题主题的影响?
  • RQ3RQ3:Copilot 生成的正确解决方案在时间和内存效率上与 LeetCode 上平均人类提交相比如何?
  • RQ4RQ4:Copilot 输出中复现(已知解法的重复)现象在多大程度上存在,尤其是在 LeetCode 问题中?

主要发现

  • Copilot 在 Java 和 C++ 中的代码生成可靠性高于 Python3 和 Rust,生成失败更少,且每个问题的建议数量更多。
  • 在所有语言中,Copilot 的正确率均超过 72%,且在 Java 和 C++ 中显著高于 Python3 和 Rust。
  • 排名第一的 Copilot 建议不总是最优解;需要评估多个建议才能找到最佳方案。
  • 在各类问题主题中,桶排序(Bucket Sort)的正确率最高,而树相关问题的正确率最低。
  • Copilot 生成的代码在时间和内存效率上优于 LeetCode 上平均人类提交的代码,表明其在效率指标上表现更优。
  • 在 1,760 个问题中观察到 5 例复现现象,全部出现在 Python3 中,Copilot 在输出中包含了无法运行的 LeetCode 链接,表明其可能接触过训练数据。
Figure 2: The code of the problem before invoking Copilot. The problem’s description is added as a comment above the code template to give Copilot a context to generate a solution. Before invoking Copilot, the mouse cursor is placed inside the function that we want Copilot to generate. In this examp
Figure 2: The code of the problem before invoking Copilot. The problem’s description is added as a comment above the code template to give Copilot a context to generate a solution. Before invoking Copilot, the mouse cursor is placed inside the function that we want Copilot to generate. In this examp

更好的研究,从现在开始

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

无需绑定信用卡

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