Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 90

Software Measures and

Metrics
Software Metrics
What and Why ?
• How to measure the size of a software?
• How much will it cost to develop a
software?
• How many bugs can we expect?
• When can we stop testing?
• When can we release the software?
• What is the complexity of a module?
• What is the module strength and coupling?
• What is the reliability at the time of release?
• Which test technique is more effective?
• Are we testing hard or are we testing smart?
• Do we have a strong program or a week test
suite?
Measurement
• 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”.
• 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”.
• Measurement is the act of determine a measure
Software metrics
• Pressman explained as “ The metric is a
quantitative measure of the degree to which a
system, component, or process possesses a
given attribute”.
• Software metrics can be defined as “The
continuous application of measurement based
techniques to the software development process
and its products to supply meaningful and timely
management information, together with the use
of those techniques to improve that process and
its products
Areas of Applications

• The most established area of software metrics is


cost and size estimation techniques.
• The prediction of quality levels for software,
often in terms of reliability, is another area where
software metrics have an important role to play.
• The use of software metrics to provide
quantitative checks on software design is also a
well established area.
Categories of Metrics
i. Product metrics: describe the characteristics of the
product such as size, complexity, design features,
performance, efficiency, reliability, portability, etc.
ii. Process metrics: describe the effectiveness and quality
of the processes that produce the software product.
Examples are:
• effort required in the process
• time to produce the product
• effectiveness of defect removal during
development
• number of defects found during testing
• maturity of the process
iii. Project metrics: describe the project characteristics
and execution. Examples are :

• number of software developers


• staffing pattern over the life cycle of the software
• cost and schedule
• productivity
Software Project Planning
• Software planning begins before technical work
starts, continues as the software evolves from
concept to reality, and culminates only when the
software is retired
Various size oriented measures
• The estimation of size is very critical and
difficult Area of project planning
• It is difficult to identify the size of system
• many attempts have made at establishing
a unit of measure of size. the more widely
known are given below:-
• Lines of Code ( LOC)
• Function Point Analysis (FPA)
Software Measurement
• Metrics
– Size-oriented (lines of Code: LOC)
• considering the “size” of the project
• execution speed, memory size, reported defects, etc
– Function-oriented (Function Point Analysis :FPA)
• Functionality, quality, complexity, reliability,
maintainability, etc
Size-oriented Metric

Sorting program
• “A line of code is any line of program text that is
not a comment or blank line, regardless of the
number of statements or fragments of
statements on the line.
• This specifically includes all lines containing
program header, declaration, and executable
and non-executable statements”.
• This is the predominant definition for lines of
code used by researchers.
• By this definition, figure shown above has 17
LOC.
Size-Oriented Metrics
• LOC is programming language dependent
– Well-designed shorter programs are
penalized
• LOC need to be estimated before design
• Not universally accepted
Lines Of Code
• Advantage
– Easy
– For counting no of assembly line
– Direct estimation metric
• Disadvantage
– Tech Dependent.
{
i=1;
while (i<=n)
{
J=1;
while(j <= i)
{
If (A[i]<A[j])
Swap(A[i], A[j]); J=j+1;
}
i = i+1;
}
}
LOC=13
read x,y,z;
type=“scalene”;
If(x==y or x==z or y==z)
type “isosceles”;
If(x==y and x==z)
type=“equilateral”;
If(x>=y+z or y>=x+z or z>=X+y)
type=“not a triangle”;
If (x<=0 or y<=0 or z<=0)
type=“bad inputs”;
print type;

LOC=11
int find_max(int i, int j,int k)
{
int max;
If(I >j) then
If(I > k) then
Max=I;
Else
Max=k;
else if(j > k)
Max=j;
Else
Max=k;
return (max);
}
Loc=14
Function points Analysis

• Alan Albrecht while working for IBM, recognized the


problem in size measurement in the 1970s, and
developed a technique (which he called Function Point
Analysis), which appeared to be a solution to the size
measurement problem.
• It measure functionality from user point of view i.e on the
basis of what the user request and receive in return.
• Therefore it deals with the functionality being delivered ,
and not with LOC, source code, files etc.
• Measuring size in this way has the advantage that size
measure is independent of the technology used to
deliver the function
Function Point analysis

