Tom Cargill The first 90% of the code accounts for the first 90% of the development time. The remaining 10% of the code accounts for the other 90% of the development time.
Computer Science 313 – Advanced Programming Topics
Tom Cargill The first 90% of the code accounts for the first 90% of the development time. The remaining 10% of the code accounts for the other 90% of the development time.
Let’s Get Coding Who will write next lab in assembly? Write entire program in assembly Apply standard optimizations for first pass Finally, hand tune every method & every class Necessary to achieve top performance pushl %ebp movl %esp, %ebp subl $24, %esp movl 8(%ebp), %eax movl %eax, -4(%ebp) cmpl $0, -4(%ebp)
Programs just λ-calculus equations Can use this to prove program correct Translate program into λ-calculus Specify and prove program correctness theorem What if I guarantee student an A? Promise of Perfect Debugging
Why Isn’t This Done? Almost never use these techniques Even device drivers not entirely in assembly Rare to develop even partial proof of correctness Perform a cost-benefit analysis Techniques requires massive amounts of time Time is money; these are very, very expensive Simply not worth the benefits provided
What’s The Secret? How do I know when to optimize? I need to know. Please, please, please?
Problem is Universal Making optimal decisions occurs frequently Using reagents during chemical synthesis When to perform maintenance on power plant Which ski lift line will be fastest Cannot optimize everything Must focus on where it matters most But how can I know what is important?
Are Graphics Important? Rewrite Swing to improve its performance? Hells, yes. We need the 30 fps gamers demand. Hells, no. What does it do for search speed?
Critical Paths Only consider code along critical path Process which determines time required Graphics are not critical for Google Could dramatically improve graphics… …but would not effect how long search takes Bungie’s critical path is graphics package Graphics limits program performance No impact from improvements to file searching
Guess the Critical Path $ java -Xprof edu.canisius.ann.Network Flat profile of 16.4 secs (956 total ticks): main Compiled + native Method 35.6% Neuron.getWeightedError 21.1% Neuron.updateWeights 13.0% Network.trainNetwork 9.5% java.lang.StrictMath.exp 9.5% Neuron.compute 4.5% Network.setNetworkInput 3.6% Network.runOneInput 2.0% java.util.ArrayList. 0.8% Network.main 99.6% Total compiled
Still a Cost-Benefit Trade Great. More useless geekery. When will it make a difference? When is it worth my time?
Amdahl’s Law Determines how much faster program can go Can finally answer the question that matters Equation’s result is program speedup Speedup of 2 when program twice as fast Program runs in 1 / 10 the time, then speedup is 10 Execution time unchanged with speedup of 1 Needs twice as long when speedup is ½
Amdahl’s Law Equation
Applying Amdahl’s Law Made getWeightedError twice as fast Speedup changed = 2, since now twice as fast Took 16.4 seconds before, what will it take now? Get execution times from java –Xprof 35.6% Neuron.getWeightedError %changed = %unchanged = = 0.644
Amdahl’s Law Speedup = 1.21
Applying Amdahl’s Law Move Neuron.compute off critical path? Removes it from program execution time Speedup changed = ∞ Get execution times from java –Xprof 9.5% Neuron.compute %changed = %unchanged = = 0.905
Amdahl’s Law Speedup = 1.10
For Next Class Lab #4 on web/Angel & due before next lab Midterm #1 in class on Monday Will be open-note, open-book, & open-reports But closed-friend, closed-slide, & closed-activity Most questions resemble in-class activities Could also ask to implement design pattern Use design patterns to develop solution to sample problem
Midterm Preparation When/where to use a design pattern Determine pattern used by real-world example Understand what the design principles mean Explain how a design pattern follows a principle Convert method to be tail recursive Make tail recursive method iterative Use Stack to eliminate recursion from method Compute speedup using Amdahl’s law Use speedup to determine new execution time