Software Construction and Evolution - CSSE 375 Code Tuning Shawn and Steve Left – Even tuning an ancient instrument like a violin involves multiple steps.

Slides:



Advertisements
Similar presentations
Summer Computing Workshop. Introduction to Variables Variables are used in every aspect of programming. They are used to store data the programmer needs.
Advertisements

Code Tuning Strategies and Techniques
Tori Bowman CSSE 375, Rose-Hulman October 22, Code Tuning (Chapters of Code Complete)
Chapter 9. Performance Management Enterprise wide endeavor Research and ascertain all performance problems – not just DBMS Five factors influence DB performance.
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.
Designed and Presented by Dr. Ayman Elshenawy Elsefy Dept. of Systems & Computer Eng.. Al-Azhar University
Computer Abstractions and Technology
Programming in Visual Basic
TU/e Processor Design 5Z032 1 Processor Design 5Z032 The role of Performance Henk Corporaal Eindhoven University of Technology 2009.
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
CSE 1301 Lecture 6B More Repetition Figures from Lewis, “C# Software Solutions”, Addison Wesley Briana B. Morrison.
CIS 101: Computer Programming and Problem Solving Lecture 8 Usman Roshan Department of Computer Science NJIT.
Software Performance Engineering - SPE HW - Answers Steve Chenoweth CSSE 375, Rose-Hulman Tues, Oct 23, 2007.
Software Performance Engineering Steve Chenoweth CSSE 375, Rose-Hulman Tues, Oct 23, 2007.
Object (Data and Algorithm) Analysis Cmput Lecture 5 Department of Computing Science University of Alberta ©Duane Szafron 1999 Some code in this.
Loops – While, Do, For Repetition Statements Introduction to Arrays
Chapter 1 and 2 Computer System and Operating System Overview
Computer Science 1620 Programming & Problem Solving.
Chapter 4 Assessing and Understanding Performance
1 Software Testing and Quality Assurance Lecture 40 – Software Quality Assurance.
Computer Organization and Architecture
Code Tuning Techniques CPSC 315 – Programming Studio Spring 2008 Most examples from Code Complete 2.
Code Tuning Techniques CPSC 315 – Programming Studio Fall 2009 Most examples from Code Complete 2.
1 Chapter 4. 2 Measure, Report, and Summarize Make intelligent choices See through the marketing hype Key to understanding underlying organizational motivation.
Code Tuning Strategies and Techniques CS480 – Software Engineering II Azusa Pacific University Dr. Sheldon X. Liang.
Chapter Seven Advanced Shell Programming. 2 Lesson A Developing a Fully Featured Program.
Jun 16, 2014IAT 2651 Debugging. Dialectical Materialism  Dialectical materialism is a strand of Marxism, synthesizing Hegel's dialectics, which proposes.
Data Structures & AlgorithmsIT 0501 Algorithm Analysis I.
Chapter 13 Recursion. Topics Simple Recursion Recursion with a Return Value Recursion with Two Base Cases Binary Search Revisited Animation Using Recursion.
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
1 Computing Software. Programming Style Programs that are not documented internally, while they may do what is requested, can be difficult to understand.
Module 7 Reading SQL Server® 2008 R2 Execution Plans.
CS 114 – Class 02 Topics  Computer programs  Using the compiler Assignments  Read pages for Thursday.  We will go to the lab on Thursday.
Copyright © 2006 Addison-Wesley. All rights reserved.1-1 ICS 410: Programming Languages.
S2008Final_part1.ppt CS11 Introduction to Programming Final Exam Part 1 S A computer is a mechanical or electrical device which stores, retrieves,
IT253: Computer Organization
An Object-Oriented Approach to Programming Logic and Design Fourth Edition Chapter 5 Arrays.
1 CS/EE 362 Hardware Fundamentals Lecture 9 (Chapter 2: Hennessy and Patterson) Winter Quarter 1998 Chris Myers.
How to Build a CPU Cache COMP25212 – Lecture 2. Learning Objectives To understand: –how cache is logically structured –how cache operates CPU reads CPU.
CSE332: Data Abstractions Lecture 8: Memory Hierarchy Tyler Robison Summer
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.
What does C store? >>A = [1 2 3] >>B = [1 1] >>[C,D]=meshgrid(A,B) c) a) d) b)
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.
By Teacher Asma Aleisa Year 1433 H.   Goals of memory management  To provide a convenient abstraction for programming.  To allocate scarce memory.
13-1 Sequential File Processing Chapter Chapter Contents Overview of Sequential File Processing Sequential File Updating - Creating a New Master.
SNU OOPSLA Lab. 1 Great Ideas of CS with Java Part 1 WWW & Computer programming in the language Java Ch 1: The World Wide Web Ch 2: Watch out: Here comes.
ITI 1120 Lab #3 Tracing and Branching Contributors: G. Arbez, M. Eid, D. Inkpen, A. Williams, D. Amyot.
13- 1 Chapter 13.  Overview of Sequential File Processing  Sequential File Updating - Creating a New Master File  Validity Checking in Update Procedures.
Intermediate 2 Computing Unit 2 - Software Development.
More Python!. Lists, Variables with more than one value Variables can point to more than one value at a time. The simplest way to do this is with a List.
1  1998 Morgan Kaufmann Publishers How to measure, report, and summarize performance (suorituskyky, tehokkuus)? What factors determine the performance.
Chapter 7 Problem Solving with Loops
Structuring Data: Arrays ANSI-C. Representing multiple homogenous data Problem: Input: Desired output:
March 1, 2004CS WPI1 CS 509 Design of Software Systems Lecture #6 Monday, March 1, 2004.
CompSci Today’s topics Machine Architecture The basic machine Basic programming Assembler programming Upcoming Language Translation Reading Great.
IMS 4212: Database Implementation 1 Dr. Lawrence West, Management Dept., University of Central Florida Physical Database Implementation—Topics.
CSCI 156: Lab 11 Paging. Our Simple Architecture Logical memory space for a process consists of 16 pages of 4k bytes each. Your program thinks it has.
EGRE 426 Computer Organization and Design Chapter 4.
CSC 212 – Data Structures Lecture 15: Big-Oh Notation.
Dynamicpartnerconnections.com Development for performance Oleksandr Katrusha, Program manager
4 - Conditional Control Structures CHAPTER 4. Introduction A Program is usually not limited to a linear sequence of instructions. In real life, a programme.
Discussion 4 eecs 183 Hannah Westra.
Code Optimization.
Topics Introduction to Repetition Structures
Informatica PowerCenter Performance Tuning Tips
Conditional Statements
Steve Hood SimpleSQLServer.com
Computer Organization and Design Chapter 4
Presentation transcript:

