1 Performance Measurement CSE, POSTECH 2 2 Program Performance Recall that the program performance is the amount of computer memory and time needed to.

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

Efficiency of Algorithms
Lecture3: Algorithm Analysis Bohyung Han CSE, POSTECH CSED233: Data Structures (2014F)
Programming Types of Testing.
90-723: Data Structures and Algorithms for Information Processing Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 2: Basics Data Structures.
Fundamentals of Python: From First Programs Through Data Structures
Chapter 1 – Basic Concepts
What is an Algorithm? (And how do we analyze one?)
CS 206 Introduction to Computer Science II 09 / 10 / 2008 Instructor: Michael Eckmann.
Introduction to Analysis of Algorithms
Efficiency of Algorithms
Scott Grissom, copyright 2004 Chapter 5 Slide 1 Analysis of Algorithms (Ch 5) Chapter 5 focuses on: algorithm analysis searching algorithms sorting algorithms.
Performance Measurement Performance Analysis Paper and pencil. Don’t need a working computer program or even a computer.
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.
Copyright © 1998 Wanda Kunkle Computer Organization 1 Chapter 2.1 Introduction.
Time Complexity s Sorting –Insertion sorting s Time complexity.
CS2420: Lecture 4 Vladimir Kulyukin Computer Science Department Utah State University.
CS 206 Introduction to Computer Science II 01 / 28 / 2009 Instructor: Michael Eckmann.
Elementary Data Structures and Algorithms
Lecture 3 Feb 7, 2011 Goals: Chapter 2 (algorithm analysis) Examples: Selection sorting rules for algorithm analysis Image representation Image processing.
Cmpt-225 Simulation. Application: Simulation Simulation  A technique for modeling the behavior of both natural and human-made systems  Goal Generate.
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]
Algorithm Analysis (Big O)
1 Chapter 2 Program Performance – Part 2. 2 Step Counts Instead of accounting for the time spent on chosen operations, the step-count method accounts.
Lecture 4 Loops.
Lecture 2 We have given O(n 3 ), O(n 2 ), O(nlogn) algorithms for the max sub-range problem. This time, a linear time algorithm! The idea is as follows:
Program Performance & Asymptotic Notations CSE, POSTECH.
For Wednesday Read Weiss chapter 3, sections 1-5. This should be largely review. If you’re struggling with the C++ aspects, you may refer to Savitch, chapter.
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)
Data Structures and Algorithms Lecture 5 and 6 Instructor: Quratulain Date: 15 th and 18 th September, 2009 Faculty of Computer Science, IBA.
Lecture 2 Computational Complexity
Analysis of Algorithms
Analysis of Algorithms CSCI Previous Evaluations of Programs Correctness – does the algorithm do what it is supposed to do? Generality – does it.
Chapter 10 Algorithm Analysis.  Introduction  Generalizing Running Time  Doing a Timing Analysis  Big-Oh Notation  Analyzing Some Simple Programs.
Performance Measurement Performance Analysis Paper and pencil. Don’t need a working computer program or even a computer.
Chapter 5 Algorithms (2) Introduction to CS 1 st Semester, 2015 Sanghyun Park.
SNU IDB Lab. Ch4. Performance Measurement © copyright 2006 SNU IDB Lab.
Basic Memory Management 1. Readings r Silbershatz et al: chapters
CS 206 Introduction to Computer Science II 09 / 18 / 2009 Instructor: Michael Eckmann.
Processor Structure and Function Chapter8:. CPU Structure  CPU must:  Fetch instructions –Read instruction from memory  Interpret instructions –Instruction.
CS 206 Introduction to Computer Science II 01 / 30 / 2009 Instructor: Michael Eckmann.
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.
1 Ch. 2: Getting Started. 2 About this lecture Study a few simple algorithms for sorting – Insertion Sort – Selection Sort (Exercise) – Merge Sort Show.
TAs Fardad Jalili: Aisharjya Sarkar: Soham Das:
CS2852 Week 2, Class 2 Today Big-O runtime analysis Linked Lists Muddiest Point Lab Quiz Includes writing a method from ArrayList class (See next slide)
Program Performance 황승원 Fall 2010 CSE, POSTECH. Publishing Hwang’s Algorithm Hwang’s took only 0.1 sec for DATASET1 in her PC while Dijkstra’s took 0.2.
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.
GC 211:Data Structures Week 2: Algorithm Analysis Tools Slides are borrowed from Mr. Mohammad Alqahtani.
Algorithm Complexity is concerned about how fast or slow particular algorithm performs.
Data Structures I (CPCS-204) Week # 2: Algorithm Analysis tools Dr. Omar Batarfi Dr. Yahya Dahab Dr. Imtiaz Khan.
Complexity Analysis (Part I)
Analysis of Algorithms
GC 211:Data Structures Algorithm Analysis Tools
Complexity In examining algorithm efficiency we must understand the idea of complexity Space complexity Time Complexity.
Algorithm Analysis CSE 2011 Winter September 2018.
Performance Measurement
GC 211:Data Structures Algorithm Analysis Tools
Performance Measurement
Analysis of Algorithms
Measuring Experimental Performance
Performance Measurement
Analysis of Algorithms
Performance Measurement
Performance Measurement
Complexity Analysis (Part I)
Analysis of Algorithms
Complexity Analysis (Part I)
Presentation transcript:

