7 views

Uploaded by Pritish Pradhan

optimisation basics

- A Unique Sorting Algorithm With Linear Time & Space Complexity
- Household Living Arrangement in Singapore
- Neeraj Mca
- JAVA
- Revision Proof by Induction
- First Term
- 00010036
- ampol
- OverviewAndMath01 (1)
- CalcII Seq Series
- Seq and Series Review Hw 10
- Function Property Browser
- Oops Lab Notes
- Calculus II - Sequences and Series
- Car Quarter Modeling
- IRJET-A comparative Study of Sorting Algorithms Comb, Cocktail and Counting Sorting
- COMP211slides_14
- Ch5.pdf
- OO Case Studies with Patterns and C++
- Projec29000

You are on page 1of 17

Gabriel Laden CS 146 – Dr. Sin-Min Lee Spring 2004

Introduction • O(n) notation is one thing • Performance of your coded algorithm is another thing!!! • This demo will use Homework #3 “ICBaseCycle” problem .

.currentTimeMillis().Where to start testing? • To find run-time between two sequential lines in your code insert the following: System.

The 80/20 rule • Your code spends 80% of its time in 20% of the code. or so they say… • How to find this hotspot in your code without just guessing : java –Xprof class [args] .

java –Xprof class [args] • -Xprof is a built-in profiler for your code • It tells you what % time is spent in running and other Java administrative tasks • Caution: eliminate your user I/O and other things like that which are not constant and will throw off your testing results .

Other interesting java –X options • -Xloggc:<file> log GC status to a file with time stamps Note: see use later in presentation • -Xmx<size> set maximum Java heap size Note: 64M is default. good use is for problems of moderately larger size. (go buy more memory at Fry’s) • -Xss<size> set java thread stack size Note: good use in recursive problems .

i.. javap prints out the package.javap . If no options are used.The Java Class File Disassembler javap [options] class • The javap command disassembles a class file.e. protected. Its output depends on the options used. and public fields and methods of the classes passed to it. the instructions that comprise the Java bytecodes . • -c option prints out disassembled code.

Most Important Step!!! • Find your inner-most loop that is in method with largest run-time % • Re-write this loop to be most efficient • This is where O(n) notation theory can be applied to your algorithm .

Java handles your garbage • So don’t forget to analyze this!!! • java -Xloggc:<file> class • The cost of gc also implies the cost of the allocation • The number of lines written to filegc will be evidence of the garbage collector activity • Look in your code for unneccessary allocations • Re-order processing to keep heap size to a minimum .

Try a few different things • • • • • Is your sort algorithm really the best one? Is your data structure really the best one? Save your working program to a backup!!! Compare run-times with different sorts Do the least # operations to get your output .

Summary • • • • v1 original code v2 inner loop re-write / algorithm design v3 minimize allocations v4 improved version (…repeat (1-4) if necessary) • v5 final version .

int[] partSums = new int[p * (p-1) + 1]. i<p. k++){ if(walk == p){ walk = 0. //k = loop for summation for(int k=0. sum. k<i..+p int walk. j<p.// version 1 private boolean sumElements(int[] permutation){ //generate sumation of terms 1+2+3+.. } partSums[index++] = sum. } sum += permutation[walk++]. // i = length of the elements of sum for(int i=1. } }// (con’t next slide…) . int index = 0. walk = j. i++){ //j = starting index for(int j=0. j++){ sum = 0.

} .java in j2sdk demo directory QSort.// version 1 (con’t) //add last element sum of all elements partSums[index] = n. //step through array to verify success int consecutive = 1. for(int i=1.length-1). } else if(partSums[i] > consecutive + 1){ return false. 0.length. i<partSums. i++){ if(partSums[i] == consecutive + 1){ consecutive++. //qsort rewritten from QSortAlgorithm. partSums. } } return true.qsort(partSums.

boolean[] partIndexes){ //generate sumation of terms 1+2+3+. i<partIndexes. i++){ if(partIndexes[i] == false){ return false. always true for(int i=3. partIndexes[(value = permutation[i])] = true.. j<pMinusOne. i++){ walk = i + 1. for(int j=1. Arrays. for(int i=0. j++. walk++){ partIndexes[(value += permutation[walk])] = true.+p int value.1. false). } .fill(partIndexes.. not used //skip over index 1 & 2. walk. i<p. } } return true.// version 5 private boolean sumElements(int[] permutation. int pMinusOne = p .length. } } //skip over index 0.

v5.v1.ICBaseCycle 8 57 Here is a set of valid arrays 1 8 11 3 18 10 2 4 1 12 2 6 3 7 22 4 1 5 15 7 16 2 8 3 1 8 2 3 21 4 12 6 1 6 17 12 2 11 5 3 1 2 10 19 4 7 9 5 # of solutions: 6 Total compute-time: 10.328 seconds C:\cs146_profiling>java hw3.078 seconds .C:\cs146_profiling>java hw3.ICBaseCycle 8 57 Here is a set of valid arrays 1 8 11 3 18 10 2 4 1 12 2 6 3 7 22 4 1 5 15 7 16 2 8 3 1 8 2 3 21 4 12 6 1 6 17 12 2 11 5 3 1 2 10 19 4 7 9 5 # of solutions: 6 Total compute-time: 110.

it will be a lot harder to start learning how to optimize then!!! .Conclusion • Easy to start learning how to test the performance on our homework problems • Later you will be running large scale applications with multi-tier enterprise applications with networking and database. etc.

References • Effective Java .Joshua Bloch • Java Platform Performance – Steve Wilson • Core Java v.2 – Cay Horstmann .

- A Unique Sorting Algorithm With Linear Time & Space ComplexityUploaded byesatjournals
- Household Living Arrangement in SingaporeUploaded bynarayaru
- Neeraj McaUploaded byTulasinagababu Lokam
- JAVAUploaded byChaika Reviera
- Revision Proof by InductionUploaded bySaifulahmed49
- First TermUploaded byTrynos
- 00010036Uploaded byRaheleh Amirlatifi
- ampolUploaded byAngelie July Anne Figuracion
- OverviewAndMath01 (1)Uploaded byMandeep Singh
- CalcII Seq SeriesUploaded byPrachee Telang
- Seq and Series Review Hw 10Uploaded bycaleb castillo
- Function Property BrowserUploaded byaddyyoung
- Oops Lab NotesUploaded byVikneshwar Vicky
- Calculus II - Sequences and SeriesUploaded byZeljko theFluxmeister Stevanovic
- Car Quarter ModelingUploaded byАбдельнасир Абдельрахман
- IRJET-A comparative Study of Sorting Algorithms Comb, Cocktail and Counting SortingUploaded byIRJET Journal
- COMP211slides_14Uploaded byalexisthe
- Ch5.pdfUploaded bymanusansano
- OO Case Studies with Patterns and C++Uploaded byImre Tuske
- Projec29000Uploaded byjayarajmevlsi
- 1603067 - BI 4.0 - Java.lang.NullPointerException After Login to CMC or BI LaunchpadUploaded byanibal goicochea
- Thomas Niemann - Sorting & SearchingUploaded byЕкатерина Шадрина
- Technical)Uploaded byhemalingam
- Computer Graphics - Hidden Surface Removal Using Polygon Area SortingUploaded bySyedkareem_hkg
- 3com-linkb-opt-fddiUploaded byxsimio
- Set 2 External SortingUploaded bySathyaPriya Ramasamy
- 05 Sorting MethodsUploaded byamitfegade121
- THIRDPARTY-LICENSE-JAVA.TXTUploaded byMilton Alves
- 1106124Uploaded byjivikukreja
- EO Gaddis Java Chapter 07 5eUploaded byelroy404

