Halstead complexity measures
Halstead complexity measures are software metrics introduced by Maurice Howard Halstead in 1977 as part of his treatise on establishing an empirical science of software development.[src] Halstead made the observation that metrics of the software should reflect the implementation or expression of algorithms in different languages, but be independent of their execution on a specific platform.[src] These metrics are therefore computed statically from the code.[src] Halstead's goal was to identify measurable properties of software, and the relations between them.[src] This is similar to the identification of measurable properties of matter (like the volume, mass, and pressure of a gas) and the relationships between them (analogous to the gas equation).[src] Thus his metrics are actually not just complexity metrics.[src]
Halstead complexity measures are software metrics introduced by Maurice Howard Halstead in 1977 as part of his treatise on establishing an empirical science of software development.[src] Halstead made the observation that metrics of the software should reflect the implementation or expression of algorithms in different languages, but be independent of their execution on a specific platform.[src] These metrics are therefore computed statically from the code.[src] Halstead's goal was to identify measurable properties of software, and the relations between them.[src] This is similar to the identification of measurable properties of matter (like the volume, mass, and pressure of a gas) and the relationships between them (analogous to the gas equation).[src] Thus his metrics are actually not just complexity metrics.[src] \,\eta_1 = the number of distinct operators \,\eta_2 = the number of distinct operands \,N_1 = the total number of operators \,N_2 = the total number of operands From these numbers, several measures can be calculated: Program vocabulary: \eta = \eta_1 + \eta_2 \, Program length: N = N_1 + N_2 \, Calculated estimated program length: \hat{N} = \eta_1 \log_2 \eta_1 + \eta_2 \log_2 \eta_2 Volume: V = N \times \log_2 \eta Difficulty : D = { \eta_1 \over 2 } \times { N_2 \over \eta_2 } Effort: E = D \times V The difficulty measure is related to the difficulty of the program to write or understand, e.g.[src] when doing code review.[src] The effort measure translates into actual coding time using the following relation, Time required to program: T = {E \over 18} seconds Halstead's delivered bugs (B) is an estimate for the number of errors in the implementation.[src] Number of delivered bugs : B = {E^{2 \over 3} \over 3000} or, more recently, B = {V \over 3000} is accepted.[src] main() { int a, b, c, avg; scanf("%d %d %d", &a, &b, &c); avg = (a+b+c)/3; printf("avg = %d", avg); } The distinct operators ( \,\eta_1 ) are: main , () , {} , int , scanf , & , = , + , / , printf , , , ; The distinct operands ( \,\eta_2 ) are: a , b , c , avg , "%d %d %d" , 3 , "avg = %d" \eta_1 = 12 , \eta_2 = 7 , \eta = 19 N_1 = 27 , N_2 = 15 , N = 42 Calculated Estimated Program Length: \hat{N} = 12 \times log_2 12 + 7 \times log_2 7 = 62.67 Volume: V = 42 \times log_2 19 = 178.4 Difficulty: D = { 12 \over 2 } \times { 15 \over 7 } = 12.85 Effort: E = 12.85 \times 178.4 = 2292.44 Time required to program: T = { 2292.44 \over 18 } = 127.357 seconds Number of delivered bugs: B = { 2292.44 ^ { 2 \over 3 } \over 3000 } = 0.05 ==References== ==External links== The Halstead metrics - Extensive discussion on the calculation and use of Halstead Metrics in an object-oriented environment (with specific reference to Java).[src] Calculation of Halstead metrics - Measurement of Halstead Metrics.[src] Explanation with a Sample Program - Example (on Page 6 of the PDF) Script computing Halstead Metrics and using them for commented code detection IBM Calculator for computing Halstead metrics[src]
19 sentences · 19 cited inline · 0 references stored
References
No reference rows published for this article.
Cite this article
MLA
"Halstead complexity measures." encyclopegia.org, 2024, https://encyclopegia.org/wiki/halstead-complexity-measures. Accessed 26 November 2026.
Chicago
"Halstead complexity measures." encyclopegia.org. Accessed November 26, 2026. https://encyclopegia.org/wiki/halstead-complexity-measures.
APA
encyclopegia.org. (2024). Halstead complexity measures. Retrieved November 26, 2026, from https://encyclopegia.org/wiki/halstead-complexity-measures
Accessed November 26, 2026 · CC BY-SA 4.0 · citation page · JSON