Unit3 Software Metrics
Unit3 Software Metrics
MEASUREMENT
AND METRICS
1
Software Measurement
2
Types of Measurement
1. Direct Measures
2. Indirect Measures
3
Software Metrics: What and Why ?
4
1. How to measure the size of a software?
6
❖ Pressman explained as “A measure provides a quantitative
indication of the extent, amount, dimension, capacity, or size
of some attribute of the product or process”.
❖ Measurement is the act of determine a measure
❖ The metric is a quantitative measure of the degree to which
a system, component, or process possesses a given
attribute.
❖ Fenton defined measurement as “ it is the process by which
numbers or symbols are assigned to attributes of entities in
the real world in such a way as to describe them according
to clearly defined rules”.
7
Areas of Applications
8
Categories of Metrics
9
iii. Project metrics: describe the project characteristics
and execution. Examples are :
• productivity
10
Control flow graph
50
How to draw Control flow graph?
1
2
3 4
5
6
Cyclomatic complexity = 7 – 6 + 2 = 3.
CYCLOMATIC COMPLEXITY
This metric was developed by Thomas J. McCabe in 1976 and it is based
on a control flow representation of the program.
Independent path is defined as a path that has atleast one edge which
has not been traversed before in any other paths.
50
Different ways to compute CC
There are three methods:-
V (G) = Π + 1
Where Π = number of decision statement of a program.
50
Flow graph for program will be
50
Flow graph notation
Computing mathematically,
V(G) = 9 - 7 + 2 = 4
V(G) = 3 + 1 = 4 (Condition nodes are 1,2 and 3 nodes)
1. V (G) >=1
2. V (G) is the maximum number of independent paths in the
graph
3. Inserting and deleting functional statements to G does not
affect V(G)
4. G will have only one path if and only if V (G) = 1
5. Inserting a new row in G increases V(G) by unity.
50
Example
SOLUTION
1. V(G) = E – N + 2P
= 13 – 10 + 2
=5
2. V(G) = Π + 1
=4+1=5
50
HALSTEAD’s SOFTWARE
SCIENCE METRICS
26
Token Count
= 1+ 2
: vocabulary of a program
where
1 : number of unique operators
2 : number of unique operands
27
The length of the program in the terms of the total number of
tokens used is
N = N1+N2
N : program length
where N1 : total occurrences of operators
N2 : total occurrences of operands
28
Program Volume
V = N * log2
The unit of measurement of volume is the common unit for
size “bits”. It is the actual size of a program if a uniform
binary encoding for the vocabulary is used.
29
Potential Volume
Program Level
L = V* / V
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).
30
Program Difficulty
D=1/L
As the volume of an implementation of a program increases,
the program level decreases and the difficulty increases.
Thus, programming practices such as redundant usage of
operands, or the failure to use higher-level control constructs
will tend to increase the volume as well as the difficulty.
Effort Equation
E=V/L=D*V
The unit of measurement of E is elementary mental
discriminations.
31
Time equation
T’ = E/S
32
Advantages of Halstead Metrics
Simple to calculate
33
Counting rules for C language
34
4. Local variables with the same name in different functions are
counted as unique operands.
35
8. The reserve words like return, default, continue, break, sizeof,
etc., are considered as operators.
11. The unary and binary occurrence of “+” and “-” are dealt
separately. Similarly “*” (multiplication operator) are dealt with
separately.
36
12. In the array variables such as “array-name [index]” “array-
name” and “index” are considered as operands and [ ] is
considered as operator.
37
Example
z=0;
while x>0
z=z+y;
x=x-1;
end while;
print (z);
() 1 - -
Here, 1 = 8, 2 = 5, N1 = 14, N 2 = 11
40
Example
int f=1, n=7; for (int i=1; i<=n; i+=1) f*=i;
42
Example
43
int sort (int x[ ], int n)
{
int i,j,save,im1;
// This function sorts array x in ascending order
if(n < 2) return 1;
for (i = 2; i <=n; i++)
{
im1 = i-1;
for( j =1; j<=im1; j++)
if( x[i] < x[j])
{
save = x[i];
x[i] = x[j];
x[j] = save;
}
}
return 0;
44
}
Solution
45
Table : Operators and operands of sorting program
46
Here N1=53 and N2=38. The program length N=N1+N2=91
= 14 log214 + 10 log210
= 14 * 3.81 + 10 * 3.32
= 53.34 + 33.2 = 86.45
47
Conceptually unique input and output parameters are
represented by
*
2
Since L = V* / V
48
11.6
0.027
417
D=I/L
1
37.03
0.027
Effort Equation
E = V / L = 15450.08
49
Therefore, 15450 elementary mental discrimination are
required to construct the program.
Time Equation
15450
T E / 18 858 seconds 14 minutes
18
This is probably a reasonable time to produce the program,
which is very simple
50
Example
51
52
53
Solution
List of operators and operands are given in Table
below.
54
55
Program vocabulary 42
Program length N = N1 +N2
= 84 + 55 = 139
Estimated length N 24log 2 24 18log 2 18 185.115
% error = 24.91
Program volume V = 749.605 bits
57