CS 3500 L12 - 1 Performance l Code Complete 2 – Chapters 25/26 and Chapter 7 of K&P l Compare today to 44 years ago – The Burroughs B1700 – circa 1974.

Slides:



Advertisements
Similar presentations
Code Tuning Strategies and Techniques
Advertisements

Tori Bowman CSSE 375, Rose-Hulman October 22, Code Tuning (Chapters of Code Complete)
Code Optimization and Performance Chapter 5 CS 105 Tour of the Black Holes of Computing.
ECE 454 Computer Systems Programming Compiler and Optimization (I) Ding Yuan ECE Dept., University of Toronto
Performance What differences do we see in performance? Almost all computers operate correctly (within reason) Most computers implement useful operations.
Lecture 1: Overview of Computers & Programming
CS 3500 SE - 1 Software Engineering: It’s Much More Than Programming! Sources: “Software Engineering: A Practitioner’s Approach - Fourth Edition” Pressman,
1 Lecture 6 Performance Measurement and Improvement.
Computer System Overview
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.
Performance Improvement
30-Jun-15 Profiling. Optimization Optimization is the process of making a program as fast (or as small) as possible Here’s what the experts say about.
Recursion Chapter 7. Chapter 7: Recursion2 Chapter Objectives To understand how to think recursively To learn how to trace a recursive method To learn.
Guide To UNIX Using Linux Third Edition
FIGURE 1-1 A Computer System
Simple Sorting Algorithms. 2 Bubble sort Compare each element (except the last one) with its neighbor to the right If they are out of order, swap them.
DATA STRUCTURE Subject Code -14B11CI211.
Code Tuning Strategies and Techniques CS480 – Software Engineering II Azusa Pacific University Dr. Sheldon X. Liang.
The Study of Computer Science Chapter 0 Intro to Computer Science CS1510, Section 2.
Chapter 3 Memory Management: Virtual Memory
Invitation to Computer Science 5th Edition
Topic #10: Optimization EE 456 – Compiling Techniques Prof. Carl Sable Fall 2003.
An Introduction Chapter Chapter 1 Introduction2 Computer Systems  Programmable machines  Hardware + Software (program) HardwareProgram.
Analysis CS 367 – Introduction to Data Structures.
1 Welcome to CS 362 Applied Software Engineering What happens after (and during) design? Testing, debugging, maintaining programs Lessons for software.
Structured programming 4 Day 34 LING Computational Linguistics Harry Howard Tulane University.
Chapter 1 What is Programming? Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition) by S.N. Kamin, D. Mickunas, E.
1 Advance Computer Architecture CSE 8383 Ranya Alawadhi.
Today  Table/List operations  Parallel Arrays  Efficiency and Big ‘O’  Searching.
Stephen P. Carl - CS 2421 Recursion Reading : Chapter 4.
Just as there are many human languages, there are many computer programming languages that can be used to develop software. Some are named after people,
CS 346 – Chapter 1 Operating system – definition Responsibilities What we find in computer systems Review of –Instruction execution –Compile – link – load.
Chapter 25: Code-Tuning Strategies. Chapter 25  Code tuning is one way of improving a program’s performance, You can often find other ways to improve.
Fundamental Programming: Fundamental Programming K.Chinnasarn, Ph.D.
CSE 303 Concepts and Tools for Software Development Richard C. Davis UW CSE – 12/6/2006 Lecture 24 – Profilers.
1 Code optimization “Code optimization refers to the techniques used by the compiler to improve the execution efficiency of the generated object code”
CS 127 Introduction to Computer Science. What is a computer?  “A machine that stores and manipulates information under the control of a changeable program”
Outline Announcements: –HW III due Friday! –HW II returned soon Software performance Architecture & performance Measuring performance.
Compiler Optimizations ECE 454 Computer Systems Programming Topics: The Role of the Compiler Common Compiler (Automatic) Code Optimizations Cristiana Amza.
Georgia Institute of Technology Speed part 4 Barb Ericson Georgia Institute of Technology May 2006.
M1G Introduction to Programming 2 3. Creating Classes: Room and Item.
1 Performance Issues CIS*2450 Advanced Programming Concepts.
Chapter 1 Basic Concepts of Operating Systems Introduction Software A program is a sequence of instructions that enables the computer to carry.
Searching Topics Sequential Search Binary Search.
The single most important skill for a computer programmer is problem solving Problem solving means the ability to formulate problems, think creatively.
Copyright 2014 – Noah Mendelsohn Performance Analysis Tools Noah Mendelsohn Tufts University Web:
Performance* Objective: To learn when and how to optimize the performance of a program. “ The first principle of optimization is don ’ t. ” –Knowing how.
What is it and why do we need it? Chris Ward CS147 10/16/2008.
CS412/413 Introduction to Compilers and Translators April 2, 1999 Lecture 24: Introduction to Optimization.
Outline Announcements: –HW II Idue Friday! Validating Model Problem Software performance Measuring performance Improving performance.
CS 177 Recitation Week 1 – Intro to Java. Questions?
Memory Design Principles Principle of locality dominates design Smaller = faster Hierarchy goal: total memory system almost as cheap as the cheapest component,
Winter 2016CISC101 - Prof. McLeod1 CISC101 Reminders Assignment 5 is posted. Exercise 8 is very similar to what you will be doing with assignment 5. Exam.
Introduction to Computer Programming Concepts M. Uyguroğlu R. Uyguroğlu.
©SoftMoore ConsultingSlide 1 Code Optimization. ©SoftMoore ConsultingSlide 2 Code Optimization Code generation techniques and transformations that result.
July 10, 2016ISA's, Compilers, and Assembly1 CS232 roadmap In the first 3 quarters of the class, we have covered 1.Understanding the relationship between.
Code Optimization.
Understanding Operating Systems Seventh Edition
Optimization Code Optimization ©SoftMoore Consulting.
CSCI1600: Embedded and Real Time Software
Lesson 15: Processing Arrays
Big O Notation.
Compiler Code Optimizations
15-110: Principles of Computing
Tonga Institute of Higher Education IT 141: Information Systems
Tonga Institute of Higher Education IT 141: Information Systems
slides created by Ethan Apter
Complexity Based on slides by Ethan Apter
CSCI1600: Embedded and Real Time Software
Embedded System Development Lecture 12 4/4/2007
Presentation transcript:

