In 1977, Mr. Maurice Howard Halstead introduced metrics to measure software complexity. Halstead’s metrics depends upon the actual implementation of program and its measures, which are computed directly from the operators and operands from source code, in static manner. It allows to evaluate testing time, vocabulary, size, difficulty, errors, and efforts for C/C++/Java source code.
According to Halstead, “A computer program is an implementation of an algorithm considered to be a collection of tokens which can be classified as either operators or operands”. Halstead metrics think a program as sequence of operators and their associated operands.
He defines various indicators to check complexity of module.
Parameter |
Meaning |
n1 |
Number of unique operators |
n2 |
Number of unique operands |
N1 |
Number of total occurrence of operators |
N2 |
Number of total occurrence of operands |
When we select source file to view its complexity details in Metric Viewer, the following result is seen in Metric Report:
Metric |
Meaning |
Mathematical Representation |
n |
Vocabulary |
n1 + n2 |
N |
Size |
N1 + N2 |
V |
Volume |
Length * Log2 Vocabulary |
D |
Difficulty |
(n1/2) * (N1/n2) |
E |
Efforts |
Difficulty * Volume |
B |
Errors |
Volume / 3000 |
T |
Testing time |
Time = Efforts / S, where S=18 seconds. |