• Advantages
– Users point of view: what user requests & receives from the
system
– Independent of tech.,lang,tool,methods
– Can be estimated from SRS or Design specification Doc.
– Since directly from first phase doc. So easy re-estimation on
expansion or modification.

• Diasadvantages
– Difficult to estimate
– Experienced based/subjective
Halstead Software science
• Halstead has proposed metrics for length and volume of
a program based of the number of operation and
operands.
• Tokens are classified as either operators or operands all
software science measures are function of the count of
these tokens
• Any symbol or keyboard in a program that specify an
algorithmic action is considered an operator ,while a
symbol used to represent the data is considered an
operand.
• Variable, constants and even labels are operands
• Operators consists of arithmetic symbols such as
+,-,/,*and command names such as while ,for, printf,
special character such as :=,braces, parentheses etc.
• Halstead’s software science is an analytical estimation
method.
• Have scientific basis
• Starts with few simple assumptions about the product,
Halstead used few primitive program parameters to
develop expressions for:
– 1. Overall program length
– 2. Potential minimum volume and Program level
– 3. Actual volume
– 4. Effort
– 5. Development time
Operator in general: a symbol or function
• representing a mathematical operation.
• assignments arithmetic and logical operators
• Parentheses pair, block begin/end pair
• If…then… else… endif
• Do…. While
• Statement terminator “;”
• Bitwise operator
• Pointers operator
Operands in general: A quantity to which an
operator is applied
• Subroutine declarations
• Variable declarations
• Variables and constants used with operators in
an expression
Operator and Oprend
• For any giving programs lets define the following
parameters:
• N1 : total occurrences of operators used in the program
• N2 : total occurrences of operands used in the program
• η1 be the number of unique parameters used in the
program
• η2 be the number of unique operands used in the
program
• In a program we define following
measurable quantities
N = N1+N2
N : program length
where
N1 : total occurrences of operators
N2 : total occurrences of operands
• Program Vocabulary (η)= η1 + η2
where
η: Vocabulary of program
η1 : total occurrences of operators
η2 : total occurrences of operands
Volume

• The unit of measurement of volume is the common unit


for size “bits”. It is the actual size of a program if uniform
binary encoding for the vocabulary is used.

• Estimated program Length


Example
Calculate the values of the following software science metrics
for the program given below:-
Main()
{
int a, b, c, avg;
scanf(“%d %d %d”, &a, &b, &c);
avg = (a +b +c )/3;
printf(“avg = %d”, avg);
}

1. N (program length)
2. V (Volume)
3. Vocabulary
4. Estimated program length
Example
The unique operators are: main, (), {}, int,
scanf, &, “, ”, “;”, =, +, /, printf
The unique operands are:
a, b, c, &a, &b, &c, a +b +c, avg, 3,
“%d %d %d”, “avg = %d”
therefore η1 = 12, η2 = 11
N = 12 log2(12)+ 11log2(11)
=81
V = Nlog2(η) = 81log2(23)
= 366
Example

Calculate the values of the following software


science metrics for the program given below:-

1.N (program length)


2.V (Volume)
3.Vocabulary
4.Estimated program length
Example
Calculate the values of the following software science metrics
for the program given below:-
Main()
{
int a, b, c, avg;
scanf(“%d %d %d”, &a, &b, &c);
avg = (a +b +c )/3;
printf(“avg = %d”, avg);
}

1. N (program length)
2. V (Volume)
3. Vocabulary
4. Estimated program length
Example
The unique operators are: main, (), {}, int,
scanf, &, “, ”, “;”, =, +, /, printf
The unique operands are:
a, b, c, &a, &b, &c, a +b +c, avg, 3,
“%d %d %d”, “avg = %d”
therefore η1 = 12, η2 = 11
N = 12 log2(12)+ 11log2(11)
=81
V = Nlog2(η) = 81log2(23)
= 366
• Calculate the values of the following software
science metrics for the program given below:-

