11.11. Code to Demonstrate Optimization Effects

The following simple code can be used to observe the effects of optimization at the different levels and for different architectures:

					main()
					{
					int i,j,k,l,m,n;
					for (i=0; i<2; i++)
					{
					j=i*5; /* constant multiplication */
					k=j*1000; /* constant multiplication */
					l=i+1;
					m=l*j; /* variable multiplication */
					printf("loop=%d, j=%d, k=%d, m=%d\n",i,j,k,m);
					}
					}
				

This code, when compiled with different options, results in quite a variety of performance characteristics. Some of this is revealed in the assembly language view of the compiled code. Using the command cc +DA1.0 -go intnoopt int.c, the code is compiled with no optimization. (The same output is obtained using +DA1.1.) The result is shown in the following ...

Get HP-UX 11i Tuning and Performance now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.