290 likes | 402 Views
Computer Science 313 – Advanced Programming Topics. Lecture 5: 90-10 Rule. 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. Tom Cargill. Let’s Get Coding.
E N D
Computer Science 313 – Advanced Programming Topics Lecture 5:90-10 Rule
The first 90% of the code accounts for thefirst 90% of the development time. The remaining 10% of the code accounts for the other 90% of the development time. Tom Cargill
Let’s Get Coding • Who will write next lab in assembly? • Can only use assembly code for entire lab pushl %ebpmovl %esp, %ebpsubl $24, %espmovl 8(%ebp), %eaxmovl %eax, -4(%ebp) cmpl $0, -4(%ebp)
Let’s Get Coding • Who will write next lab in assembly? • Can only use assembly code for entire lab • During the first pass, apply standard optimizations pushl %ebpmovl %esp, %ebpsubl $24, %espmovl 8(%ebp), %eaxmovl %eax, -4(%ebp) cmpl $0, -4(%ebp)
Let’s Get Coding • Who will write next lab in assembly? • Can only use assembly code for entire lab • During the first pass, apply standard optimizations • Every method should be tuned to maximize branches pushl %ebpmovl %esp, %ebpsubl $24, %espmovl 8(%ebp), %eaxmovl %eax, -4(%ebp) cmpl $0, -4(%ebp)
Let’s Get Coding • Who will write next lab in assembly? • Can only use assembly code for entire lab • During the first pass, apply standard optimizations • Every method should be tuned to maximize branches • Necessary to achieve top performance pushl %ebpmovl %esp, %ebpsubl $24, %espmovl 8(%ebp), %eaxmovl %eax, -4(%ebp) cmpl $0, -4(%ebp)
Promise of Perfect Debugging • Programs just λ-calculus equations • Use Java, but instead prove program correct • Translate program into λ-calculus • Specify theorem & prove program correctness
Fewest Lectures Ever • What if guaranteed A for student doing this? • Would still need to submit assignment on time • Working assembly needed (with optimizations) • Code should work, but proof must be perfect • Any takers?
Fewest Lectures Ever • What if guaranteed A for student doing this? • Would still need to submit assignment on time • Working assembly needed (with optimizations) • Code should work, but proof must be perfect • Any takers? Why not?
Why Isn’t This Done? • Almost never use these techniques • Low-level device drivers use some C (or similar) • Rare for partial proof of correctness to be used • Simple result from easy cost-benefit analysis • Techniques requires massive amounts of time • Time is money; these are very, very expensive • The provided benefits just not worth it
What’s The Secret? How do I know when to optimize? I need to know. Please, please, please?
Problem is Universal • Frequent need to make optimal decision • Using reagents during chemical synthesis • Take power plant offline & perform maintenance • Fastest torrent from which to download • Cannot optimize everything • Instead we only focus efforts where it matters
Problem is Universal But how can I know what is important? • Frequent need to make optimal decision • Using reagents during chemical synthesis • Take power plant offline & perform maintenance • Fastest torrent from which to download • Cannot optimize everything • Instead we only focus efforts where it matters
Are Graphics Important? • Rewrite Swing to improve its performance?
Are Graphics Important? • Rewrite Swing to improve its performance? Hells, yes.We need 60 fps for new games.
Are Graphics Important? • Rewrite Swing to improve its performance? Hells, yes.We need 60 fps for new games. %#$ no. What does it do for search speed?
Critical Paths • All that is important is code along critical path • Determines time needed and not just the fluff • Graphics are not critical for Google • Major graphics improvements are nice… • …but have zero affect on search times • Bungie’s critical path is graphics package • Games performance limited by graphic times • Would hate GPU for search – slows them down
Guess the Critical Path $ java -Xprofedu.canisius.ann.Network Flat profile of 16.4 secs (956 total ticks): main Compiled + native Method 35.6% 282 + 58 Neuron.getWeightedError21.1% 187 + 15 Neuron.updateWeights13.0% 124 + 0 Network.trainNetwork 9.5% 0 + 91 java.lang.StrictMath.exp 9.5% 91 + 0 Neuron.compute 4.5% 22 + 21 Network.setNetworkInput 3.6% 34 + 0 Network.runOneInput 2.0% 0 + 19 java.util.ArrayList.<init> 0.8% 8 + 0 Network.main99.6% 748 + 204 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 • Use this to answer question that matters • Speedup calculated by this equation • Speedup of 2 means program twice as fast • Need 1/10 the time, 10 is speedup factor of approach • When speedup is 1, time taken unchanged • Speedup of ½ == twice as long as past approach
Amdahl’s Law • Determines how much faster program can go • Use this to answer question that matters • Speedup calculated by this equation • Speedup of 2 means program twice as fast • Need 1/10 the time, 10 is speedup factor of approach • When speedup is 1, time taken unchanged • Speedup of ½ == twice as long as past approach(But usually say slowdown factor of 2)
Amdahl’s Law • Determines how much faster program can go • Use this to answer question that matters • Speedup calculated by this equation • Speedup of 2 means program twice as fast • Need 1/10 the time, 10 is speedup factor of approach • When speedup is 1, time taken unchanged • Speedup of ½ == twice as long as past approach(But usually say slowdown factor of 2)(Or hide report that shows this sucks)
Amdahl’s Law Equation • %changed of time in methods to be optimized • Expressed as decimal between 0 - 1 • All other time from run is %unchanged • Another decimal from 0 – 1 • If %changed + %unchanged ≠ 1,you FAIL
Applying Amdahl’s Law • Made getWeightedErrortwice as fast • Speedupchanged = 2, since now twice as fast • Took 16.4 seconds before, what will it take now? • Get execution times using java –Xprof 35.6% 282 + 58 Neuron.getWeightedError%changed = 0.356%unchanged = 1 - 0.356 = 0.644
Amdahl’s Law Speedup = 1.21
Applying Amdahl’s Law • Move Neuron.computeoff critical path? • Removes it from program execution time • Speedupchanged = ∞ • Get execution times from java –Xprof 9.5%91 + 0 Neuron.compute%changed = 0.095%unchanged = 1 - 0.095 = 0.905
Amdahl’s Law Speedup = 1.10
For Next Class • Lab #2 on web/Angel in 1 hour • I will be in lab from 12 - 1 – feel free to stop by • Read pages 37 – 55 in book • Get back into code & design patterns • How could we handle 1-to-many communication? • Why not have cycles in UML class diagram? • What is secret to Lindsay Lohan'ssuccess?