Software Construction and Evolution - CSSE 375 Code Tuning Shawn and Steve Left – Even tuning an ancient instrument like a violin involves multiple steps. Here is fine tuning, being done after coarse tuning has been accomplished using the pegs on the other end.

2 RHIT is all about the tuning! Brief Overview of Code Tuning

3 Historical Context  1960s: When Dinosaurs Roamed the Earth :-) l Resources decidedly limited l Nothing more important than efficient use of resources  1970s: Dinosaurs got faster l Computing improves l Realizing how much it hurt readability and maintainability  1980s: Dinosaurs giving way to warm bloods l Microcomputers brought efficiency issues back l Waned in throughout the 1990s  2000s: Not many Dinosaurs anymore… l Memory in embedded issues becomes the efficiency concern

4 Example: Performance Requirements You have a system that monitors economic transactions for say Amazon.com  Critical use cases / scenarios: l 60K transactions per hour (peak) l Each validated transaction updates status and activity information in the memory of a server l 5 displays for people watching –Monitor exception transactions and statistics l Screens must automatically update every 10 seconds l Every 10 minutes the in-memory information is saved to disk, using SQL-Server

5 Example: System Performance Architecture  Design looks something like this figure above  60,0000 trans/hr = 1000 trans/min = 60 ms/trans  Naïvely assume each of the 3 functions on a transaction takes equal time  So, they each have to be done in 20 ms What are the two performance “lumps”? Can they be tuned out? Trans validate Find exceptions Update displays Put in DB Update stats Trans Input Stream 60k/hr 20 ms? Every 10 sec Every 10 min Q1 “Every” means “batched.”

