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.

Slides:



Advertisements
Similar presentations
Code Tuning Strategies and Techniques
Advertisements

Tori Bowman CSSE 375, Rose-Hulman October 22, Code Tuning (Chapters of Code Complete)
When and How to Improve Code Performance? Ivaylo Bratoev Telerik Corporation
Code Tuning Strategies and Techniques CS524 – Software Engineering Azusa Pacific University Dr. Sheldon X. Liang Mike Rickman.
Part IV: Memory Management
Writing Modern C++ Marc Grégoire Software Architect April 3 rd 2012.
P3 / 2004 Register Allocation. Kostis Sagonas 2 Spring 2004 Outline What is register allocation Webs Interference Graphs Graph coloring Spilling Live-Range.
1 Chapter Six Algorithms. 2 Algorithms An algorithm is an abstract strategy for solving a problem and is often expressed in English A function is the.
CSE 1301 Lecture 6B More Repetition Figures from Lewis, “C# Software Solutions”, Addison Wesley Briana B. Morrison.
Chapter 1 Computer System Overview Patricia Roy Manatee Community College, Venice, FL ©2008, Prentice Hall Operating Systems: Internals and Design Principles,
Chapter XI Reduced Instruction Set Computing (RISC) CS 147 Li-Chuan Fang.
Analysis of Algorithms. Time and space To analyze an algorithm means: –developing a formula for predicting how fast an algorithm is, based on the size.
Reasons to study concepts of PL
Program Design and Development
Computer System Overview
Computer System Overview
Computer Science 1620 Programming & Problem Solving.
Code Tuning Techniques CPSC 315 – Programming Studio Spring 2008 Most examples from Code Complete 2.
Amdahl's Law.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
Performance and Code Tuning Overview CPSC 315 – Programming Studio Fall 2009.
1 Chapter 4. 2 Measure, Report, and Summarize Make intelligent choices See through the marketing hype Key to understanding underlying organizational motivation.
1 CHAPTER 4 LANGUAGE/SOFTWARE Hardware Hardware is the machine itself and its various individual equipment. It includes all mechanical, electronic.
Chapter 1: Introduction To Computer | SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2005 | Last Updated: July 2005 Slide 1 Introduction To Computers.
DATA STRUCTURE Subject Code -14B11CI211.
Code Tuning Strategies and Techniques CS480 – Software Engineering II Azusa Pacific University Dr. Sheldon X. Liang.
Advanced Decisions and Loops Chapter Some Simple Schoolroom Statistics.
Code-Tuning By Jacob Shattuck. Code size/complexity vs computation resource utilization A classic example: Bubblesort A classic example: Bubblesort const.
Chapter 1 Computer System Overview Patricia Roy Manatee Community College, Venice, FL ©2008, Prentice Hall Operating Systems: Internals and Design Principles,
Chapter 2.6 Comparison of Algorithms modified from Clifford A. Shaffer and George Bebis.
Computer Systems Overview. Page 2 W. Stallings: Operating Systems: Internals and Design, ©2001 Operating System Exploits the hardware resources of one.
IT253: Computer Organization Lecture 4: Instruction Set Architecture Tonga Institute of Higher Education.
Operating Systems and Networks AE4B33OSS Introduction.
Tot 15 LTPDA Graphic User Interface summary and status N. Tateo 26/06/2007.
Analysis of Algorithms CSCI Previous Evaluations of Programs Correctness – does the algorithm do what it is supposed to do? Generality – does it.
Operating Systems Lecture No. 2. Basic Elements  At a top level, a computer consists of a processor, memory and I/ O Components.  These components are.
Program Efficiency & Complexity Analysis. Algorithm Review An algorithm is a definite procedure for solving a problem in finite number of steps Algorithm.
Software Construction and Evolution - CSSE 375 Code Tuning Shawn and Steve Left – Even tuning an ancient instrument like a violin involves multiple steps.
1 Code optimization “Code optimization refers to the techniques used by the compiler to improve the execution efficiency of the generated object code”
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.
Optimised C/C++. Overview of DS General code Functions Mathematics.
Operating System Isfahan University of Technology Note: most of the slides used in this course are derived from those of the textbook (see slide 4)
Selection Statements. Introduction Today we learn more about learn to make decisions in Turing ▫Nested if statements, ▫case statements.
Chapter 11 Instruction Sets: Addressing Modes and Formats Gabriel Baron Sydney Chow.
Processor Structure and Function Chapter8:. CPU Structure  CPU must:  Fetch instructions –Read instruction from memory  Interpret instructions –Instruction.
Optimization of C Code The C for Speed
© Janice Regan, CMPT 128, February CMPT 128: Introduction to Computing Science for Engineering Students Recursion.
Computer Organization Instruction Set Architecture (ISA) Instruction Set Architecture (ISA), or simply Architecture, of a computer is the.
Chapter 1 Java Programming Review. Introduction Java is platform-independent, meaning that you can write a program once and run it anywhere. Java programs.
Improving Matlab Performance CS1114
Evolution of C and C++ n C was developed by Dennis Ritchie at Bell Labs (early 1970s) as a systems programming language n C later evolved into a general-purpose.
4 - Conditional Control Structures CHAPTER 4. Introduction A Program is usually not limited to a linear sequence of instructions. In real life, a programme.
Windows Programming Lecture 03. Pointers and Arrays.
Computer Systems Overview. Lecture 1/Page 2AE4B33OSS W. Stallings: Operating Systems: Internals and Design, ©2001 Operating System Exploits the hardware.
Introduction to Algorithms
Code Optimization.
Chapter 1 Computer System Overview
DDC 1023 – Programming Technique
A451 Theory – 7 Programming 7A, B - Algorithms.
Chapter 5 Decisions. Chapter 5 Decisions ssential uestion: How are Boolean expressions or operators used in everyday life?
Chapter 5: Repetition Structures
Algorithm Analysis CSE 2011 Winter September 2018.
Lecture 07 More Repetition Richard Gesick.
Chapter 6: Repetition Structures
Chapter 5: Repetition Structures
Programming Fundamentals (750113) Ch1. Problem Solving
Introduction to Algorithms
Code Tuning Techniques
Chapter 1 Computer System Overview
Programming Fundamentals (750113) Ch1. Problem Solving
Presentation transcript:

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 performance more- and in less time and with less harm to the code-than by code tuning.

