Expert C Programming

(Jeff_L) #1

IP address le0=129.144.248.36 /usr/sbin/ifconfig -a


The IP address is built into the network
Floating-point
hardware

FPU's frequency appears to be 38.2
MHz

fpversion comes with the compiler


Some Light Relief—Programming Puzzles at CMU


A few years ago, the Computer Science Department at Carnegie-Mellon University regularly ran a
small programming contest for its incoming graduate students. The contest was intended to give the
new researchers some hands-on experience with the department systems and let them demonstrate
their star potential. CMU has a long and distinguished involvement with computers, stretching back to
the pioneering days, so you'd typically expect some outstanding entries in a programming competition
there.


The form of the contest varied from year to year, and in one particular year it was very simple.
Contestants had to read a file of numbers and print the average. There were only two rules:



  1. The program had to run as fast as possible.

  2. The program had to be written in Pascal or C.


The rival programs were grouped together and submitted in batches by a faculty member. Students
could submit as many entries as they wished; this encouraged the use of non-deterministic
probabilistic algorithms (algorithms that would guess at certain characteristics of the data set and use
the guess to obtain faster performance). The golden rule was that the program which ran in the
shortest amount of time won the contest.


The graduate students duly retired to dark corners and started whacking their various programs. Most
of them had three or four versions to enter and run. At this point, the reader is invited to guess the
techniques that helped the programs run fast.


Programming Challenge


How to Exceed the Speed Limit?


Imagine that you have been given the task of writing a program to read a file of 10,000
numbers and calculate the average. Your program must run in the shortest amount of time.


What programming and compiler techniques will you use to achieve this?


Most people guess the biggest wins will come through code optimization, either explicitly in the code,
or implicitly by using the correct compiler options. The standard code optimizations are techniques

Free download pdf