Program 2, Process Time

Short Description:

Compute the runtime of a program.

This assignment is worth 50 points.

Goals

When you finish this homework, you should:

Formal Description

The clock cycle of your computer is one of the factors which determines how much time a program will take to run. You are to write a program which given the speed of the processor and the number of instructions a program executes, will compute how much time that program will take to finish. We will make a simplifying assumption that your computer can execute one instruction every clock cycle. To determine the run time for your program, you simply need to multiply the length of a clock cycle by the number of instructions your program requires to execute.

For example, if your program requires 2× 107 instructions and your clock cycle is 570ps (picoseconds), the time required is 2× 107 × 570ps = 1.14 × 1010 ps.

Unfortunately, as humans we really don't understand picoseconds. We are more comfortable with things in larger units. Therefor you should convert the time to several more palatable units. To be specific, the program should output the following:

The program should read in a single line without prompting. This line will be in the format c:i where c is an integer representing the clock speed for the machine and i is the instruction count for the program. You should discard the : between these two values.

I will be using an automated system to grade this program, so you should print the output exactly is written below.

Example Run

Input is bold

570:20000000
11400000000 ps
11400000 ns, 0 ps
11400 us, 0 ns, 0 ps
11 ms, 400 us, 0 ns, 0 ps
0 s, 11 ms, 400 us, 0 ns, 0 ps
0 min, 0 s, 11 ms, 400 us, 0 ns, 0 ps

Discussion

If you do not understand the mathematics, or the measurement system seek assistance early.

You should perform all computations as a long to avoid overflow. All data should be stored in an integer type.

All computations can be done with the instructions you know. You do not need if statements or loops to complete this program.

Integer division and modulus are very helpful in this program.

Your identifiers should be constructed properly, with meaningful names.

You should document your code with comments.

Your output should be organized, easy to read, and make appropriate use of white space.

Any numbers with a fixed meaning should be stored as a constant.

You should only perform any given computation once, store the results.

Testing

I have provided a simple script to test your program for some of my input. You may use this program if you wish. If your program is named myprog.cpp or myprog.C you can type
~dbennett/130/p2/runTests myprog
Note there is no .C or .cpp on the end. This will build an executable called myprog. If it is successful, it will run a number of tests. These tests are by no means exhaustive, I will be running others when I test your code.

My program was called solution.C and here is a transcript of running the test code.

~dbennett/130/p2/runTests solution
make: 'solution' is up to date.

Test 1
Success
Test 2
Success
Test 3
Success

Success, all tests have run correctly

I stuck a clear at the top of the test driver, so it will clear your screen.

make: 'solution' is up to date is normal if the program has already been compiled in your directory.

Required Files

A single source code file.

Submission

Email your final source code file to danbennett360@gmail.com.