GreenCode doesn't make up grades. It translates computational patterns into verifiable metrics, combining static scoring and dynamic profiling to estimate energy and carbon impact.
Energy Score (Statico)
Proxy Metrics e classi energetiche da A a G
The static phase analyzes code with AST rules and weights each anti-pattern by its potential impact on CPU, memory and battery, especially in mobile scenarios. Examples: N+1 queries in loops, redundant API/LLM calls, heavy frontend dependencies, inefficient React rendering.
Computing the score
Each finding lowers the score with a penalty proportional to the estimated energy severity. The final score is mapped to an A-G class to make the energy risk immediately readable.
Interpretazione
A low class is not an aesthetic judgment: it indicates a higher probability of computational waste, more battery use and higher cloud costs in production.
Static analysis commands
ecocode analyze: local AST parsing on JS/TS/React with energy findings and A-G score.
ecocode analyze --max-files N: limits the analysis scope.
ecocode analyze --host URL: sends report metadata to a specific dashboard endpoint.
Software Physics (Dynamic)
From CPU time to Joules, Watts and CO2
The CLI command ecocode profile <file>runs the file locally and measures user/system CPU time with native Node.js modules. For more representative analysis on real repositories, ecocode profile-projectruns multiple scenarios from config, repeats the benchmarks and produces a weighted average. From these measurements we estimate energy in mWh with the model:
This is an engineering estimate, not a lab measurement. Still, it follows computational efficiency logic consistent with the principles promoted by the Green Software Foundation: use observable data, state assumptions explicitly, and optimize where real consumption is demonstrable.