1. N (program length)
2. V (Volume)
3. Vocabulary
4. Estimated program length

{
Int I,j,sum;
scanf(“%d%d”, i,j);
Sum=i+j;
Printf(“%d”,sum:
}
Example:
Example:- Find the length and vocabulary of program ?

Z=0;
While x>0
z=z+y;
x=x-1;
end-while;
Print (z);
Control flow graph
• The control flow graph G = (N, E) of a program
consists of a set of nodes N and a set of edge E.
• Each node represents a set of program
statements.
• There are five types of nodes. There is a unique
entry node and a unique exit node.
• There is an edge from node n1 to node n2 if the
control may flow from the last statement in n1 to
the first statement in n2 .
Control flow graph nodes
• A decision node contains a conditional
statement that creates 2 or more control
branches (e.g. if or switch statements).
• A merge node usually does not contain any
statement and is used to represent a program
point where multiple control branches merge.
• A statement node contains a sequence of
statements. The control must enter from the first
statement and exit from the last statement.
CFG for (a) sequence, (b) selection, and (c)
iteration type of constructs
Example
Int compute-gcd (x,Y) 1
while x!=y
Int x,y ;
{ if (x>y) then 2
1 while x!=y
{ x=x-y; 3
4
y=y-x;
2 if (x>y) then
3 x=x-y;
5
4 else y=y-x;
5}
6. Return x;
Choosen test cases,(x=4,y=3),
} 6
(x=3,y=4) Return x ;
Example: draw the control flow graph for the
following program:-

0 {
1 i=1;
2 while (i<=n) {
3 J=1;
4 while(j <= i) {
5 If (A[i]<A[j])
6 Swap(A[i], A[j]);
7 J=j+1;}
8 i = i+1;}
9 }
DD Graph
• Flow graph representation is the first step of path
testing
• Second step is to draw the DD graph from the flow
graph
• DD path graph is known as decision to decision path
graph in which concentrate on decision nodes.
• The nodes of flow graph which are in sequence are
combined into single node.
• Hence DD graph is directed graph in which nodes
are sequence of statements and edges show control
flow between nodes
• The DD path graph is used to find
independent path.
• Execute all independent path at least
once.
Example 2
Draw the DD graph for this program:-
1. read x,y,z;
2. type=“scalene”;
3. If(x==y or x==z or y==z)
4. type “isosceles”;
5. If(x==y and x==z)
6. type=“equilateral”;
7. If(x>=y+z or y>=x+z or z>=X+y)
8. type=“not a triangle”;
9. If (x<=0 or y<=0 or z<=0)
10. type=“bad inputs”;
11. print type;
Example 2

1,2,3

7 4
6

8
9
10

11
Cyclometic Complexity
• Cyclomatic complexity is a software metric used
to measure the complexity of a program.
• This metric measures independent paths
through the program's source code.
• An independent path is defined as a path that
has at least one edge which has not been
traversed before in any other paths.
• Cyclomatic complexity can be calculated with
respect to functions, modules, methods or
classes within a program.
Cyclomatic Complexity
• Is also known as structural complexity because it gives
internal view of code
• For more complicated programs it is not easy to
determine the number of independent paths of the
program.
• McCabe’s cyclomatic complexity defines the number of
linear independent paths through a program. Also, the
McCabe’s cyclomatic complexity is very simple to
compute.
• The McCabe’s cyclomatic complexity metric provides a
practical way of determining the maximum number of
linearly independent paths in a program. Though the
McCabe’s metric does not directly identify the linearly
independent paths, but it informs approximately how
many paths to look for.
• There are three different ways to compute the cyclomatic
complexity. The
• Method 1: Given a control flow graph G of a program,
the cyclomatic complexity V(G) can be computed as:
V(G) = E – N + 2(P)
where N is the number of nodes of the control flow graph
and E is the number of edges in the control flow graph.
• Method 2: An alternative way of computing the
cyclomatic complexity of a program from an inspection of
its control flow graph is as follows:
V(G) = Total number of bounded areas + 1
In the program’s control flow graph G, any region enclosed
by nodes and edges can be called as a bounded area.
• Method 3:The cyclomatic complexity of a
program can also be easily computed by
computing the number of decision
statements of the program.
• If N is the number of decision statement of
a program, then the McCabe’s metric is
equal to N+1.
Example
Int compute-gcd (x,Y) 1
Int x,y ;
{ 2
1 while x!=y
{ 3
4

2 if (x>y) then
3 x=x-y;
5
4 else y=y-x;
5}
6. Return x;
} 6
• Method1 :- Given a control flow graph G
of a program, the cyclomatic complexity
V(G) can be computed as:
V(G) = E – N + 2(P)
E=7 and N=6. Therefore, the cyclomatic
complexity = 7-6+2 = 3.
• Method 2:- V(G) = Total number of
bounded areas + 1
• computing with this method is also 2+1 = 3
• Method 3: If N is the number of decision
statement of a program, then the
McCabe’s metric is equal to N+1.
• Total no of decision statement =2+1
• Cyclometic complexity is =3
• Total Number of independent path of this
program is =3 1

1:- 1,6 4
3
2:- 1,2,3,5,1,6
3:- 1,2,4,5,1,6 5

6
Example 2
Draw the DD graph for this program:-
1. read x,y,z;
2. type=“scalene”;
3. If(x==y or x==z or y==z)
4. type “isosceles”;
5. If(x==y and x==z)
6. type=“equilateral”;
7. If(x>=y+z or y>=x+z or z>=X+y)
8. type=“not a triangle”;
9. If (x<=0 or y<=0 or z<=0)
10. type=“bad inputs”;
11. print type;
Example 2

1,2,3

7 4
6

8
9
10

11
• Method1 :- Given a control flow graph G
of a program, the cyclomatic complexity
V(G) can be computed as:
V(G) = E – N + 2(P)
E=7 and N=6. Therefore, the cyclomatic
complexity = 12-9+2 = 5.
• Method 2:- V(G) = Total number of
bounded areas + 1
• computing with this method is also 4+1 = 5
• Method 3: If N is the number of decision
statement of a program, then the
McCabe’s metric is equal to N+1.
• Total no of decision statement =4+1
• Cyclometic complexity is =5
Example 2

E B
D

F
G
H Independent Paths= 1. ABI
2. ACDI
3. ACEFI
4. ACEGHI
I
5. ACEGI
C.C :example
0 {
1 i=1;
2 while (i<=n) {
3 J=1;
4 while(j <= i) {
5 If (A[i]<A[j])
6 Swap(A[i], A[j]);
7 J=j+1;}
8 i = i+1;}
9 }
CC:Example 1
e-n+2=9-7+2=4
0,1,2

3,4

9
5

8
7 6
Example 2
1. read x,y,z;
2. type=“scalene”;
3. If(x==y or x==z or y==z)
4. type “isosceles”;
5. If(x==y and x==z)
6. type=“equilateral”;
7. If(x>=y+z or y>=x+z or z>=X+y)
8. type=“not a triangle”;
9. If (x<=0 or y<=0 or z<=0)
10. type=“bad inputs”;
11. print type;
Example 2
e-n+2=12-9+2=5
1,2,3

7 4
6

8
9
10

11
Example3
0 cin>>a>>b>>c;
1 If (a>10)
{
2 cout<<“hello”;
3 If(b<a)
{
4 Cout<<“part1”;
5 if(c>a)
{
6 cout<<“part2”;
}
}
7 Else
{
8 cout<<“part3”;
}
}
9 Cout<<“exiting”;
Example3:e-n+2=8-6+2=4
0,1

2,3

4,5
7,8

6
Example 4
1. int find_max(int i, int j,int k)
{
1. int max;
2. If(I >j) then
3. If(I > k) then
4. Max=I;
5. Else
6. Max=k;
7. else if(j > k)
8. Max=j;
9. Else
10. Max=k;
11. return (max);
12. }
Example 4

e-n+2=10-8+2=4

0,1

5 2

7 6 4 3

You might also like