scitools.com

← Metric catalog

Percent Changed is one of the source-code metrics Understand computes across 17+ languages — browse them in the GUI, export and track them, or script them with the Python API.

Percent Changed

API ID: PercentChanged
Languages: Ada, Assembly, Basic, C#, C++, Fortran, Java, Jovial, Pascal, Python, Rust, VHDL, Web
Targets: Classes, Files, Functions, Modules, Packages, Subprograms

Percentage of lines that differ from the comparison database.

(New + Removed + 2 × Changed) / (Current Lines + Comparison Lines) × 100

The formula weights changed lines double since they show up on both sides of the diff.

For example, diffing a file's current version against the comparison database's version:


--- sample.cpp (comparison database)
+++ sample.cpp (current)
@@ -1,15 +1,16 @@
 #include <iostream>

-// Utility functions
 int square(int x) {
-  return x * x;
+  return x * x * x;
 }

-int unused() {
-  return 0;
+// Compute a cube
+int cube(int x) {
+  return x * x * x;
 }

 int main() {
   std::cout << square(4) << std::endl;
+  std::cout << cube(3) << std::endl;
   return 0;
 }

gives New Lines = 2, Removed Lines = 1, and Changed Lines = 3, across 16 lines in the current version and 15 in the comparison database, so:

PercentChanged = (2 + 1 + 2 × 3) / (16 + 15) × 100 = 29.03%