Alex Rivera | Logout

Optimization! - What is it? How is it done?

Asked 2009-10-19T05:04:25.743
13

Its common to hear about "highly optimized code" or some developer needing to optimize theirs and whatnot. However, as a self-taught, new programmer I've never really understood what exactly do people mean when talking about such things.

Care to explain the general idea of it? Also, recommend some reading materials and really whatever you feel like saying on the matter. Feel free to rant and preach.

Edit
Report

1 Answer

2

Optimizing a program means: make it run faster

The only way of making the program faster is making it do less:

  • find an algorithm that uses fewer operations (e.g. N log N instead of N^2)
  • avoid slow components of your machine (keep objects in cache instead of in main memory, or in main memory instead of on disk); reducing memory consumption nearly always helps!

Further rules:

  • In looking for optimization opportunities, adhere to the 80-20-rule: 20% of typical program code accounts for 80% of execution time.
  • Measure the time before and after every attempted optimization; often enough, optimizations don't.
  • Only optimize after the program runs correctly!

Also, there are ways to make a program appear to be faster:

  • separate GUI event processing from back-end tasks; priorize user-visible changes against back-end calculation to keep the front-end "snappy"
  • give the user something to read while performing long operations (every noticed the slideshows displayed by installers?)
answered 2009-10-19T06:43:19.197

Your Answer