1 Performance Measurement CSE, POSTECH

2 2 Program Performance Recall that the program performance is the amount of computer memory and time needed to run a program. 1. Analytically - performance analysis 2. Experimentally - performance measurement The performance of a program depends on – the number and type of operations performed, and – the memory access pattern for the data and instructions

3 3 Performance Analysis Paper and pencil. Do NOT need a working computer program or even a computer.

4 4 Some Uses of Performance Analysis Why do want to do a performance analysis of algorithms? To determine the practicality of algorithm To predict run time on large instance To compare two algorithms that have different asymptotic complexity - e.g., O(n) and O(n 2 )

5 5 Limitations of Performance Analysis Does NOT account for constant factors. But constant factors may dominate 1000n vs. n 2 especially if we are interested only in n < 1000 Modern computers have a hierarchical memory organization with different access times for memory at different levels of the hierarchy.

6 Memory Hierarchy R L1 L2 MAIN ALU KB512KB512MB 1C2C10C100C C = CPU cycle Read Sections & 4.5.2

7 7 Limitations of Performance Analysis Performance analysis does not account for this difference in memory access times. Programs that do more work may take less time than those that do less work. – e.g., a program with a large operation count and a small number of accesses to slow memory may take less time than a program with a small operation count and a large number of accesses to slow memory

8 8 Performance Measurement Concerned with obtaining the actual space and time requirements of a program Actual space and time are dependent on – Compiler and options – Specific computer We do not generally consider run-time space requirements (read the reasons on page 122)

9 9 Performance Measurement Needs (1) l programming language l working program l computer l compiler and options to use g++ –O, –O2, -O3 (see manual pages for g++)

10 Performance Measurement Needs (2) l data to use for measurement 1. worst-case data 2. best-case data 3. average-case data  What is the worst-case, best-case, average-case data for insertionSort and how do you generate them? timing mechanism --- clock

11 Choosing Instance Size l We decide on which values of instance size (n) to use according to two factors: 1. the amount of time we want to perform 2. what we expect to do with the times l In practice, we generally need the times for more than three values of n (read the reasons on page 123)

12 Timing in C++ double clocksPerMillis = double(CLOCKS_PER_SEC) / 1000; // clock ticks per millisecond clock_t startTime = clock(); // code to be timed comes here double elapsedMillis = (clock() – startTime) / clocksPerMillis; // elapsed time in milliseconds

13 Shortcoming See Program 4.1 and its execution times in Figure 4.1 (what is wrong with these execution times?)  the time needed for the worst case sorts is too small for clock() to measure Clock accuracy – assume the clock is accurate to within 100 ticks – If the method returns the time of t, the actual time lies between max{0,t-100} and t+100 – For Figure 4.1, the actual time could be between 0-100

14 Shortcoming Repeat work many times to bring total time to be >= 1000 ticks See Program 4.2 What is the difference between Prog 4.1 & 4.2? See Figures 4.2 & 4.3 See Figure 4.4 (overhead measurement)

15 Accurate Timing clock_t startTime = clock(); long numberofRepetitions; do { numberofRepetitions++; doSomething(); } while (clock() - startTime < 1000) double elapsedMillis = (clock()- startTime) / clocksPerMillis; double timeForCode = elapsedMillis/numberofRepetitions;

16 Accuracy Now accuracy is 10%. First reading may be just about to change to startTime Second reading (final value of clock()) may have just changed to finishTime so finishTime - startTime is off by 100 ticks

17 First reading may have just changed to startTime Second reading may be about to change to finishTime so finishTime - startTime is off by 100 ticks Accuracy

18 Examining remaining cases, we get trueElapsedTime = finishTime - startTime ticks To ensure 10% accuracy, require elapsedTime = finishTime – startTime >= 1000 ticks Accuracy

19 What is wrong with the following measurement? long numberOfRepetitions = 0; // Program 4.3 clock_t elapsedTime = 0; do { numberOfRepetitions++; clock_t startTime = clock( ); doSomething(); elapsedTime += clock( ) - startTime; } while (elapsedTime < 1000); // repeat until enough time has elapsed

20 Answer to Ch. 4, Exercise 1 In each iteration of the do-while loop, the amount added to elapsedTime may deviate from the actual run time of doSomething by up to 100 ms (or 100 ticks). This error is additive over the iterations and so does not decline as a fraction of total time. For example, suppose that doSomething takes almost 100 ms. to execute. In the worst case, the clock reading will change just before each execution of the assignment startTime = clock() and the amount added to elapsedTime is zero on each iteration of the do-while loop; the do-while loop does not terminate. How do we fix this?

21 Time Measurement in Time Shared Systems UNIX – time MyProgram – See man pages for time Do Exercise 4.2 Read Chapter 4