The Halstead Complexity calculator computes several code factors based the total and unique number of operators and operands.
INSTRUCTIONS: Enter the following:
(N1) Total number of operators
(N2) Total number of operands
(η1) Number of unique operators
(η2) Number of unique operands
Halstead Complexity (HC): The calculator returns the following:
Program vocabulary
Program length
Calculated estimated program length
Volume of Code
Software Difficulty
Software Effort
Time to Write Code
Estimated Number of Delivered Bugs
The Math / Science
Halstead Complexity calculations were intended to provide software metrics established as an empirical science of software development. For a software development effort, one can use the following metrics to characterize the level of complexity of developing the software:
η1 = the number of distinct operators
η2 = the number of distinct operands
N1 = the total number of operators
N2 = the total number of operands
From these numbers, several measures can be calculated:
Program vocabulary: η = η1 + η2
Program length: N = N1 + N2
Calculated estimated program length: L = η1 * log2(η1) + η2* log2 (η2)
Volume of Code: V=N * log2(η)
Software Difficulty: D = (η1/2) * (N2 / η2)
Software Effort: E = D*V
Time to Write Code: T = (E/18) seconds
Estimated Number of Delivered Bugs: B = V/3000
Note: The difficulty measure is related to the difficulty of the program to write or understand, e.g. when doing code review.
This equation, Halstead Software Complexity, references 5 pages