Table of Contents
Fetching ...

CodeComplex: Dataset for Worst-Case Time Complexity Prediction

Seung-Yeop Baik, Joonghyuk Hahn, Jungin Kim, Mingi Jeon, Aditi, Yo-Sub Han, Sang-Ki Ko

TL;DR

CodeComplex presents the first large-scale bilingual benchmark (Java and Python) for predicting worst-case code time complexity across seven classes, including $O(1)$, $O(n)$, $O(n^2)$, $O(n^3)$, $O( abla n)$, $O(n abla n)$, and $O(2^n)$, with 9,800 total codes and careful labeling by algorithm experts. It introduces dead-code elimination and input-representation-aware annotation, along with a Hierarchy Complexity Score (HC-Score) to measure near-miss predictions beyond traditional accuracy. The dataset is openly accessible and balanced to avoid class bias, enabling robust evaluation of classical ML models, pre-trained programming language models, and large LLMs, including ChatGPT and open-source alternatives. Empirical results show that while state-of-the-art models achieve promising indications of reasoning capability, substantial gaps remain for reliable deployment, and error analyses reveal systematic confusion around logarithmic loops, boilerplate noise, and Python conciseness. Overall, CodeComplex provides a rigorous, practical benchmark for advancing LLMs’ reasoning in code time-complexity inference with meaningful implications for software optimization and program analysis.

Abstract

Reasoning ability of Large Language Models (LLMs) is a crucial ability, especially in complex decision-making tasks. One significant task to show LLMs' reasoning capability is code time complexity prediction, which involves various intricate factors such as the input range of variables and conditional loops. Current benchmarks fall short of providing a rigorous assessment due to limited data, language constraints, and insufficient labeling. They do not consider time complexity based on input representation and merely evaluate whether predictions fall into the same class, lacking a measure of how close incorrect predictions are to the correct ones. To address these dependencies, we introduce CodeComplex, the first robust and extensive dataset designed to evaluate LLMs' reasoning abilities in predicting code time complexity. CodeComplex comprises 4,900 Java codes and an equivalent number of Python codes, overcoming language and labeling constraints, carefully annotated with complexity labels based on input characteristics by a panel of algorithmic experts. Additionally, we propose specialized evaluation metrics for the reasoning of complexity prediction tasks, offering a more precise and reliable assessment of LLMs' reasoning capabilities. We release our dataset (https://github.com/sybaik1/CodeComplex-Data) and baseline models (https://github.com/sybaik1/CodeComplex-Models) publicly to encourage the relevant (NLP, SE, and PL) communities to utilize and participate in this research.

CodeComplex: Dataset for Worst-Case Time Complexity Prediction

TL;DR

CodeComplex presents the first large-scale bilingual benchmark (Java and Python) for predicting worst-case code time complexity across seven classes, including , , , , , , and , with 9,800 total codes and careful labeling by algorithm experts. It introduces dead-code elimination and input-representation-aware annotation, along with a Hierarchy Complexity Score (HC-Score) to measure near-miss predictions beyond traditional accuracy. The dataset is openly accessible and balanced to avoid class bias, enabling robust evaluation of classical ML models, pre-trained programming language models, and large LLMs, including ChatGPT and open-source alternatives. Empirical results show that while state-of-the-art models achieve promising indications of reasoning capability, substantial gaps remain for reliable deployment, and error analyses reveal systematic confusion around logarithmic loops, boilerplate noise, and Python conciseness. Overall, CodeComplex provides a rigorous, practical benchmark for advancing LLMs’ reasoning in code time-complexity inference with meaningful implications for software optimization and program analysis.

Abstract

Reasoning ability of Large Language Models (LLMs) is a crucial ability, especially in complex decision-making tasks. One significant task to show LLMs' reasoning capability is code time complexity prediction, which involves various intricate factors such as the input range of variables and conditional loops. Current benchmarks fall short of providing a rigorous assessment due to limited data, language constraints, and insufficient labeling. They do not consider time complexity based on input representation and merely evaluate whether predictions fall into the same class, lacking a measure of how close incorrect predictions are to the correct ones. To address these dependencies, we introduce CodeComplex, the first robust and extensive dataset designed to evaluate LLMs' reasoning abilities in predicting code time complexity. CodeComplex comprises 4,900 Java codes and an equivalent number of Python codes, overcoming language and labeling constraints, carefully annotated with complexity labels based on input characteristics by a panel of algorithmic experts. Additionally, we propose specialized evaluation metrics for the reasoning of complexity prediction tasks, offering a more precise and reliable assessment of LLMs' reasoning capabilities. We release our dataset (https://github.com/sybaik1/CodeComplex-Data) and baseline models (https://github.com/sybaik1/CodeComplex-Models) publicly to encourage the relevant (NLP, SE, and PL) communities to utilize and participate in this research.
Paper Structure (39 sections, 2 equations, 11 figures, 12 tables)

This paper contains 39 sections, 2 equations, 11 figures, 12 tables.

Figures (11)

  • Figure 1: Overview of the CodeComplex dataset creation process.
  • Figure 2: Statistics of CodeComplex dataset. The first and second lines are for Java and Python codes, respectively.
  • Figure 3: Classification performance of models for different length groups of codes.
  • Figure 4: Wrong LLM response example.
  • Figure 5: LLM prompt examples used in our experiments.
  • ...and 6 more figures