DOI: 10.5281/zenodo.18377892
title: AI Code Optimization for Sustainability: Dataset
title: Refactoring Python Code for Energy-Efficiency using Qwen3: Dataset based on HumanEval, MBPP, and Mercury

description: AI Code Optimization for Sustainability: Dataset



Refactoring Python Code for Energy-Efficiency using Qwen3: Dataset based on HumanEval, MBPP, and Mercury


📄 Read the Paper | HuggingFace Mirror | DOI: 10.5281/zenodo.18377893 | About the author

This dataset is a part of a Master thesis research internship investigating the use of LLMs to optimize Python code for energy efficiency. The research was conducted as part of the Greenify My Code (GMC) project at the Netherlands Organisation for Applied Scientific Research (TNO).

The code samples were curated from Mercury paper, dataset, Google MBPP (paper, dataset), and OpenAI HumanEval (paper, dataset) datasets. The 1,763 unique Python code samples analyzed before and after refactoring by Qwen3 models using four inference strategies (prompt and interaction style): cot-code-single, cot-code-plan, cot-suggestions-single, and cot-suggestions-plan. The analysis provides the following information (when possible):



Functional correctness via provided test suites

Static code analysis via Radon, eco-code-analyzer (custom fork used) and custom AST metrics

Runtime profiling in a sandboxed environment using pyRAPL to measure energy consumption (µJ) under synthetic stress load (80% using stress-ng):



baseline: 10ms (no code execution)

warmup: 10ms (running test suite in a loop)

profiling: 1s (running test suite in a loop)




This analysis uses the following versions of Qwen3 models:



0.6B-Q8-GGUF

1.7B-Q8-GGUF

4B-Q8-GGUF

8B-Q8-GGUF

14B-Q8-GGUF

32B-Q8-GGUF


Dataset Structure & Column Descriptions

The dataset is structured hierarchically using dot-notation to separate nodes. The message column provides a status message of the entire process (success means that analysis before, refactoring, and analysis after were all successful)

1. Input Sample Metadata

Information regarding the source code sample.




Column
Description




input.sample_num
Unique index identifier for the sample


input.origin
Source benchmark (Mercury, MBPP, or HumanEval)


input.name
Name of the function/task


input.code
Original Python source code


input.test.initialization
Test setup code to run before executing tests


input.test.assertions
List of assertions used for functional verification




2. Analysis

These suffixes apply to both the original code (analysis_before) and the refactored code (analysis_after).

Static Analysis




Column
Description




analysis_*.static.radon.*
Radon metrics


analysis_*.static.ast.nodes
Total nodes in the Abstract Syntax Tree


analysis_*.static.ast.branching_factor
total_branches divided by nodes_with_children


analysis_*.static.ast.tree_depth
Maximum depth of the AST


analysis_*.static.eco.score
Energy efficiency score (higher is better)


analysis_*.static.eco.suggestions
List of static analysis suggestions for energy improvement




Runtime & Energy Profiling

Measured using pyRAPL. Energy values are in Microjoules (µJ). Metrics starting with ... are the same for baseline, warmup, and profiling




Column
Description




analysis_*.runtime.test.status
Functional correctness status (passed, failed, error)


...duration_us
Phase duration in microseconds


...util_avg_cpu
Average CPU utilization


...util_avg_memory
Average Memory utilization


...pkg_uj
CPU Package Energy


...dram_uj
DRAM Energy


...total_uj
Total Energy (Package + DRAM)


...total_per_rep_uj
Energy per single test execution




3. Greenify/Refactoring Process

Details on the model, prompts, and the refactoring process. Columns starting with ... are the same for plan and refactor phases, however plan may be empty if a single-phase strategy is used.




Column
Description




greenify.meta.input_type
Context provided: just_code or code_with_suggestions


greenify.meta.process_variation
Strategy used: single_phase or plan_then_implement (two-step)


greenify.meta.model.tag
HuggingFace tag of the model


...prompt
The prompt sent to the LLM for code generation


...tokens.*
Token counts (input/output/total) for the given phase


...duration_seconds
Time taken by the LLM to generate output


...rewritten_code
LLM output: energy-optimized Python code


...explanation
LLM output: self-written description for the reasoning of the applied changes




Attribution and Licensing

This dataset contains derivative work of the source datasets and is thus licensed under CC BY-NC 4.0.