CS 3500 L Performance l Code Complete 2 – Chapters 25/26 and Chapter 7 of K&P l Compare today to 44 years ago – The Burroughs B1700 – circa 1974 l Why do we care about performance today? l First principle of optimization: – DON’T l Second principle of optimization: – DON’T l Third principle of optimization – DON’T B1700Today Proc Spd6Mhz3.8Ghz (dual) Memory64KB2GB Disk2.3MB hd per track 1TB InputCards Keyboard/ Monitor LangSDLC++ Cost?50K1K

CS 3500 L Optimization l Easiest technique is to turn on the compiler’s optimizer l In VS.NET do a release build vs. debug build l Makes debugging harder l Hopefully doesn’t introduce new bugs – But could if there are non-deterministic parts of the program already – Also, debug mode is known to initialize locations for easy debugging but your code may count on that initialization

CS 3500 L Optimization - 2 l Measurement is the critical component before deciding that you should worry about performance improvement l Make sure that you have good regression tests – Eliminates issue of optimizing something so it is so fast that you forgot to preserve the semantics and it doesn’t work any more l Often algorithm analysis is the most fruitful place to start l How much faster is binary search than linear search on a one million element array? l See you in CS 4150!

CS 3500 L Targets of Improvement l Program design: how a program is divided into classes may make it hard or easy to improve performance l Class & method design: choice of data types, algorithms l Operating system interactions l Code compilation: the right compiler may be all you need l Hardware: why not a hardware upgrade? l Code tuning: small scale changes to correct code with hopes of running faster (or smaller)

