[论文解读] Evaluating the Code Quality of AI-Assisted Code Generation Tools: An Empirical Study on GitHub Copilot, Amazon CodeWhisperer, and ChatGPT
基于 HumanEval 基准,在代码质量方面对 GitHub Copilot、Amazon CodeWhisperer 和 ChatGPT 进行了实证比较,衡量有效性、正确性、安全性、可靠性和可维护性。
Context: AI-assisted code generation tools have become increasingly prevalent in software engineering, offering the ability to generate code from natural language prompts or partial code inputs. Notable examples of these tools include GitHub Copilot, Amazon CodeWhisperer, and OpenAI's ChatGPT. Objective: This study aims to compare the performance of these prominent code generation tools in terms of code quality metrics, such as Code Validity, Code Correctness, Code Security, Code Reliability, and Code Maintainability, to identify their strengths and shortcomings. Method: We assess the code generation capabilities of GitHub Copilot, Amazon CodeWhisperer, and ChatGPT using the benchmark HumanEval Dataset. The generated code is then evaluated based on the proposed code quality metrics. Results: Our analysis reveals that the latest versions of ChatGPT, GitHub Copilot, and Amazon CodeWhisperer generate correct code 65.2%, 46.3%, and 31.1% of the time, respectively. In comparison, the newer versions of GitHub CoPilot and Amazon CodeWhisperer showed improvement rates of 18% for GitHub Copilot and 7% for Amazon CodeWhisperer. The average technical debt, considering code smells, was found to be 8.9 minutes for ChatGPT, 9.1 minutes for GitHub Copilot, and 5.6 minutes for Amazon CodeWhisperer. Conclusions: This study highlights the strengths and weaknesses of some of the most popular code generation tools, providing valuable insights for practitioners. By comparing these generators, our results may assist practitioners in selecting the optimal tool for specific tasks, enhancing their decision-making process.
研究动机与目标
- 在真实世界的提示上评估领先的 AI 辅助代码生成器的整体代码质量。
- 识别生成代码在有效性、正确性、安全性、可靠性和可维护性方面的优点与不足。
- 检查文档字符串和有意义的函数名如何影响代码质量。
- 跟踪工具随时间的演变,以了解各版本的改进。
提出的方法
- 以包含函数提示、文档字符串和单元测试的 HumanEval 数据集作为评估基础。
- 在典型的 IDE/浏览器环境中使用 GitHub Copilot、Amazon CodeWhisperer 和 ChatGPT 生成代码。
- 通过直接在 Python 中执行来评估代码有效性,以检测语法/运行时错误。
- 通过单元测试评估代码正确性;将 Code Correctness Score 计算为通过测试数除以总测试数。
- 使用 SonarQube 测量 Code Security(漏洞)、Code Reliability(缺陷)和 Code Maintainability(代码异味/可维护性)。
- 进行两个额外实验:(i) 移除文档字符串以测试输入的影响(RQ2),(ii) 替换为虚拟函数名以测试命名的影响(RQ3)。
- 通过测试更新后的工具版本来比较随时间的表现(RQ4)。

实验结果
研究问题
- RQ1RQ1:就有效性、正确性、安全性、可靠性和可维护性而言,工具生成的代码质量如何?
- RQ2RQ2:文档字符串对生成代码质量有何影响?
- RQ3RQ3:使用有意义的函数名对生成代码质量有何影响?
- RQ4RQ4:代码生成工具在不同版本之间如何演变?
主要发现
- 在三种工具中,ChatGPT 具有最高的有效性(93.3%),正确性(65.2% 正确),以及平均正确性(78.1%)。
- GitHub Copilot 对 91.5% 的问题生成了有效代码,46.3% 的解答正确;30.5% 不正确,23.2% 部分正确。
- Amazon CodeWhisperer 对 90.2% 的问题生成了有效代码,31.1% 的解答正确;28.7% 不正确,40.2% 部分正确。
- 在安全性/可靠性/可维护性方面的代码质量未出现低于最大阈值的安全评级;Copilot、CodeWhisperer 和 ChatGPT 在部分问题中各自出现了少量的错误或代码异味(Copilot:3 个错误;CodeWhisperer:1 个错误;ChatGPT:2 个错误;可维护性异味在工具间差异较大)。
- 移除文档字符串(RQ2)在仅提供函数签名时显著降低了正确性(例如,Copilot 的正确性从 46.3% 降至 20.1%;CodeWhisperer 从 31.1% 降至 14.6%;ChatGPT 从 65.2% 降至 22.0%)。
- 使用虚拟函数名(RQ3)通常降低了有效性和正确性,但保留了一定的有用性;有效性维持在较高水平,但正确性下降(例如 Copilot 原始版本的 46.3% 正确,与使用虚拟名称时的 42.1% 相比)。
- 随时间(RQ4)的变化,Copilot 的有效性在较新版本中保持在约 91.5%;CodeWhisperer 的有效性从早期结果的 95.1% 降至现在的 90.2%。

阅读本论文
在 Nubint 阅读器中打开原文,边读边就任意段落提问。
在 Nubint 中阅读本论文本解读由 AI 根据论文原文生成,引用前请核对原文。