Performance and Code Tuning  Efficiency as a priority  Program requirements  Program design  Class and routine design  Operating-system interactions  Code compilation  Hardware  Code tuning

Program Requirements  Performance is stated as priority more often than it actually is a requirement  Before you invest time solving a performance problem, make sure that you’re solving a problem that needs to be solved.

Program Design  Program design includes the major strokes of the design for a single program, mainly the way in which a program is divided into classes.  Some program designs make it difficult to write a high-performance system.

Class and Routine Design  Designing the internals of classes and routines presents another opportunity to design for performance.  The choice of data types and algorithms is a performance factor that can effect the program’s memory and execution speed.

Code Compilation  Compilers turn clear, high-level language code into optimized machine code.  If you choose the right compiler, you might not need to think about optimizing speed any further.

Hardware  Sometimes the cheapest and best way to improve a program’s performance is to buy new hardware.  If you’re developing custom software for a few in-house users, a hardware upgrade might be the cheapest option.

Code Tuning  Code tuning is the practice of modifying correct code in ways that make ir run more efficiently.  “Tuning” refers to small-scale changes that affect a single class, a single routine, or more commonly a few lines of code.

The Pareto Principle  The Pareto Principle states that you can get 80 percent of the result with 20 percent of the effort.  Jon Bentley describes a case in which a 1000 line program spent 80 percent of its time in a five-line square root routine. By tripling the speed of the square root routine, he doubled the speed of the program.

Old Wives’ Tales  Reducing the lines of code in a high-level language improves the speed or size of the resulting machine code.  Examples:  For i=1to 10 a[i] = I End for  A[1] = 1 A[2]=2 ….

Old Wives’ Tales  Certain operations are probably faster or smaller than others.  You should optimize as you go.  A fast program is just as important as a correct one.

Compiler Optimizations  Shop for a compiler because each compiler can add performance to certain parts of your code.

Common Sources of operations  Input/output operations  An operation that causes the operating system to swap pages of memory is much slower than an operation that works on only one page of memory  System calls can eat up a lot of time.  Avoid going to the system

Chapter 26: Code-Tuning Techniques

Stop Testing When You Know the Answer  negativeInputFound=false; For (…..){ if(input[i]<0){ negativeInputFound=true; }

Order Tests by Frequency  Arrange test so that the one that’s fastest and most likely to be true is performed first.  Switch statement.

Compare Performance of Similar Logic Structures  Switch statement vs. if statement VS.

Use Lazy Evaluation  Some things can wait to be calculated.

Jamming  Jamming is the result of combining two loops that operate on the same set of elements.

Unrolling  Often more lines of code can be more efficient.

Minimizing the Work inside loops  Improving readability  Saving pointers as a well named variable.

Putting the Busiest Loop on the inside  When you have nested loops it is better to put the bigger loop on the inside.  It can save time up to 33% in C++

Data transformations  Use integers rather than floating –point numbers.  Addition and multiplication of integers is faster then floating point values

Arrays  Use the fewest array dimensions as possible  Minimize Array references