CSE 141 Turn-in assignment number 3

Performance differences

Due Friday, March 15 in class

Notice: You can do this homework either individually or in a group of up to three people. In either case, you should not ask or give help to anyone (except members of your own group).

Note that if you do the homework individually, you don't need to do the last part of the assignment.


  1. Compile and run this C program.

    Important: You must compile the code with optimizations turned on. For gcc and most Unix C compilers, use the "-O2" optimization level. Note that this uses a capital letter "O". (A small "o" would say the object code should be named "2".) If you use SUN's native compiler (which might be named "cc"), use the "-fast" compiler option (don't use "-xO2").

    By the way, I'm totally unfamiliar with Microsoft's Visual C/C++, and don't recommend using it. If you do, you'll have to use the Project Settings to set optimization for speed, and somehow figure out how to get gettimeofday or some other microsecond-resolution timer to work. Good luck!

    Turn in the following:

  2. If things work as I hope, the program will report different times for the first and second loop, even though they are doing the same computation. (Incidentally, the program runs each loop 5 times - you should consider the time for each loop to be the minimum time reported. This way, your times are less likely to be affected by strange events, such as the operating system interrupting one of the timings.) Explain why one loop is faster than the other. (If you can't figure it out from the source code, it might help to look at the assembly code, which you can get by specifying the "-S" compiler option.) Please keep your explanation brief and to the point.

  3. Similarly, explain why the third loop's performance is better or worse than the fourth loop's performance.

  4. This part is only required if you are doing this as a group homework. Design and carry out with some other experiment similar to these. It should shows that writing code two different ways leads to different performance because of some architectural feature that we have studied. Please keep this fairly simple - after all, it's only worth 1 point! Show the source code, the performance results, and give a brief explanation.