Halstead Metrics

Static Metrics for C, C++, Ada

Halstead complexity measurement was developed to measure a program module's complexity directly from source code, with emphasis on computational complexity. The measures were developed by the late Maurice Halstead as a means of determining a quantitative measure of complexity directly from the operators and operands in the module.

Halstead provides various indicators of the module's complexity

Halstead metrics allow you to evaluate the testing time of any C/C++ source code. These only make sense at the source file level and vary with the following parameters:

 

Parameter

Meaning

n1

Number of distinct operators

n2

Number of distinct operands

N1

Number of operator instances

N2

Number of operand instances

 

When a source file node is selected in the Metrics Viewer, the following results are displayed in the Metrics report:

 

Metric

Meaning

Formula

n

Vocabulary

n1 + n2

N

Size

N2 + N2

V

Volume

N * log2 n

D

Difficulty

n1/2 * N2/n2

E

Effort

V * D

B

Errors

V / 3000

T

Testing time

E / k

 

In the above formulae, k is the stroud number, which has an arbitrary default value of 18. With experience, you can adjust the stroud number to adapt the calculation of the estimated testing time (T) to your own testing conditions: team background, criticity level, and so on.

When the Root node is selected, the Metrics Viewer displays the total testing time for all loaded source files.

Related Topics

Viewing Static Metrics | V(g) or Cyclomatic Number