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.

Slides:



Advertisements
Similar presentations
Programming for Beginners
Advertisements

How To Chord by Fritz Löhr
Code Tuning Strategies and Techniques
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.
Chapter Chapter 4. Think back to any very difficult quantitative problem that you had to solve in some science class How long did it take? How many times.
CMPT 225 Sorting Algorithms Algorithm Analysis: Big O Notation.
Shellsort. Review: Insertion sort The outer loop of insertion sort is: for (outer = 1; outer < a.length; outer++) {...} The invariant is that all the.
Introduction to Analysis of Algorithms
25-Jun-15 Refactoring III. General philosophy A refactoring is just a way of rearranging code Refactorings are used to solve problems If there’s no problem,
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.
Selection Sort, Insertion Sort, Bubble, & Shellsort
Introduction to a Programming Environment
SM3121 Software Technology Mark Green School of Creative Media.
Performance and Code Tuning Overview CPSC 315 – Programming Studio Fall 2009.
Cmpt-225 Simulation. Application: Simulation Simulation  A technique for modeling the behavior of both natural and human-made systems  Goal Generate.
Insertion Sort & Shellsort By: Andy Le CS146 – Dr. Sin Min Lee Spring 2004.
SharePoint document libraries I: Introduction to sharing files How to add and edit files Wondering how to actually work with a document library? You’re.
1 Programming Languages Examples: C, Java, HTML, Haskell, Prolog, SAS Also known as formal languages Completely described and rigidly governed by formal.
Search Lesson CS1313 Spring Search Lesson Outline 1.Searching Lesson Outline 2.How to Find a Value in an Array? 3.Linear Search 4.Linear Search.
1 1 Profiling & Optimization David Geldreich (DREAM)
CPU PROFILING FIND THE BOTTLENECK. WHAT? WHEN? HOW?
Pleasures and Pitfalls of Profiling Primož Gabrijelčič.
JavaScript & Metaperformance Douglas Crockford Yahoo! Inc.
Computer Programming and Basic Software Engineering 4. Basic Software Engineering 1 Writing a Good Program 4. Basic Software Engineering.
PHP meets MySQL.
Clearing your Cookies Internet Explorer A short guide to help you navigate our website faster Brought to you by:
According to Mrs. Hebda Middle School Gifted Facilitator USD 231.
Stephen P. Carl - CS 2421 Recursion Reading : Chapter 4.
CS453 Lecture 3.  A sequential algorithm is evaluated by its runtime (in general, asymptotic runtime as a function of input size).  The asymptotic runtime.
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,
Profile and optimize your Java code Gabriel Laden CS 146 – Dr. Sin-Min Lee Spring 2004.
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.
Introduction to Computer Systems Topics: Theme Five great realities of computer systems (continued) “The class that bytes”
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.
1 How will execution time grow with SIZE? int array[SIZE]; int sum = 0; for (int i = 0 ; i < ; ++ i) { for (int j = 0 ; j < SIZE ; ++ j) { sum +=
Outline Announcements: –HW III due Friday! –HW II returned soon Software performance Architecture & performance Measuring performance.
Hashing Fundamental Data Structures and Algorithms Margaret Reid-Miller 18 January 2005.
Compiling “premature optimization is the root of all evil.” -Donald Knuth.
Georgia Institute of Technology Speed part 4 Barb Ericson Georgia Institute of Technology May 2006.
Maths & Technologies for Games Optimisation for Games 1 CO3303 Week 4.
Am I RAM Or am I ROM?.
Winter 2006CISC121 - Prof. McLeod1 Stuff No stuff today!
1 Performance Issues CIS*2450 Advanced Programming Concepts.
AppMetrics for.NET Serviced Components Improving the performance of the Application, by giving you unique visibility and insight into the transaction paths.
COP 3540 Data Structures with OOP
BASICS OF CODE DESIGN.  Modular  Reusable  Easy to Read  Maintainable  Testable  Easy to Change  Easy to Understand THE GOAL.
Comments, Conditional Statements Continued, and Loops Engineering 1D04, Teaching Session 4.
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
Improving Matlab Performance CS1114
By Anand George SourceLens.org Copyright. All rights reserved. Content Owner - Meera R (meera at sourcelens.org)
Software Engineering Prof. Dr. Bertrand Meyer March 2007 – June 2007 Chair of Software Engineering Lecture #20: Profiling NetBeans Profiler 6.0.
What is it and why do we need it? Chris Ward CS147 10/16/2008.
CS 177 Recitation Week 1 – Intro to Java. Questions?
CSC 212 – Data Structures Lecture 15: Big-Oh Notation.
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.
. A little bit about optimization, 2d array, 1d array used as 2d, register and volatile.
Algorithm Complexity is concerned about how fast or slow particular algorithm performs.
Nov String Algorithms, Q Algorithmic programming...and testing your suffix trees...
Lecture 2: Performance Evaluation
Which slows more? Java or C++?
Introduction to Computer Systems
Refactoring III 27-Nov-18.
Which is better? 4-Dec-18.
Refactoring III 25-Dec-18.
Which is better? 15-May-19.
Which is better? 28-May-19.
Performance and Code Tuning Overview
ENERGY 211 / CME 211 Lecture 11 October 15, 2008.
Presentation transcript:

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 optimization: Sir Tony Hoare: “Premature optimization is the root of all evil.” Donald Knuth: “We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil.” W. A. Wulf: “More computing sins are committed in the name of efficiency (without necessarily achieving it) than for any other single reason - including blind stupidity.” Michael A. Jackson: “The First and Second Rules of Program Optimization: 1.Don’t do it. 2.(For experts only!) Don’t do it yet.” Richard Carlson: “Don’t sweat the small stuff.”

When should you optimize? Optimize when (and only when): A program you have written is taking too long to run A method you have written will be called millions or billions of times in a highly graphics-intensive application Your code is going into the kernel of an operating system One of the major principles of the XP (Extreme Programming) approach is: “Do the simplest thing that could possibly work.” In other words, don’t use a faster method in preference to a simpler one If it turns out to be too slow, you can fix it later However: If efficiency is completely ignored in a large project, it may be very difficult to fix it later Individual methods can be improved, but if the overall design of the project is inefficient, redesign can be prohibitively expensive

What should you optimize? From Wikipedia: In engineering, bottleneck is a phenomenon where the performance or capacity of an entire system is limited by a single component The 90/10 rule is: 90% of the runtime is taken up by 10% of the code That 10% is the bottleneck This is where significant improvements can be made How do you find the bottleneck? Intuition is surprisingly inaccurate A profiler is a program that measures which parts of your program are taking the most time (or using the most memory) Use a profiler before you waste your time optimizing the wrong part of the program!

What shouldn’t you optimize? Don’t sweat the small stuff Virtually any modern compiler is better at optimization than you are Consider: for (int i = 0; i limit) array[i] = limit; } Would this be faster if you took the assignment to limit out of the loop? No! The compiler will do that anyway In fact, there is a fair chance that doing so would slow your program down!

How should you optimize? The best way to speed up a bottleneck is to avoid doing it altogether! Example: In one case study I read about, one program added debugging information to a dataset; the dataset was sent to a second program, which stripped off the debugging information before using the dataset Eliminating the debugging information doubled the speed of the program The second best way is to find a faster algorithm This what a course in “Analysis of Algorithms” is all about Always remember, though, that in “real life” you should use a profiler to find out what to optimize The fastest sorting algorithm in the world won’t help you very much if you’re sorting a 10-element array

Aside: Timing without a profiler Here’s an easy way to time a section of code: long t = System.currentTimeMillis(); // code to be timed goes here t = System.currentTimeMillis() - t; System.out.println(t + " milliseconds");

Basic use of the NetBeans Profiler First, make sure the project you want to profile is NetBean’s “Main Project”

Adding the profiler to the project Next, choose Profile > Profile Main Project... You will get the following message; just click OK

Profile execution speeds Next, click CPU, then Part of application, then edit

Select root methods Select the methods you want to profile, then click OK

Run the program Click the Run button

Look at the results I’ve left out a couple of obvious steps This is just a very basic introduction--you should explore some of the options yourself

Problems with profiling Profiling is not as useful for distributed code For example, an application that runs on a server, accesses a database, makes remote calls, does input/output, etc., is too distributed for profiling to be much help Environment “noise” can be a problem Profiling is more meaningful in the absence of “alien” code, network access, input/output, etc. Try to isolate the code to be profiled from these factors Many Java compilers interpret the code the first time through, rather than compile it Run the code being tested multiple times, rather than just once Longer runs are better; ideally, your profiling run should take tens of seconds, or a few minutes

The End