- Gate 2015 7feb AnUploaded byPritish Pradhan
- Dual FittingUploaded byPritish Pradhan
- Linear Algebra in 4 PagesUploaded bynislam57
- rbnsUploaded byPritish Pradhan
- 180A.LectureNotesUploaded byPritish Pradhan
- More LP BasedUploaded byPritish Pradhan
- Primal DualUploaded byPritish Pradhan
- CSP_2014_AnsUploaded byPratibha Ch
- 9.MicroProcessor & Computer OrganisationUploaded byPritish Pradhan
- Approx IntroUploaded byPritish Pradhan
- 11 ChapUploaded bySandeep Kumar
- 10 Measures to Reduce CorruptionUploaded byprits112
- Vazirani PresentationUploaded byPritish Pradhan
- Vazirani PresentationUploaded byPritish Pradhan
- Putnam Analysis Practice Problems 2013Uploaded byPritish Pradhan
- Profile and OptimizeUploaded byPritish Pradhan
- 10 Things to Know About Anna HazareUploaded byshubhakar
- 10 Things to Know About Anna HazareUploaded byshubhakar
- 20_yrsUploaded byPritish Pradhan

- c ProgrammingUploaded byShabbin Shabz
- College Website CreationUploaded byTarachand Maurya
- ApplicationUploaded bymariammari
- c ProgrammingUploaded byAkshay Phadke
- Event Handling in c PDFUploaded byScott
- VHDL PPTUploaded bysansure
- OpenFOAM Steady StateUploaded byAli Hussain Kadar
- Migration Guide - PV+ 6 Terminals to PV+ 7 Terminals Catalog Number Conversions - 2711P-AP004B-EN-P - January 2017Uploaded byNicolás A. Selvaggio
- suid-sgidUploaded bySaurabh Lamgora
- JF_V02_S02_L04Uploaded byFitria Noer Chahya Ningsih
- lecture1.pptUploaded byhk3987gmailcom
- Understanding BEx Query Designer- Part-5 Query Element PropertiesUploaded byZaynab Fadlallah
- Cara menggunakan data loadUploaded byYasienSayidiman
- cs2252finalnotesUploaded byearth2hellothere
- VANET AbstractUploaded bySujesh P Lal
- sqlUploaded byAnna Mariia
- DSA 1.pdfUploaded byNishu Rave
- 17.0 Mechanical EnterpriseUploaded bysainath_84
- sfhas_virtualization_62_sol.pdfUploaded byDavid
- Problem AUploaded byPallavi Chand
- Pix Asa Dhcp Svr ClientUploaded byHugo Adorno
- Software Custom is at Ion GuideUploaded byjardelmv
- ZEDi USB Windows Driver Help GuideUploaded byDani Caraiani
- High Performance ComputingUploaded byGodfrey J Lawrence
- EasyLanguage TechniquesUploaded byAggelos Kotsokolos
- B10258_01Uploaded bytolobao
- Qb 2Uploaded byJPR EEE
- Pix Asa VPN FilterUploaded byotakking
- Dynamic Systems Development MethodUploaded byJasper Labenia
- 66381708 System Software Cs2304 NotesUploaded byAnirudhan Guru