Measuring Experimental Performance

Slides:



Advertisements
Similar presentations
Analysys & Complexity of Algorithms Big Oh Notation.
Advertisements

CMPUT 101 Lab # 5 October 22, :00 – 17:00.
1 Data Structures Performance Analysis. 2 Fundamental Concepts Some fundamental concepts that you should know: –Dynamic memory allocation. –Recursion.
1 9/29/06CS150 Introduction to Computer Science 1 Loops Section Page 255.
Complexity Analysis (Part I)
Data Structures Performance Analysis.
Lecture 3 Aug 31, 2011 Goals: Chapter 2 (algorithm analysis) Examples: Selection sorting rules for algorithm analysis discussion of lab – permutation generation.
CS 240: Data Structures Thursday, July 12 th Vector, Algorithms, Recursion.
CS2420: Lecture 4 Vladimir Kulyukin Computer Science Department Utah State University.
CS 240: Data Structures Supplemental: Command Line Input.
1 Performance Measurement CSE, POSTECH 2 2 Program Performance Recall that the program performance is the amount of computer memory and time needed to.
Algorithm Analysis (Big O)
Algorithm Analysis & Complexity We saw that a linear search used n comparisons in the worst case (for an array of size n) and binary search had logn comparisons.
Program Performance & Asymptotic Notations CSE, POSTECH.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved ADT Implementation:
SEARCHING, SORTING, AND ASYMPTOTIC COMPLEXITY Lecture 12 CS2110 – Fall 2009.
1 Recursion Algorithm Analysis Standard Algorithms Chapter 7.
Algorithm Analysis. Algorithm An algorithm is a clearly specified set of instructions which, when followed, solves a problem. recipes directions for putting.
CS 1704 Introduction to Data Structures and Software Engineering.
Analysis of Algorithms
1 7.Algorithm Efficiency What to measure? Space utilization: amount of memory required  Time efficiency: amount of time required to process the data Depends.
Searching. RHS – SOC 2 Searching A magic trick: –Let a person secretly choose a random number between 1 and 1000 –Announce that you can guess the number.
1 7.Algorithm Efficiency What to measure? Space utilization: amount of memory required  Time efficiency: amount of time required to process the data.
Analysis of Algorithms CSCI Previous Evaluations of Programs Correctness – does the algorithm do what it is supposed to do? Generality – does it.
1 Dr. J. Michael Moore Data Structures and Algorithms CSCE 221 Adapted from slides provided with the textbook, Nancy Amato, and Scott Schaefer.
CSE 332: C++ execution control statements Overview of C++ Execution Control Expressions vs. statements Arithmetic operators and expressions * / % + - Relational.
Chapter 10 Algorithm Analysis.  Introduction  Generalizing Running Time  Doing a Timing Analysis  Big-Oh Notation  Analyzing Some Simple Programs.
CISC 235: Topic 1 Complexity of Iterative Algorithms.
Algorithm Analysis (Big O)
PROGRAMMING 1 – REPORT ACKNOWLEDGEMENT: THE SLIDES ARE PREPARED FROM SLIDES PROVIDED BY NANCY M. AMATO AND JORY DENNY 1.
1 Chapter 2 Algorithm Analysis All sections. 2 Complexity Analysis Measures efficiency (time and memory) of algorithms and programs –Can be used for the.
1 Chapter 2 Algorithm Analysis Reading: Chapter 2.
CSE 3358 NOTE SET 2 Data Structures and Algorithms 1.
Infinite for Loop If you omit the test condition, the value is assumed to be TRUE so the loop will continue indefinitely unless you provide some other.
(Complexity) Analysis of Algorithms Algorithm Input Output 1Analysis of Algorithms.
Algorithm Analysis 1.
Complexity Analysis (Part I)
CS212: Object Oriented Analysis and Design
Chapter 2 Algorithm Analysis
Theoretical analysis of time efficiency
Analysis of Algorithms
Analysis of Algorithms
C++ Programming: CS150 For.
Development and Testing Ch4.1. Algorithm Analysis
Analysis of Algorithms
Big-O notation.
Multi-dimensional Array
DATA HANDLING.
Templates ACKNOWLEDGEMENT: THE SLIDES ARE PREPARED FROM SLIDES PROVIDED BY NANCY M. AMATO AND JORY DENNY.
Big-Oh and Execution Time: A Review
Random Number Generation
Lab 03 - Iterator.
CS 3343: Analysis of Algorithms
GC 211:Data Structures Algorithm Analysis Tools
Performance Measurement
Arrays November 8, 2017.
Algorithm Efficiency Chapter 10.
Lecture 6 Efficiency of Algorithms (2) (S&G, ch.3)
Analysys & Complexity of Algorithms
Analysis of Algorithms
Searching, Sorting, and Asymptotic Complexity
Parasol Lab, Texas A&M University
Time Complexity Lecture 15 Mon, Feb 27, 2006.
Sum this up for me Let’s write a method to calculate the sum from 1 to some n public static int sum1(int n) { int sum = 0; for (int i = 1; i
Performance Measurement
CS210- Lecture 2 Jun 2, 2005 Announcements Questions
C++ Basics CSci 107. A C++ program //include headers; these are modules that include functions that you may use in your //program; we will almost always.
Complexity Analysis (Part I)
Analysis of Algorithms
Complexity Analysis (Part I)
Presentation transcript:

Measuring Experimental Performance CSCE 221H Parasol Lab, Texas A&M University 1 1

Designing Experiments Experiments should test average, best, and worst case inputs Experiments are designed by keeping all but a few (usually one) variables constant and measuring output E.g., input size varies, measure time, and keep all algorithm variables constant Experimental design is an art! Attempt to show strength AND weaknesses (limits) of an algorithm Comparing two algorithms should have equivalent inputs

Timing Dedicated machine, minimal background processes Measure “wallclock” time ctime Measure within clock resolution Average multiple executions

Example: STL Accumulate accumulate(vec.begin(), vec.end(), 0); Accumulates elements in a container Complexity: O(n)

Example: Experimental Setup double run_test(size_t _size, int _num_itr) { //create vector, allocating _size elements vector<double> random_vector(_size); //randomly generate input data generate(random_vector.begin(), random_vector.end(), rand); //begin timing clock_t k=clock(); clock_t start; do start = clock(); //begin at new tick while (start == k); //Run accumulate _num_itr times double sum(0.0); for(int i=0; i<_num_itr; ++i) { sum += accumulate(random_vector.begin(), random_vector.end(), double(0.0)); } //end timing clock_t end = clock(); cout << sum << ", "; double elapsed_time = double(end - start) / double(CLOCKS_PER_SEC); return elapsed_time / double(_num_itr);

Example: Experimental Setup int main(int argc, char** argv) { cout << setprecision(10); cout << "Sum, Size, Time(sec)" << endl; size_t size = 2; while( size <= 200000000) { cout << size << ", " << run_test(size,10+int(10000000/size)) << endl; size *=2; } return 0;

Example: Gather Results Choose appropriate input size range Run experiments, average multiple executions Size Time (sec) 2 8.000E-08 4 1.200E-07 8 1.600E-07 16 3.199E-07 32 6.398E-07 … 33554432 7.280E-01 67108864 1.455E+00

Example: Timing Small Input Small input may be too small to time individually Execute many iterations under one timer and average May need 1M iterations for very small input

Plot Time vs. Input Size

Finding Big-O constants 0 <= f(n) <= c*g(n), for all n >=n0 Find constants : c and n0 Plot time/expectedTime vs. input size May need log-x plot

Big O constant c & n0 value

Summary Experimental code setup Gather timing data Display results Average, best, worst case performance. To test the limit of algorithm Fair comparison : Equivalent inputs Gather timing data Appropriate range of input data Average multiple iterations Display results

Exercise Using the accumulate as an example, prepare a program for measuring the running time of the STL sort algorithm. Your program should put the elements to be sorted into an STL vector and it should produce timing results that let you investigate the experimental performance of the algorithm. Determine the appropriate amount of data points needed for step 2. After you have collected the timing results for the sorting algorithm, you should make plots similar to those for accumulate so that you can explore the relationship of the theoretical and experimental performance. You will need to know the complexity of sort(), which is O(nlogn).