Large Language Models (LLMs) are increasingly used to optimize code for performance. This practice often assumes that improvements in execution speed naturally translate into overall lower energy consumption. We challenge this assumption empirically by measuring whether performance-optimized code produced by LLM self-refinement pipelines is also energy-efficient relative to canonical human reference solutions, and whether the energy cost of the optimization process can be offset by subsequent execution-time savings. We evaluate 11 open-source models across four decoding configurations on all 1,000 problems of EffiBench, a state-of-the-art performance benchmark, while collecting per-process, hardware-level energy measurements throughout. Inference energy spans 0.79 to 8.68 MJ across model-variant pairs, which is roughly equivalent to the energy of 250 to 2800 GPT-4.1 queries. Limiting the maximum number of output tokens has the largest impact, reducing energy use by up to 69% compared to the default configuration. On the execution side, 42 of 44 configurations produce code that consumes more energy per problem than the canonical human reference, with overheads ranging from +4% to +886%. The two exceptions achieve only marginal gains, with break-even points on the order of 10^6 to 10^7 executions. Mixture-of-Experts architectures consume substantially less inference energy than equivalently-sized dense models without sacrificing correctness, making architectural choice a more consequential sustainability lever than decoding parameters. Performance optimization and energy efficiency are not always aligned goals: LLM self-refinement consistently produces faster-seeking but energy-heavier code relative to what a human engineer would write. All artifacts are available at https://doi.org/10.5281/zenodo.23598170.
Figures & tables
Group
Task
Inference Energy
Runtime Energy
Standardized Benchmark
Parameter Sweep
Break-Even Analysis
Iterative Pipeline
Canonical Reference
Inference-energy studies [ 12 , 5 , 13 , 14 ]
General LLM
●
○
○
◐
○
○
○
DL framework energy [ 15 ]
General DL
●
○
●
○
○
○
○
Inference energy for code gen. [ 16 , 17 , 18 , 19 ]
Code Generation
●
○
◐
○
○
○
○
Generated-code energy [ 10 , 7 , 20 , 21 ]
Code Generation
○
●
●
○
○
○
●
Code-optimisation pipelines [ 3 , 22 , 23 ]
Code Optimization
○
●
◐
○
○
●
◐
Break-even analysis [ 9 ]
Code Optimization
●
●
●
○
●
◐
○
TABLE I: Coverage of the dimensions relevant to our three RQs across prior work, grouped by capability profile. ○ = not addressed, ◐ = partial, ● = addressed.
Family
Model
Parameters
Architecture
Qwen3.5
Qwen3.5-4B
4B
Dense
Qwen3.5-9B
9B
Dense
Qwen3.5-27B
27B
Dense
Qwen3.5-35B-A3B
35B
MoE
GLM
GLM-4.7-Flash
31B
Dense
GLM-4.6V-Flash
10B
Dense
TABLE II: Models evaluated in this work.
Model
ET (s)
NET
MU (MB)
NMU
TMU
NTMU
pass@1 (%)
GLM-4.6V-Flash
0.133
1.052
23.098
1.003
2.215
1.053
25.4
0.131 (1.4%)
1.038 (1.4%)
23.091 (0.0%)
1.003 (0.0%)
2.189 (1.2%)
1.040 (1.3%)
GLM-4.7-Flash
0.129
1.034
23.150
1.005
2.168
1.039
25.0
0.123 (4.7%)
0.984 (4.8%)
23.133 (0.1%)
1.005 (0.1%)
2.062 (4.9%)
0.989 (4.8%)
Ministral-3B
0.126
0.994
23.439
1.018
2.170
1.024
32.7
0.120 (4.8%)
0.946 (4.9%)
23.248 (0.8%)
1.009 (0.8%)
2.026 (6.7%)
0.956 (6.7%)
TABLE III: Resource efficiency before (top row) and after (bottom row) self-optimization and pass@1, with relative change in parentheses. ET: Execution Time (s); MU: Max Memory Usage (MB); TMU: Total Memory Usage (MB ⋅ s). NET, NMU and NTMU are ET, MU and TMU normalized by the canonical solution; values below 1.0 beat the canonical reference.
Model
Etotal
ECPU
EGPU
CPU %
GPU %
GLM-4.6V-Flash
1.926
1.231
0.695
63.9
36.1
GLM-4.7-Flash
6.077
3.636
2.440
59.8
40.2
Ministral-3B
1.273
0.829
0.444
65.1
34.8
Ministral-8B
2.625
1.693
0.932
64.5
35.5
Ministral-14B
3.512
2.220
1.291
63.2
36.8
Nemotron-Cascade
3.085
1.913
1.171
62.0
38.0
TABLE IV: Inference energy consumption per model during self-optimization, in megajoules (MJ). CPU % and GPU % are each component’s share of Etotal .
Fig. 1: Total inference energy Etotal (MJ) per model and decoding variant after five epochs of self-optimization. mt1024 is almost always the lowest-energy variant and t0.5 is highest in most cases.
Fig. 2: Correctness efficiency (pass@1 / Etotal ) vs. NET for all model-variant pairs. Shaded region: optimal zone. Dashed line: canonical baseline (NET = 1.0). Nemotron-Nano mt1024 is clipped due to pass@1 collapse.
Model
Variant
NET
NMU
NTMU
pass@1 (%)
Etotal
CPU %
GPU %
GLM-4.6V-Flash
default
1.038
1.003
1.040
25.4
1.930
63.9
36.1
ctx65536
1.031
1.002
1.033
26.1
1.790
61.5
38.5
mt1024
1.059
1.002
1.058
9.0
0.790
61.2
38.8
t0.5
1.028
1.003
1.028
25.4
1.850
61.7
38.3
GLM-4.7-Flash
default
0.984
1.005
0.989
25.0
6.080
59.8
40.2
ctx65536
0.966
1.004
0.971
25.5
6.110
60.2
39.8
TABLE V: Resource efficiency, inference energy, and pass@1 after self-optimization. N-prefixed metrics are normalized against the canonical solution; values below 1.0 indicate better performance than the canonical reference. Etotal in MJ.
Fig. 3: Left: (Ecanon−Eopt)/n ; points left of zero beat the canonical baseline. Right: (Ebase−Eopt)/n ; positive values indicate improvement over the base epoch.
Model
Etotal (MJ)
gCO 2 eq
GLM-4.6V-Flash
1.926
116.1
GLM-4.7-Flash
6.077
366.3
Ministral-3B
1.273
76.8
Ministral-8B
2.625
158.2
Ministral-14B
3.512
211.7
Nemotron-Cascade
3.085
186.0
TABLE VI: Carbon footprint of the five-epoch optimization loop (default variant), computed using γ=217 gCO 2 eq/kWh [ 35 ] .