Performance Computations
Notes
- This is section 1.6 by the way.
- H&P defined performance as execution time per program
- There are other measures, but for this class, this will do for now.
- We will revisit this later.
- The problem is, as execution time goes up, our program is slower!
- So for a program on computer X $\text{Performance}_X = \frac{1}{\text{Execution time}_X}$
- This way if ${\text{Execution time}_X} > {\text{Execution time}_Y}$
- $\text{Performance}_X < \text{Performance}_Y$
The statement X is n times as fast as Y means - $\frac{\text{Performance}_X}{\text{Performance}_Y} = n$
- $\frac{\text{Execution Time}_Y}{\text{Execution Time}_X} = n$
- So if Computer X can run a program in 200 seconds, and Y runs a program in 300 seconds
- $\frac{300}{200} = 1.5$
- Or X is 1.5 times faster than Y
- Y is 1.5 times slower than X
- We will be back to discuss "program", but for now, it is the same program on both machines.
- Unlike Algorithms, we do want to measure these in wall clock time.
- We do want this value to change as the machines get better.
- In Algorithms, we want a "timeless" (ie does not change over the years) measure of the efficiency of the algorithm.
- Or we are interested in the algorithm, not the hardware
- It is quite the opposite here.
- We will assume the algorithm is fixed!
- But not, surprisingly the encoding of the algorithm
- How can the encoding of the algorithm change from one machine to another?
- The underlying machine code could be different
- The compiler might be more efficient, or may optimize for the specific hardware.
- There may be other factors that influence wall clock time
- The OS and other programs on the system
- Parallelism
- I/O, hard drive, cache, ...
- To semi abstract this away, we will consider the following
- The number of instructions in a program
- This may be different,
- Compiler A produces a program that will required n instructions to execute, while compiler B will require m instructions for that same program.
- The Cycles Per Instruction (CPI)
- Continuing with the above example
- The CPI obtained by compiler A is c, while the CPI for compiler B is d.
- And the clock speed or cycles per second
- Given in t GHz
- Which compiler is better in the above example?
-
I have program I want seconds assume j Instructions assume k cycles/instruction assume g cycles/second j instructions 1programx -------------- = j instructions 1programk cycles jinstructionsx ------------- = j×k cycles 1instructioni 1 second j×kcycles= -------------- = j×k/g × 10 -9 seconds g x 109cyclesTimeA = n×c/t ×10-9 TimeB = m×d/t ×10-9 - If $n \times c > m\times d$ then A is slower, otherwise B is slower.
- To make this more concrete, assume
-
Compiler Instructions CPI A 2.3×105 1.1 B 1.9×105 1.4 - Since no clock rate is given, we can just compute the cycles for each program
Compiler A: 2.3×105 × 1.1 = 2.53 × 105cycles Compiler B: 1.9×105 × 1.4 = 2.66 × 105cycles
- Note, since I have derived the generic formula above, I don't feel I need to carry units along in this computation.
- So The first compiler, even though it takes more instructions, is faster, because it uses faster instructions.