## Halstead's Software MetricsAccording to Halstead's "A computer program is an implementation of an algorithm considered to be a collection of tokens which can be classified as either operators or operand." ## Token CountIn these metrics, a computer program is considered to be a collection of tokens, which may be classified as either operators or operands. All software science metrics can be defined in terms of these basic symbols. These symbols are called as a token. The basic measures are n1 = count of unique operators. In terms of the total tokens used, the size of the program can be expressed as N = N1 + N2. ## Halstead metrics are:
The unit of measurement of volume is the standard unit for size "bits." It is the actual size of a program if a uniform binary encoding for the vocabulary is used. V=N*log
The value of L ranges between zero and one, with L=1 representing a program written at the highest possible level (i.e., with minimum size). L=V*/V
The difficulty level or error-proneness (D) of the program is proportional to the number of the unique operator in the program. D= (n1/2) * (N2/n2)
The unit of measurement of E is elementary mental discriminations. E=V/L=D*V
According to Halstead, The first Hypothesis of software science is that the length of a well-structured program is a function only of the number of unique operators and operands. N=N1+N2 And estimated program length is denoted by N^ N^ = n1log The following alternate expressions have been published to estimate program length: - N
_{J}= log_{2}(n1!) + log_{2}(n2!) - N
_{B}= n1 * log_{2}n2 + n2 * log2n1 - N
_{C}= n1 * sqrt(n1) + n2 * sqrt(n2) - N
_{S}= (n * log_{2}n) / 2
The potential minimum volume V* is defined as the volume of the most short program in which a problem can be coded. V* = (2 + n2*) * log Here, n2* is the count of unique input and output parameters
The size of the vocabulary of a program, which consists of the number of unique tokens used to build a program, is defined as: n=n1+n2 where n=vocabulary of a program
lambda = L * V* = L ^{2} * V
- Comments are not considered.
- The identifier and function declarations are not considered
- All the variables and constants are considered operands.
- Global variables used in different modules of the same program are counted as multiple occurrences of the same variable.
- Local variables with the same name in different functions are counted as unique operands.
- Functions calls are considered as operators.
- All looping statements e.g., do {...} while ( ), while ( ) {...}, for ( ) {...}, all control statements e.g., if ( ) {...}, if ( ) {...} else {...}, etc. are considered as operators.
- In control construct switch ( ) {case:...}, switch as well as all the case statements are considered as operators.
- The reserve words like return, default, continue, break, sizeof, etc., are considered as operators.
- All the brackets, commas, and terminators are considered as operators.
- GOTO is counted as an operator, and the label is counted as an operand.
- The unary and binary occurrence of "+" and "-" are dealt with separately. Similarly "*" (multiplication operator) are dealt separately.
- In the array variables such as "array-name [index]" "array-name" and "index" are considered as operands and [ ] is considered an operator.
- In the structure variables such as "struct-name, member-name" or "struct-name -> member-name," struct-name, member-name are considered as operands and '.', '->' are taken as operators. Some names of member elements in different structure variables are counted as unique operands.
- All the hash directive is ignored.
Here N1=53 and N2=38. The program length N=N1+N2=53+38=91 Vocabulary of the program n=n1+n2=14+10=24 Volume V= N * log The estimate program length N of the program = 14 log Conceptually unique input and output parameters are represented by n2*. n2*=3 {x: array holding the integer to be sorted. This is used as both input and output} {N: the size of the array to be sorted} The Potential Volume V*=5log Since L=V*/V We may use another formula V^=V x L^= 417 x 0.038=15.67E^=V/L^=D^ x V Therefore, 10974 elementary mental discrimination is required to construct the program. This is probably a reasonable time to produce the program, which is very simple. Next TopicFunctional Point (FP) Analysis |