CS 3500 L Timing l Easiest is to use time mechanism provided by system – 5 faith> time clean.csh – 0.0u 2.0s 0:08 24% 0+0k 0+0io 0pf+0w – 6 faith> l How about on Windows? – C:\Documents and Settings\kessler>time – The current time is: 10:06:08.06 – Enter the new time: – C:\Documents and Settings\kessler> l So, what should you do on systems like Windows to get a coarse view of time? – #include – double begin = clock(); –…–… – double result = clock() – begin; // time in ms

CS 3500 L The Pareto Principle (20% of Italians have 80% of the wealth) You can get 80% of the result with 20% of the effort. l 20% of a program consumes 80% of its execution time (Boehm) l Less than 4% of a program accounts for more than 50% of the run time (Knuth) l Measure your code for hot spots, and then put resources into optimizing the small portion(s) of the program used most

CS 3500 L Profiling l What is a profile? – A measure of where a program spends its time l Provides more detailed timing information about a program – Number of times a function is called – Percentage of execution time spent in a function – Some provide the information in a line by line fashion l Profiling is effective for finding hot spots in a program l How does a profiler work?

CS 3500 L Misconceptions l Reducing the lines of code in a high-level language improves the speed or size of the resulting machine code l Certain operations are probably faster or smaller than others l You should optimize as you go l A fast program is as important as a correct one l A fast program is as important as a readable one

CS 3500 L Strategies l After deciding that you HAVE to optimize: – Measure – Track down slow parts – Remember important principle – if you improve one part so it takes no time, your program will only get x% faster if the part you are optimizing is taking x% of the time l Use a better algorithm or data structure – Try to determine complexity l Enable compiler optimizations – Measure before and after to make sure it is worth it l Tune the code – Adjust the loops and expressions to be faster l Don’t optimize what doesn’t matter – Rule of thumb – your time vs. how much time you’ll save over the lifetime of the program

CS 3500 L Tuning The Code l Collect common subexpressions – Is probably not worth it these days l Reduction in strength of operations – Again is probably not worth it these days l Unroll or eliminate loops – Short loop vs. 3 lines – Again – many good compilers will do this already l Cache frequently used values – Again – compilers are pretty good at this l Rewrite in a lower-level language – Costs programmer time l Good, modern compilers – Already do much of this – Are often better at it than you are – Are faster – Better at optimizing straightforward code than tricky code – Can often improve your code by 40% or more!!

CS 3500 L Quote from McConnell – About Code-Tuning Optimizations “Computers are dramatically faster and memory is more plentiful. In the first edition [written 10 years ago], I ran most of the tests in this chapter [26] 10,000 to 50,000 times to get meaningful, measurable results. For this edition I had to run most tests 1 million to 100 million times. When you have to run a test 100 million times to get measurable results, you have to ask whether anyone will ever notice the impact in a real program. Computers have become so powerful that for many common kinds of programs, the level of performance optimization discussed in this chapter has become irrelevant. … People writing desktop applications may not need this information, but people writing software for embedded systems, real-time systems, and other systems with strict speed or space restrictions can still benefit from it.” – pg , Chapter 26.7, Code Complete 2.

CS 3500 L Space Efficiency l Time is not the only measure of a program’s performance – Which is more important space or time? l First principle of space optimization? – Don’t do it l What is paging? Caching? Why do we care? l Use the smallest possible data type – int vs. short l Don’t store what you can easily recompute – What tradeoff is going on here? – Image compression description is a good one to consider

CS 3500 L Summary l The best is the enemy of the good l Don’t do space or time optimization – Unless you have to – Unless you have measured it – Unless you know where the hot spots are – Unless you decide what real improvements are possible l Check algorithms and data structures – Can have the single most benefit – “Don’t put lipstick on a pig!!! ” l Turn on compiler optimization l Be careful of hardware differences – A PC with a big cache vs. no cache l Resort to detailed tuning only as last resort or if your environment demands it

CS 3500 L Notes About Tools l VS.Net 2005 has its own performance tools which was demonstrated in discussion yesterday