4

I am planning on purchasing this book to learn more about C++ programming with regards to fast code. However, the book was published in 1999 and I am worried most of it may be irrelevant now due to optimizations that compilers perform.

Could anyone please advise?

http://www.amazon.com/Efficient-C-Performance-Programming-Techniques/dp/0201379503/ref=cm_cr_pr_product_top

edit:

Found this book too, albeit also rather old:

http://www.amazon.com/Optimizing-C-Steve-Heller/dp/0139774300

3
  • Instead of efficient c++ why not follow the Effective C++ series?
    – Job
    Commented May 14, 2012 at 16:53
  • 1
    Does Meyers' Effective series cover performance?
    – user997112
    Commented May 14, 2012 at 21:23
  • Maybe not as directly, but Meyers is very concerned about performance (as you'll know if you've seen his talks about cache effects) and his tips almost always lead to clearer, more maintainable and faster code. Commented May 20, 2012 at 5:13

5 Answers 5

5

The book touches on subjects like temporaries, constructors/destructors, the overhead of virtual functions, benefits and pitfalls of inlining, memory pooling, caching, CPU cache effects, registers etc.

Many of those techniques are still valid - even if the language and compilers will be providing a lot more help now than in 1999, and the hardware you are running it on is different.

It helps to know what has changed since then, but I'd still recommend reading the book if you don't know where to start, simply because I do not know of anything more recent that covers these kinds of topics specifically.

2
  • There doesn't appear to be anything more recent- although Meyers is supposed to be releasing a non-C++-specific book called "Fastware". Im not sure how much of his current "Effective" series books is devoted to performance....
    – Roger
    Commented May 14, 2012 at 14:35
  • 2
    You may find this helpful: en.wikibooks.org/wiki/Optimizing_C%2B%2B
    – quant_dev
    Commented May 14, 2012 at 15:34
3

I think it's not necessarily irrelevant just because it's old. For example, C++ lets you put a constructor invocation anywhere an expression can occur. That means the compiler isn't allowed to move your constructor invocations to make the runtime code more efficient, because there are rules about what is guaranteed to have happened between sequence points in a C++ program. OK, it's just one example, and the rule is simple (lazy instantiation means not running a constructor until you need to), but it means there are compiler-independent techniques to improve code efficiency.

4
  • As you touched upon, I agree that the key is to avoid the compiler and /or platform specific techniques as those are the techniques that become irrelevant with time.
    – user53019
    Commented May 14, 2012 at 13:32
  • Ironic that you should mention constructor invocations, because that's exactly where RVO and NRVO come in and the compiler can ellide them.
    – DeadMG
    Commented May 14, 2012 at 13:32
  • 1
    RVO is a very limited subset of the situations in which objects are created, though.
    – user4051
    Commented May 14, 2012 at 14:33
  • @GrahamLee: Not necessarily. I would say more relevantly that rvalue references and wide-spread expression templates absolutely do dominate the temporaries optimization scene, though.
    – DeadMG
    Commented May 14, 2012 at 17:15
3

More relevantly, there are simply new techniques and new language features- especially rvalue references, and compiler optimizations are much stronger than they used to be with features like cross-TU inlining, RVO, and NRVO. I would look for a newer book.

3
  • 3
    The book actually has a chapter on RVO, but it doesn't cover rvalue references obviously. Commented May 14, 2012 at 13:41
  • @MadKeithV: AFAIK, common compilers only began introducing RVO and NRVO post-2000.
    – DeadMG
    Commented May 14, 2012 at 14:13
  • 1
    @DeadMG would you be so kind as to recommend something more recent?
    – Roger
    Commented May 14, 2012 at 14:19
1

No, the book is not irrelevant at all. It's somewhat old school in places, but a lot of coding companies are that way too. Further, most of what it teaches will always be a part of C++.

That said, I personally think that Sutter's books are better. They don't cover the same material though, so if what's in Meyers's books is new to you...get both.

4
  • 3
    I think you misread -- Meyers wrote Effective C++, but he's asking about Efficient C++. Commented May 14, 2012 at 16:02
  • @Jerry. I did mention Meyer's books in a comment above. Maybe Crazy Eddie refers to that?
    – Roger
    Commented May 14, 2012 at 16:31
  • @Crazy Eddie, so Sutter's books cover performance then? Would you be able to suggest which Sutter books in particular? Thanks
    – Roger
    Commented May 14, 2012 at 16:31
  • @Roger: Maybe. Sutter's books undoubtedly mention efficiency in passing, but are devoted primarily to other issues (especially exception safety). Commented May 14, 2012 at 16:53
1

The compiler tries to optimize what it can, but you have to optimize what you can, and the book should help you with that (somewhat).

If you are going to write significantly large programs, it is very easy to put in slowness, without meaning to, that the compiler could never undo.

My favorite example is here. It consists of a realistically large program that was optimized. It was made faster by 50%. But that did not mean it could not be further optimized. The second attempt knocked out a healthy percent of what was left. But that still wasn't the end. This was done six times, and guess what the overall speedup ratio was?

730 times.

Toward the end, the optimizations being done were, out of the original program's time, so small as to be insignificant. But after a series of other problems were removed, small problems become larger, percentage-wise, so they become worth removing. The individual speedup ratio that you get with each optimization may not be too surprising, but they multiply together like compound interest.

That's how you can really optimize code. By all means, use the book, but don't limit yourself to what it says.

Not the answer you're looking for? Browse other questions tagged or ask your own question.