Skip to main content
QUICK REVIEW

[Paper Review] No Need to Lift a Finger Anymore? Assessing the Quality of Code Generation by ChatGPT

Zhijie Liu, Yutian Tang|arXiv (Cornell University)|Aug 9, 2023
Artificial Intelligence in Healthcare and EducationMedicine3 citations
TL;DR

This study systematically evaluates ChatGPT's code generation capabilities across correctness, complexity, and security in five programming languages (C, C++, Java, Python, JavaScript). Using 728 algorithm problems and 54 CWE-based scenarios, it finds that while ChatGPT generates functionally correct code for pre-2021 problems with a 48.14% higher acceptance rate, its direct bug-fixing ability is weak; however, multi-round fixing resolves over 89% of vulnerabilities, though complexity often increases and non-determinism affects output consistency.

ABSTRACT

Large language models (LLMs) have demonstrated impressive capabilities across various NLP tasks. Additionally, LLMs are also highly valuable in supporting software engineering tasks, particularly in the field of code generation. Automatic code generation is a process of automatically generating source code or executable code based on given specifications or requirements, improving developer productivity. In this study, we perform a systematic empirical assessment to the quality of code generation using ChatGPT. We leverage 728 algorithm problems in five languages (i.e., C, C++, Java, Python, and JavaScript) and 18 CWEs with 54 code scenarios for the code generation task. Our evaluation encompasses a comprehensive analysis of code snippets generated by ChatGPT, focusing on three critical aspects: correctness, complexity, and security. We also specifically investigate ChatGPT's ability to engage in multi-round fixing process (i.e., ChatGPT's dialog ability) of facilitating code generation. By delving into the generated code and examining the experimental results, this work provides valuable insights into the performance of ChatGPT in tackling code generation tasks over the three critical aspects. Overall, our findings uncover potential issues and limitations that arise in the ChatGPT-based code generation and lay the groundwork for improving AI and LLM-based code generation techniques.

Motivation & Objective

  • To evaluate the functional correctness of code generated by ChatGPT across multiple programming languages and problem sets.
  • To analyze the cyclomatic and cognitive complexity of ChatGPT-generated code snippets.
  • To investigate the presence and remediation of security vulnerabilities in generated code using CWE-based scenarios.
  • To assess the effectiveness of multi-round fixing processes in improving code quality.
  • To examine the impact of ChatGPT’s non-determinism on code consistency across correctness, complexity, and security.

Proposed method

  • The study uses 728 algorithm problems from competitive programming platforms, categorized into pre-2021 and post-2021 problem sets.
  • It evaluates code generation across five languages: C, C++, Java, Python, and JavaScript, using standardized judgment platforms.
  • Security vulnerabilities are assessed using 18 CWEs across 54 code scenarios, focusing on common coding flaws.
  • A multi-round fixing process is simulated, where ChatGPT iteratively revises buggy code based on feedback.
  • Complexity metrics—cyclomatic and cognitive—are computed for each generated code snippet to assess structural complexity.
  • Non-determinism is analyzed by generating multiple code samples per prompt and measuring variation in correctness, complexity, and security.

Experimental results

Research questions

  • RQ1How does ChatGPT’s code generation performance vary between pre-2021 and post-2021 algorithm problems in terms of functional correctness?
  • RQ2What is the distribution of cyclomatic and cognitive complexity in code generated by ChatGPT across different programming languages?
  • RQ3To what extent do ChatGPT-generated code snippets contain security vulnerabilities in real-world CWE scenarios?
  • RQ4How effective is the multi-round fixing process in correcting functional bugs and resolving security vulnerabilities in generated code?
  • RQ5How does ChatGPT’s non-determinism affect the consistency of code generation in terms of correctness, complexity, and security?

Key findings

  • ChatGPT achieves a 48.14% higher average Accepted rate on code judgment platforms for pre-2021 algorithm problems compared to post-2021 problems.
  • The multi-round fixing process with ChatGPT is relatively weak in directly correcting erroneous code to achieve functional correctness.
  • Cyclomatic and cognitive complexity levels vary significantly across different programming languages, with complexity generally preserved or increased during multi-round fixing.
  • In C, C++, and Java for algorithmic problems, and in C and Python3 for CWE-based scenarios, ChatGPT-generated code contains relevant security vulnerabilities.
  • The multi-round fixing process successfully resolves 100% of vulnerabilities in C and 89.4% in Python3, demonstrating strong remediation potential.
  • ChatGPT’s non-determinism leads to variations in functional correctness, complexity, and security across multiple generations of the same prompt.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.