TAs Fardad Jalili: Aisharjya Sarkar: Soham Das:

Slides:



Advertisements
Similar presentations
Write a program step by step. Step 1: Problem definition. Given the coordinate of two points in 2-D space, compute and print their straight distance.
Advertisements

Review for Final Exam Dilshad M. NYU. In this review Arrays Pointers Structures Java - some basic information.
Lecture3: Algorithm Analysis Bohyung Han CSE, POSTECH CSED233: Data Structures (2014F)
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
Computational Complexity 1. Time Complexity 2. Space Complexity.
What is an Algorithm? (And how do we analyze one?)
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.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 23 Algorithm Efficiency.
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];
Time Complexity s Sorting –Insertion sorting s Time complexity.
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.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 23 Algorithm Efficiency.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L18 (Chapter 23) Algorithm.
Chapter 7 (Part 2) Sorting Algorithms Merge Sort.
1 Performance Measurement CSE, POSTECH 2 2 Program Performance Recall that the program performance is the amount of computer memory and time needed to.
Data Structure & Algorithm Lecture 3 –Algorithm Analysis JJCAO.
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
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 23 Algorithm Efficiency.
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)
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
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:
Algorithm Efficiency and Sorting Data Structure & Algorithm.
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.
Performance Measurement Performance Analysis Paper and pencil. Don’t need a working computer program or even a computer.
CGS3460 Summer 2011 Programming Using C Andrei Todor.
SNU IDB Lab. Ch4. Performance Measurement © copyright 2006 SNU IDB Lab.
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.
CS 6290 Branch Prediction. Control Dependencies Branches are very frequent –Approx. 20% of all instructions Can not wait until we know where it goes –Long.
CSE1222: Lecture 1The Ohio State University1. Computing Basics  Computers CPU, Memory & Input/Output (IO)  Program Sequence of instructions for the.
Chapter 11  Getting ready to program  Hardware Model  Software Model  Programming Languages  Facts about C++  Program Development Process  The Hello-world.
End of the beginning Let’s wrap up some details and be sure we are all on the same page Good way to make friends and be popular.
ICS312 Introduction to Compilers Set 23. What is a Compiler? A compiler is software (a program) that translates a high-level programming language to machine.
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.
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.
Final Project of Computer Graphics
Development and Testing Ch4.1. Algorithm Analysis
Big-O notation.
Complexity In examining algorithm efficiency we must understand the idea of complexity Space complexity Time Complexity.
Performance Measurement
Lesson 15: Processing Arrays
Performance Measurement
Complexity Analysis of Algorithms
Measuring Experimental Performance
Performance Measurement
BlueJ: a very quick introduction
Performance Measurement
Interpreting Java Program Runtimes
Visibilities and Static-ness
Performance Measurement
Presentation transcript:

TAs Fardad Jalili: Aisharjya Sarkar: Soham Das:

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 )

Reminder

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 KB~512KB~512MB 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 le.g. C++/Java l working program lInsertion Sort l computer l compiler and options to use gcc –O2

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

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

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

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

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

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

Accuracy 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 Examining remaining cases, we get trueElapsedTime = finishTime - startTime ticks To ensure 10% accuracy, require elapsedTime = finishTime – startTime >= 1000 ticks

Timing in Java s Same semantics, slightly different syntax long startTime = System.nanoTime(); //Code to be measured System.out.println( "Elapsed time: " + (System.nanoTime() - startTime)); or Use micro-benmarking frameworks such as JMH

What Went Wrong? clock_t startTime = clock(); long numberOfRepetitions; do { numberOfRepetitions++; insertionSort(a, n); } while (clock() - startTime < 1000) double elapsedMillis = (clock()- startTime) / clocksPerMillis; double timeForCode = elapsedMillis/numberOfRepetitions;

The Fix clock_t startTime = clock(); long numberOfRepetitions; do { numberOfRepetitions++; // put code to initialize a[] here insertionSort(a, n) } while (clock() - startTime < 1000) double elapsedMillis = (clock()- startTime) / clocksPerMillis;

Time Shared System UNIX time MyProgram

To-do s 1. C++: – s 1’.Java (JMH): – architect-benchmarking htmlhttp:// architect-benchmarking html – Microbenchmarking/ Microbenchmarking/ s 2. Linux: –