Step One on this example…  Somebody had to be working the performance concerns from Day 1 of the project.  You can’t wait till it hits the test lab, then expect to tune to spec something this big!  Problem is you don’t really SEE the issues until it does hit the lab.  So, you can get lulled into thinking everything is ok. l And focus just on writing features.  If the architecture isn’t right, you could have to start over.  See CSSE 477 for more! 6

7 Program Requirements Example  Initial requirement: sub-second response time l Highly complex design l Estimate cost: $100 million  Further analysis: l User’s happy with four-second response time 90% of the time l Reduced system cost by ~$70 million Make sure you’re solving a problem that needs to be solved Q2

8 Pareto Principle – 80/20 Rule  80% of result is achieved by 20% of effort  “An Empirical Study of Fortran Programs” by Donald Knuth l < 4% of a program accounts for more than 50% of it’s run-time How does this relate to code tuning? Q3

9 Let’s consider… Reducing the lines of code in a high- level language improves speed or the size of the resulting machine code. (Pick which one – it matters.)

10 Which is faster? for i = 1 to 10 a[ i ] = i end for a [ 1 ] = 1 a [ 2 ] = 2 a [ 3 ] = 3 a [ 4 ] = 4 a [ 5 ] = 5 a [ 6 ] = 6 a [ 7 ] = 7 a [ 8 ] = 8 a [ 9 ] = 9 a [ 10 ] = 10 Q4

11 Results… Language for-Loop Time Straight- code time Time Savings Perform- ance Ratio C %2.5:1 Java %4:1 You had some of this in CSSE 132, etc.

12 Common Sources of Inefficiencies  I/O Operations  Paging  System Calls  Interpreted languages  Errors

13 Good Tips on Logic  Stop testing when you know the answer l Short circuit in conditionals and loops l Standard with C++ and Java  Order tests by frequency  Compare performance of similar logic structures l Some languages case is faster than if-then-else  Substitute table lookups for complicated expressions Q5, Q7

14 Loops – Make Decisions outside of Loop  Putting the loop inside the conditional  Good for ~20% time savings for ( i = 0; i < count; i++ ) { if ( sumType == SUMTYPE_NET) netSum = netSum + amount[ i ]; else grossSum = grossSum + amount[ i ]; } if ( sumType == SUMTYPE_NET) { for ( i = 0; i < count; i++ ) netSum = netSum + amount[ i ]; } else { for ( i = 0; i < count; i++ ) grossSum = grossSum + amount[ i ]; }

15 More Loops  Jamming l Combine loops that operate over the same elements  Unrolling l Reduce the amount of loop housekeeping  Minimize work inside of the loop l Assign complicated pointer expressions to a well-named variable

16 More Loops (continued)  Sentinel values l Simplifying compound tests  Nested loops: l Put busiest loop on the inside  Strength reduction l Replace expensive operations (multiplication) with cheaper operations (addition) Q6, Q8

17 Data Transformations  Use integers rather than floating-point numbers  Use the fewest array dimensions possible  Minimize array references  Use supplementary indexes  Use caching  Much more in books like Steve McConnell’s Code Complete… Q9

18 Can Refactoring and Design Patterns coexist with Code Tuning?  Yes, but pick your battles…  Know the landscape of requirements and constraints  Balance Performance & Maintainability l Design Performance in the large l Tune code locally