Fog Creek Software
Discussion Board

Book recs - optimising code?

Can anyone recommend any books about how to optmize (C/C++) code? It needs to cover not only optimizing for speed but also size. TIA.

Wednesday, October 08, 2003

"Efficient C++" by Bulka and Mayhew.

I have not read it all, but what I have read I have agreed with - though the do concentrate more on speed than size. See the ACCU review at .

(There are a couple of other books with "Efficient in their title reviewed at the ACCU site, see .)


Tim Sharrock
Wednesday, October 08, 2003

Thanks Tim. I'd never heard of the ACCU before. They have a whole section of reviews on optimization books, however. Ta.

Wednesday, October 08, 2003

It's not about optimizing C++ specifically, but anyone interested in the topic should look at Programming Pearls.  I think the author is Jon Bentley.

Bruce Perry
Wednesday, October 08, 2003

It is difficult to optimize for both speed AND size.  Often, the techniques that optimize for speed require more memory, and the techniques that optimize for memory result in less speed.

That said, I consider the most important thing for optimization to be a good design.  Second most important: a profiling tool and the knowledge of how to use it.

Everything I know about optimization I have learned while optimizing assembly, C/C++, and Java code.  A few rules of thumb:

- The thing you *expect* is taking the most time usually is 10th or 12th down the list.
- Never assume that any particular optimization actually is.
- The 80/20 rule applies: 80% of your improvements will come with the first 20% of effort; the last 20% of improvements will come with the remaining 80% of work.
- Always consider the external factors that affect performance.

Good luck with your optimization efforts.  I hope you find it to be a rewarding and satisfying experience.


Wednesday, October 08, 2003

I have Efficient C++ - it's pretty good.

There are is a section in More Exceptional C++ too - a good constrast, as they are mostly about how traditional optimization techniques don't necessarily help in a multi-threaded environment.

Wednesday, October 08, 2003

Kernighan & Pike's "The Practice of Programming" has a good chapter entitled "Performance".

Wednesday, October 08, 2003

Don't start bottle-neck optimizing your program without any profiler - it will be a waste of time - especially yours ;-)

We use Rationals Purify with Visual C++ and it works like a charm and have saved us SO much time in pinpointing bottlenecks, and I really don't think they ever were where we expected them to be... ;-)

That said, algorithmic optimization is another field (that is, choosing one algorithm over another because of its superiour performance) - and I think Programming Pearls as previously mentioned might be a good choice here.

Torben Koch
Friday, October 10, 2003

*  Recent Topics

*  Fog Creek Home