Presentation is loading. Please wait.

Presentation is loading. Please wait.

Performance Measurement Performance Analysis Paper and pencil. Don’t need a working computer program or even a computer.

Similar presentations


Presentation on theme: "Performance Measurement Performance Analysis Paper and pencil. Don’t need a working computer program or even a computer."— Presentation transcript:

1

2 Performance Measurement

3 Performance Analysis Paper and pencil. Don’t need a working computer program or even a computer.

4 Some Uses Of Performance Analysis  determine practicality of algorithm  predict run time on large instance  compare 2 algorithms that have different asymptotic complexity  e.g., O(n) and O(n 2 )

5 Limitations of Analysis Doesn’t account for constant factors. but constant factor may dominate 1000n vs n 2 and we are interested only in n < 1000

6 Limitations of Analysis Modern computers have a hierarchical memory organization with different access time for memory at different levels of the hierarchy.

7 Memory Hierarchy R L1 L2 MAIN ALU 8-3232KB512KB512MB 1C2C10C100C

8 Limitations of Analysis Our analysis doesn’t account for this difference in memory access times. Programs that do more work may take less time than those that do less work.

9 Performance Measurement Measure actual time on an actual computer. What do we need?

10 Performance Measurement Needs l programming language l working program l computer l compiler and options to use

11 Performance Measurement Needs l data to use for measurement worst-case data best-case data average-case data l timing mechanism --- clock

12 Timing In C clock_t start, stop; start = clock(); /* set start to current time in hundredths of a second */ /* code to be timed comes here */ stop = clock(); /* set stop to current time */ runTime = (double) (stop – start)/ CLOCKS_PER_SEC;

13 Shortcoming Clock accuracy assume 100 ticks Repeat work many times to bring total time to be >= 1000 ticks

14 Accurate Timing start = clock(); counter = 0; do { counter++; doSomething(); } while (clock() - start < 1000) elapsedTime = (double) (clock() – start)/ CLOCKS_PER_SEC ; timeForTask = elapsedTime/counter;

15 Accuracy Now accuracy is 10%. first reading may be just about to change to start + 100 second reading may have just changed to stop so stop - start is off by 100 ticks

16 Accuracy first reading may have just changed to start second reading may be about to change to stop + 100 so stop - start is off by 100 ticks

17 Accuracy Examining remaining cases, we get trueElapsedTime = stop - start +- 100 To ensure 10% accuracy, require elapsedTime = stop – start >= 1000

18 What Went Wrong? start = clock(); counter = 0; do { counter++; insertionSort(a,n); } while (clock() - start < 1000) elapsedTime = (double)(clock() – start)/ CLOCKS_PER_SEC ; timeToSort = elapsedTime/counter;

19 The Fix start = clock(); counter = 0; do { counter++; /* put code to initialize a here */ insertionSort(a,n); } while (clock() - start < 1000)

20 Bad Way To Time do { counter++; start = clock(); doSomething(); stop = clock(); elapsedTime += stop - start; } while (elapsedTime < 1000)


Download ppt "Performance Measurement Performance Analysis Paper and pencil. Don’t need a working computer program or even a computer."

Similar presentations


Ads by Google