Linked by Thom Holwerda on Fri 13th Feb 2009 16:19 UTC, submitted by ShlomiFish
General Development There's a new essay called "Optimizing Code for Speed" available on Shlomi Fish's site. It covers the motivation, methods and terminology of optimizing code, and provides many links and examples to illustrate this important subject.
Permalink for comment 348743
To read all comments associated with this story, please click here.
All true... but
by voidlogic on Fri 13th Feb 2009 19:30 UTC
voidlogic
Member since:
2005-09-03

All of the techniques in the article are valid for the objective of decreasing execution time, and in fact I would expect anyone with a BS in Computer Science to understand and be familiar with the techniques. I believe there should be a greater emphasis on the order of optimization. Time and time again I have seen novices worrying about porting their C# or Java application to C/C++ only to find they have not done other optimization. When a novice was skeptical that anything could beat the "almighty" C, I told him to proceed with his port. His original Java program to about a minute, his new C program took about 35 seconds. He felt this has been a success until he was given my Java implementation which ran in 0.6 seconds.

My point is basics first. I tend to follow this order:
1. Have a well structured design.
2. Optimize IO (File or database)
3. Minimize in memory usage and copying
4. Replace your algorithms with ones with better runtime characteristics.
5. Replace the 10% most executed portion of your program with assembly (ie. java native method, C/C++ inline)

Note: the application should be profiled between every step.

Just my 2 cents.

P.S. The article didn't mention that in some cases reusable modular functions are faster, despite the call overhead, if the result is that most functions used remain in cache during execution.

Reply Score: 5