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

Slides:



Advertisements
Similar presentations
CHAPTER 2 ALGORITHM ANALYSIS 【 Definition 】 An algorithm is a finite set of instructions that, if followed, accomplishes a particular task. In addition,
Advertisements

Performance What differences do we see in performance? Almost all computers operate correctly (within reason) Most computers implement useful operations.
Lecture3: Algorithm Analysis Bohyung Han CSE, POSTECH CSED233: Data Structures (2014F)
Fundamentals of Python: From First Programs Through Data Structures
ALG0183 Algorithms & Data Structures Lecture 3 Algorithm Analysis 8/25/20091 ALG0183 Algorithms & Data Structures by Dr Andy Brooks Weiss Chapter 5 Sahni.
100 Performance ENGR 3410 – Computer Architecture Mark L. Chang Fall 2006.
Computational Complexity 1. Time Complexity 2. Space Complexity.
Java Syntax, Java Conventions, CSE 115 Conventions (Part 1) CSE 115 Spring 2006 January 25 & 27, 2006.
Introduction to Analysis of Algorithms
Exceptions. Errors and Exceptions An error is a bug in your program –dividing by zero –going outside the bounds of an array –trying to use a null reference.
Time Remaining 30:00. 29:30 29:00 28:30 28:00.
CS 206 Introduction to Computer Science II 09 / 05 / 2008 Instructor: Michael Eckmann.
Performance Measurement Performance Analysis Paper and pencil. Don’t need a working computer program or even a computer.
10/10/2002CSE Memory Hierarchy CSE Algorithms Quicksort vs Heapsort: the “inside” story or A Two-Level Model of Memory.
Insertion Sort for (i = 1; i < n; i++) {/* insert a[i] into a[0:i-1] */ int t = a[i]; int j; for (j = i - 1; j >= 0 && t < a[j]; j--) a[j + 1] = a[j];
Lecture 3 Aug 31, 2011 Goals: Chapter 2 (algorithm analysis) Examples: Selection sorting rules for algorithm analysis discussion of lab – permutation generation.
Time Complexity s Sorting –Insertion sorting s Time complexity.
CS2420: Lecture 4 Vladimir Kulyukin Computer Science Department Utah State University.
27-Jun-15 Profiling code, Timing Methods. Optimization Optimization is the process of making a program as fast (or as small) as possible Here’s what the.
CS 206 Introduction to Computer Science II 01 / 28 / 2009 Instructor: Michael Eckmann.
Introduction to Analysis of Algorithms Prof. Thomas Costello (reorganized by Prof. Karen Daniels)
Lecture 3 Feb 7, 2011 Goals: Chapter 2 (algorithm analysis) Examples: Selection sorting rules for algorithm analysis Image representation Image processing.
1 Performance Measurement CSE, POSTECH 2 2 Program Performance Recall that the program performance is the amount of computer memory and time needed to.
Insertion Sort for (int i = 1; i < a.length; i++) {// insert a[i] into a[0:i-1] int t = a[i]; int j; for (j = i - 1; j >= 0 && t < a[j]; j--) a[j + 1]
1 I.Introduction to Algorithm and Programming Algoritma dan Pemrograman – Teknik Informatika UK Petra 2009.
Chapter 1 Algorithm Analysis
Introduction to Analysing Costs 2015-T2 Lecture 10 School of Engineering and Computer Science, Victoria University of Wellington  Marcus Frean, Rashina.
Discrete Mathematics Algorithms. Introduction  An algorithm is a finite set of instructions with the following characteristics:  Precision: steps are.
1 Chapter 24 Developing Efficient Algorithms. 2 Executing Time Suppose two algorithms perform the same task such as search (linear search vs. binary search)
{ CS203 Lecture 7 John Hurley Cal State LA. 2 Execution Time Suppose two algorithms perform the same task such as search (linear search vs. binary search)
Loops: Handling Infinite Processes CS 21a: Introduction to Computing I First Semester,
Arrays Tonga Institute of Higher Education. Introduction An array is a data structure Definitions  Cell/Element – A box in which you can enter a piece.
Complexity of Algorithms
CSE332: Data Abstractions Lecture 8: Memory Hierarchy Tyler Robison Summer
Asymptotic Notation (O, Ω, )
ALG0183 Algorithms & Data Structures Lecture 4 Experimental Algorithmics 8/25/20091 ALG0183 Algorithms & Data Structures by Dr Andy Brooks Case study article:
Introduction to Programming (in C++) Complexity Analysis of Algorithms
Chapter 10 Algorithm Analysis.  Introduction  Generalizing Running Time  Doing a Timing Analysis  Big-Oh Notation  Analyzing Some Simple Programs.
New Mexico Computer Science For All Algorithm Analysis Maureen Psaila-Dombrowski.
SNU IDB Lab. Ch4. Performance Measurement © copyright 2006 SNU IDB Lab.
M180: Data Structures & Algorithms in Java Algorithm Analysis Arab Open University 1.
Chapter 7 Analysis of Algorithms © 2006 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
Processor Structure and Function Chapter8:. CPU Structure  CPU must:  Fetch instructions –Read instruction from memory  Interpret instructions –Instruction.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 23 Algorithm Efficiency.
ANALYSING COSTS COMP 103. RECAP  ArrayList: add(), ensuring capacity, iterator for ArrayList TODAY  Analysing Costs 2 RECAP-TODAY.
TAs Fardad Jalili: Aisharjya Sarkar: Soham Das:
1 Chapter 2 Program Performance. 2 Concepts Memory and time complexity of a program Measuring the time complexity using the operation count and step count.
Announcements Assignment 2 Out Today Quiz today - so I need to shut up at 4:25 1.
Analysis of Algorithms Spring 2016CS202 - Fundamentals of Computer Science II1.
1 Algorithms Searching and Sorting Algorithm Efficiency.
Introduction to Analysing Costs 2013-T2 Lecture 10 School of Engineering and Computer Science, Victoria University of Wellington  Marcus Frean, Rashina.
Introduction To Algorithm and Data Structures Course Teacher: Moona Kanwal -Algorithm Design -Algorithm Analysis -Data structures -Abstract Data Type.
Algorithm Complexity is concerned about how fast or slow particular algorithm performs.
LECTURE 9 CS203. Execution Time Suppose two algorithms perform the same task such as search (linear search vs. binary search) and sorting (selection sort.
(Complexity) Analysis of Algorithms Algorithm Input Output 1Analysis of Algorithms.
Big-O notation.
Complexity In examining algorithm efficiency we must understand the idea of complexity Space complexity Time Complexity.
Computer Architecture Experimental Design
Performance Measurement
CSCI1600: Embedded and Real Time Software
Packages and Interfaces
Lesson 15: Processing Arrays
Performance Measurement
Complexity Analysis of Algorithms
Performance Measurement
Performance Measurement
CSCI1600: Embedded and Real Time Software
CSCI1600: Embedded and Real Time Software
CSCI1600: Embedded and Real Time Software
Performance Measurement
Presentation transcript:

Performance Measurement

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

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 )

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

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

Memory Hierarchy R L1 L2 MAIN ALU KB512KB512MB 1C2C10C100C

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.

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

Performance Measurement Needs l programming language l working program l computer l compiler and options to use javac -o

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

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;

Shortcoming Clock accuracy assume 100 milliseconds Repeat work many times to bring total time to be >= 1 second

Accurate Timing long startTime = System.currentTimeMillis(); long counter; do { counter++; doSomething(); } while (System.currentTimeMillis() - startTime < 1000) long elapsedTime = System.currentTimeMillis() - startTime; float timeForMethod = ((float) elapsedTime)/counter;

Accuracy Now accuracy is 10%. first reading may be just about to change to startTime second reading may have just changed to finishTime so finishTime - startTime is off by 100ms

Accuracy first reading may have just changed to startTime second reading may be about to change to finishTime so finishTime - startTime is off by 100ms

Accuracy Examining remaining cases, we get trueElapsedTime = finishTime - startTime ms To ensure 10% accuracy, require elapsedTime = finishTime – startTime >= 1sec

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;

The Fix long startTime = System.currentTimeMillis(); long counter; do { counter++; // put code to initialize a[] here InsertionSort.insertionSort(a); } while (System.currentTimeMillis() - startTime < 1000)

Time Shared System UNIX time MyProgram

Bad Way To Time do { counter++; startTime = System.currentTimeMillis(); doSomething(); elapsedTime += System.currentTimeMillis() - startTime; } while (elapsedTime < 1000)