go to single .html
[fw/sdcc] / doc / SDCCUdoc-24.html
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
2 <HTML>
3 <HEAD>
4  <META NAME="GENERATOR" CONTENT="SGML-Tools 1.0.7">
5  <TITLE>SDCC Compiler User Guide: Cyclomatic Complexity</TITLE>
6  <LINK HREF="SDCCUdoc-25.html" REL=next>
7  <LINK HREF="SDCCUdoc-23.html" REL=previous>
8  <LINK HREF="SDCCUdoc.html#toc24" REL=contents>
9 </HEAD>
10 <BODY>
11 <A HREF="SDCCUdoc-25.html">Next</A>
12 <A HREF="SDCCUdoc-23.html">Previous</A>
13 <A HREF="SDCCUdoc.html#toc24">Contents</A>
14 <HR>
15 <H2><A NAME="Cyclomatic"></A> <A NAME="s24">24. Cyclomatic Complexity</A> </H2>
16
17 <P>Cyclomatic complexity of a function is defined as the number of independent
18 paths the program can take during execution of the function. This is an important
19 number since it defines the number test cases you have to generate to validate
20 the function . The accepted industry standard for complexity number is 10,
21 if the cyclomatic complexity reported by SDCC exceeds 10 you should think about
22 simplification of the function logic.
23 <P>Note that the complexity level is not related to the number of lines of
24 code in a function. Large functions can have low complexity, and small functions
25 can have large complexity levels. SDCC uses the following formula to compute
26 the complexity.
27 <P>
28 <PRE>
29 complexity = (number of edges in control flow graph) - 
30              (number
31  of nodes in control flow graph) + 2;
32  
33 </PRE>
34 <P>Having said that the industry standard is 10, you should be aware that
35 in some cases it may unavoidable to have a complexity level of less than 10.
36 For example if you have switch statement with more than 10 case labels, each
37 case label adds one to the complexity level. The complexity level is by no
38 means an absolute measure of the algorithmic complexity of the function, it
39 does however provide a good starting point for which functions you might look
40 at for further optimization.
41 <HR>
42 <A HREF="SDCCUdoc-25.html">Next</A>
43 <A HREF="SDCCUdoc-23.html">Previous</A>
44 <A HREF="SDCCUdoc.html#toc24">Contents</A>
45 </BODY>
46 </HTML>