performance measurement performance analysis paper and pencil. don’t need a working computer...
TRANSCRIPT
![Page 1: Performance Measurement Performance Analysis Paper and pencil. Don’t need a working computer program or even a computer](https://reader035.vdocuments.us/reader035/viewer/2022072006/56649f4f5503460f94c70ed1/html5/thumbnails/1.jpg)
Performance Measurement
![Page 2: Performance Measurement Performance Analysis Paper and pencil. Don’t need a working computer program or even a computer](https://reader035.vdocuments.us/reader035/viewer/2022072006/56649f4f5503460f94c70ed1/html5/thumbnails/2.jpg)
Performance Analysis
Paper and pencil.
Don’t need a working computer program or even a computer.
![Page 3: Performance Measurement Performance Analysis Paper and pencil. Don’t need a working computer program or even a computer](https://reader035.vdocuments.us/reader035/viewer/2022072006/56649f4f5503460f94c70ed1/html5/thumbnails/3.jpg)
Some Uses Of Performance Analysis
determine practicality of algorithmpredict run time on large instancecompare 2 algorithms that have different asymptotic complexity
e.g., O(n) and O(n2)
![Page 4: Performance Measurement Performance Analysis Paper and pencil. Don’t need a working computer program or even a computer](https://reader035.vdocuments.us/reader035/viewer/2022072006/56649f4f5503460f94c70ed1/html5/thumbnails/4.jpg)
Limitations of Analysis
Doesn’t account for constant factors.
but constant factor may dominate
1000n vs n2
and we are interested only in
n < 1000
![Page 5: Performance Measurement Performance Analysis Paper and pencil. Don’t need a working computer program or even a computer](https://reader035.vdocuments.us/reader035/viewer/2022072006/56649f4f5503460f94c70ed1/html5/thumbnails/5.jpg)
Limitations of Analysis
Modern computers have a hierarchical memory organization with different access time for memory at different levels of the hierarchy.
![Page 6: Performance Measurement Performance Analysis Paper and pencil. Don’t need a working computer program or even a computer](https://reader035.vdocuments.us/reader035/viewer/2022072006/56649f4f5503460f94c70ed1/html5/thumbnails/6.jpg)
Memory Hierarchy
RL1
L2
MAIN
ALU
8-32 32KB 512KB 512MB1C 2C 10C 100C
![Page 7: Performance Measurement Performance Analysis Paper and pencil. Don’t need a working computer program or even a computer](https://reader035.vdocuments.us/reader035/viewer/2022072006/56649f4f5503460f94c70ed1/html5/thumbnails/7.jpg)
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.
![Page 8: Performance Measurement Performance Analysis Paper and pencil. Don’t need a working computer program or even a computer](https://reader035.vdocuments.us/reader035/viewer/2022072006/56649f4f5503460f94c70ed1/html5/thumbnails/8.jpg)
Performance Measurement
Measure actual time on an actual computer.
What do we need?
![Page 9: Performance Measurement Performance Analysis Paper and pencil. Don’t need a working computer program or even a computer](https://reader035.vdocuments.us/reader035/viewer/2022072006/56649f4f5503460f94c70ed1/html5/thumbnails/9.jpg)
Performance Measurement Needs
programming language working program computer compiler and options to use
javac -o
![Page 10: Performance Measurement Performance Analysis Paper and pencil. Don’t need a working computer program or even a computer](https://reader035.vdocuments.us/reader035/viewer/2022072006/56649f4f5503460f94c70ed1/html5/thumbnails/10.jpg)
Performance Measurement Needs
data to use for measurement worst-case data best-case data average-case data
timing mechanism --- clock
![Page 11: Performance Measurement Performance Analysis Paper and pencil. Don’t need a working computer program or even a computer](https://reader035.vdocuments.us/reader035/viewer/2022072006/56649f4f5503460f94c70ed1/html5/thumbnails/11.jpg)
Timing In Java
long startTime = System.currentTimeMillis();// gives time in milliseconds since 1/1/1970 GMT
// code to be timed comes here
long elapsedTime = System.currentTimeMillis()
- startTime;
![Page 12: Performance Measurement Performance Analysis Paper and pencil. Don’t need a working computer program or even a computer](https://reader035.vdocuments.us/reader035/viewer/2022072006/56649f4f5503460f94c70ed1/html5/thumbnails/12.jpg)
Shortcoming
Clock accuracy
assume 100 milliseconds
Repeat work many times to bring total time to be >= 1 second
![Page 13: Performance Measurement Performance Analysis Paper and pencil. Don’t need a working computer program or even a computer](https://reader035.vdocuments.us/reader035/viewer/2022072006/56649f4f5503460f94c70ed1/html5/thumbnails/13.jpg)
Accurate Timinglong startTime = System.currentTimeMillis();long counter;do { counter++; doSomething(); } while (System.currentTimeMillis() - startTime < 1000)long elapsedTime = System.currentTimeMillis()
- startTime;float timeForMethod = ((float) elapsedTime)/counter;
![Page 14: Performance Measurement Performance Analysis Paper and pencil. Don’t need a working computer program or even a computer](https://reader035.vdocuments.us/reader035/viewer/2022072006/56649f4f5503460f94c70ed1/html5/thumbnails/14.jpg)
AccuracyNow accuracy is 10%.
first reading may be just about to change to startTime + 100
second reading may have just changed to finishTime
so finishTime - startTime is off by 100ms
![Page 15: Performance Measurement Performance Analysis Paper and pencil. Don’t need a working computer program or even a computer](https://reader035.vdocuments.us/reader035/viewer/2022072006/56649f4f5503460f94c70ed1/html5/thumbnails/15.jpg)
Accuracy
first reading may have just changed to startTime
second reading may be about to change to finishTime + 100
so finishTime - startTime is off by 100ms
![Page 16: Performance Measurement Performance Analysis Paper and pencil. Don’t need a working computer program or even a computer](https://reader035.vdocuments.us/reader035/viewer/2022072006/56649f4f5503460f94c70ed1/html5/thumbnails/16.jpg)
Accuracy
Examining remaining cases, we get
trueElapsedTime =
finishTime - startTime +- 100ms
To ensure 10% accuracy, require
elapsedTime = finishTime – startTime
>= 1sec
![Page 17: Performance Measurement Performance Analysis Paper and pencil. Don’t need a working computer program or even a computer](https://reader035.vdocuments.us/reader035/viewer/2022072006/56649f4f5503460f94c70ed1/html5/thumbnails/17.jpg)
What Went Wrong?long startTime = System.currentTimeMillis();long counter;do { counter++; InsertionSort.insertionSort(a); } while (System.currentTimeMillis() - startTime < 1000)long elapsedTime = System.currentTimeMillis()
- startTime;float timeForMethod = ((float) elapsedTime)/counter;
![Page 18: Performance Measurement Performance Analysis Paper and pencil. Don’t need a working computer program or even a computer](https://reader035.vdocuments.us/reader035/viewer/2022072006/56649f4f5503460f94c70ed1/html5/thumbnails/18.jpg)
The Fix
long startTime = System.currentTimeMillis();long counter;do { counter++; // put code to initialize a[] here InsertionSort.insertionSort(a); } while (System.currentTimeMillis() - startTime < 1000)
![Page 19: Performance Measurement Performance Analysis Paper and pencil. Don’t need a working computer program or even a computer](https://reader035.vdocuments.us/reader035/viewer/2022072006/56649f4f5503460f94c70ed1/html5/thumbnails/19.jpg)
Time Shared System
UNIX
time MyProgram
![Page 20: Performance Measurement Performance Analysis Paper and pencil. Don’t need a working computer program or even a computer](https://reader035.vdocuments.us/reader035/viewer/2022072006/56649f4f5503460f94c70ed1/html5/thumbnails/20.jpg)
Bad Way To Time
do {
counter++;
startTime = System.currentTimeMillis();
doSomething();
elapsedTime +=
System.currentTimeMillis()
- startTime; } while (elapsedTime < 1000)