- You'll save an extra 5% on Books purchased from Amazon.ca, now through July 29th. No code necessary, discount applied at checkout. Here's how (restrictions apply)
Efficient C++: Performance Programming Techniques Paperback – Nov 3 1999
Special Offers and Product Promotions
Customers Who Bought This Item Also Bought
No Kindle device required. Download one of the Free Kindle apps to start reading Kindle books on your smartphone, tablet, and computer.
Getting the download link through email is temporarily not available. Please check back later.
To get the free app, enter your mobile phone number.
From the Inside Flap
If you conducted an informal survey of software developers on the issue of C++ performance, you would undoubtedly find that the vast majority of them view performance issues as the Achilles' heel of an otherwise fine language. We have heard it repeatedly ever since C++ burst on the corporate scene: C++ is a poor choice for implementing performance-critical applications. In the mind of developers, this particular application domain was ruled by plain C and, occasionally, even assembly language.
As part of that software community we had the opportunity to watch that myth develop and gather steam. Years ago, we participated in the wave that embraced C++ with enthusiasm. All around us, many development projects plunged in headfirst. Some time later, software solutions implemented in C++ began rolling out. Their performance was typically less than optimal, to put it gently. Enthusiasm over C++ in performance-critical domains has cooled. We were in the business of supplying networking software whose execution speed was not up for negotiation--speed was top priority. Since networking software is pretty low on the software food-chain, its performance is crucial. Large numbers of applications were going to sit on top of it and depend on it. Poor performance in the low levels ripples all the way up to higher level applications.
Our experience was not unique. All around, early adopters of C++ had difficulties with the resulting performance of their C++ code. Instead of attributing the difficulties to the steep learning curve of the new object-oriented software development paradigm, we blamed it on C++, the dominant language for the expression of the paradigm. Even though C++ compilers were still essentially in their infancy, the language was branded as inherently slow. This belief spread quickly and is now widely accepted as fact. Software organizations that passed on C++ frequently pointed to performance as their key concern. That concern was rooted in the perception that C++ cannot match the performance delivered by its C counterpart. Consequently, C++ has had little success penetrating software domains that view performance as top priority: operating system kernels, device drivers, networking systems (routers, gateways, protocol stacks), and more.
We have spent years dissecting large systems of C and C++ code trying to squeeze every ounce of performance out of them. It is through our experience of slugging it out in the trenches that we have come to appreciate the potential of C++ to produce highly efficient programs. We've seen it done in practice. This book is our attempt to share that experience and document the many lessons we have learned in our own pursuit of C++ efficiency. Writing efficient C++ is not trivial, nor is it rocket science. It takes the understanding of some performance principles, as well as information on C++ performance traps and pitfalls.
The 80-20 rule is an important principle in the world of software construction. We adopt it in the writing of this book as well: 20% of all performance bugs will show up 80% of the time. We therefore chose to concentrate our efforts where it counts the most. We are interested in those performance issues that arise frequently in industrial code and have significant impact. This book is not an exhaustive discussion of the set of all possible performance bugs and their solutions; hence, we will not cover what we consider esoteric and rare performance pitfalls.
Our point of view is undoubtedly biased by our practical experience as programmers of server-side, performance-critical communications software. This bias impacts the book in several ways:
The profile of performance issues that we encounter in practice may be slightly different in nature than those found in scientific computing, database applications, and other domains. That's not a problem. Generic performance principles transcend distinct domains, and apply equally well in domains other than networking software. At times, we invented contrived examples to drive a point home, although we tried to minimize this. We have made enough coding mistakes in the past to have a sizable collection of samples taken from real production-level code that we have worked on. Our expertise was earned the hard way--by learning from our own mistakes as well as those of our colleagues. As much as possible, we illustrated our points with real code samples. We do not delve into the asymptotic complexity of algorithms, data structures, and the latest and greatest techniques for accessing, sorting, searching, and compressing data. These are important topics, but they have been extensively covered elsewhere Knu73, BR95, KP74. Instead, we focus on simple, practical, everyday coding and design principles that yield large performance improvements. We point out common design and coding practices that lead to poor performance, whether it be through the unwitting use of language features that carry high hidden costs or through violating any number of subtle (and not so subtle) performance principles.
So how do we separate myth from reality? Is C++ performance truly inferior to that of C? It is our contention that the common perception of inferior C++ performance is invalid. We concede that in general, when comparing a C program to a C++ version of what appears to be the same thing, the C program is generally faster. However, we also claim that the apparent similarity of the two programs typically is based on their data handling functionality, not their correctness, robustness, or ease of maintenance. Our contention is that when C programs are brought up to the level of C++ programs in these regards, the speed differences disappear, or the C++ versions are faster.
Thus C++ is inherently neither slower nor faster. It could be either, depending on how it is used and what is required from it. It's the way it is used that matters: If used properly, C++ can yield software systems exhibiting not just acceptable performance, but yield superior software performance.
We would like to thank the many people who contributed to this work. The toughest part was getting started and it was our editor, Marina Lang, who was instrumental in getting this project off the ground. Julia Sime made a significant contribution to the early draft and Yomtov Meged contributed many valuable suggestions as well. He also was the one who pointed out to us the subtle difference between our opinions and the absolute truth. Although those two notions may coincide at times, they are still distinct.
Many thanks to the reviewers hired by Addison-Wesley; their feedback was extremely valuable.
Thanks also to our friends and colleagues who reviewed portions of the manuscript. They are, in no particular order, Cyndy Ross, Art Francis, Scott Snyder, Tricia York, Michael Fraenkel, Carol Jones, Heather Kreger, Kathryn Britton, Ruth Willenborg, David Wisler, Bala Rajaraman, Don "Spike" Washburn, and Nils Brubaker.
Last but not least, we would like to thank our wives, Cynthia Powers Bulka and Ruth Washington Mayhew.
From the Back Cover
Far too many programmers and software designers consider efficient C++ to be an oxymoron. They regard C++ as inherently slow and inappropriate for performance-critical applications. Consequently, C++ has had little success penetrating domains such as networking, operating system kernels, device drivers, and others.
Efficient C++ explodes that myth. Written by two authors with first-hand experience wringing the last ounce of performance from commercial C++ applications, this book demonstrates the potential of C++ to produce highly efficient programs. The book reveals practical, everyday object-oriented design principles and C++ coding techniques that can yield large performance improvements. It points out common pitfalls in both design and code that generate hidden operating costs.
This book focuses on combining C++'s power and flexibility with high performance and scalability, resulting in the best of both worlds. Specific topics include temporary objects, memory management, templates, inheritance, virtual functions, inlining, reference-counting, STL, and much more.
With this book, you will have a valuable compendium of the best performance techniques at your fingertips.
0201379503B04062001 See all Product Description
Top Customer Reviews
It discussed Reference counting in depth. I'm a garbage collection professional and have all the details. Reference counting is a very poor method, it triggers paging by touching the dead, traversals do work.
It discussed caching and again I have professional knowledge. Things are very different from machine to machine. Cache synonyms are crucial. So on one machine you will want to have objects a power of two size to keep them in cache lines and on another avoid power of two sizes to avoid cache synonyms. In the end if you care you have to measure.
The chapter about inlines is mixed bag of very good information and useless information. What I did appreciate less is that several pages are dedicated for describing what could be possible to do with inlines if very smart compilers were available. It was interesting to read but nothing applicable immediatly. Maybe this section is a wish list intended to be read by compiler implementers. However at the same time, it is the chapter that gave me the most new tricks that I did not already knew. This is the book that presents how to efficiently use inlines in the best way that I have seen in books.
Finally, if I abstract the fact that I did not learn a lot of new things, I must say that it is very well written. It is interesting to read. The authors give reference to actual cases from their work experience and this book would probably be very beneficial to read for someone that has never yet spent a lot of time doing code optimization.
Unfortunately, there are a number of topics which are not discussed or are only briefly discussed. The chapter on the STL, while accurate, is very incomplete. I would recommend bolstering this information with Meyers' "Effective STL". Also, different compilers implement different optimizations. It would have been nice to see a discussion of the optimizations provided by the most popular compilers, as well as tips on how to use these features effectively. The C++ standard allows compiler implementers to ignore certain keywords (register and inline) and to provide optimizations such as the return value optimization. I would have liked to have seen a discussion of the optimizations actually provided by various compilers as well as how they relate to the C++ standard. In addition, there are some advanced techniques, such as the Barton-Nackman trick, for avoiding the cost of virtual functions. Unfortunately, this and other comparable methods are not discussed.
On the whole, this book provides a lot of valuable information, but it could have been much more complete.
This book is a well-written overview of the C++ performance programming techniques. It looks into a broad spectrum of the issues, some of them are examined in a great detail, like C++ inlining. Most often there is no free lunch in software development, and the book does a good job of showing the trade-offs of performance techniques, keeps a good balance of not advocating extra efforts simply for the sake of having faster programs.
The book has many coding examples that show "side-by-side" performance of different code snippets trying to achieve the same computational goal. The examples are very simple and are independent off each other, so one does not have to read all the previous chapters to understand a point made in the middle of the book.
Elegance usually goes hand-in-hand with good performance, so if you are just a beginner in C++, this book will help you to polish the patterns of your programming style. I think that this book will be helpful to any C++ programmer, especially to one who is writing real-time or performance intensive applications. I wish the management could read and understand it too: hopefully then it wouldn't assume that "performance profiling" is just an afterthought and is not a necessary entry in the schedule for every serious product.
Most recent customer reviews
First off: it's practical! It's based not on some tenured professor's abstract hifalutin vaporous gobbledegook but on personal, actual, concrete experiences of the author. Read morePublished on June 2 2002 by John Doe
The authors are developers of network and web server software for IBM. They specifically target performance issues related to C++ programming. Read morePublished on Jan. 4 2001 by Daniel Mall
I thought the book a useful compendium of performance information, as far as it went: temporaries, constructors and destructors, virtual functions, inlining, reference counting,... Read morePublished on June 16 2000 by George V. Reilly
This book came well reviewed from either CUJ or DDJ (can't remember). Anyways, page 21, there's a "cout << "blah blah blah" << blah < endl" Is... Read morePublished on June 14 2000 by Corey L Cole
I found this book to be quite helpful as a guide to areas in which C++ performance may be an issue. I was surprised by the vast difference in speeds caused by choice of allocation... Read morePublished on June 2 2000 by Brent Fulgham
I was really pleased to find this book at Borders. When I saw the title I thought that this was the book we were really missing among other excellent books on C++. Read morePublished on March 29 2000 by Anton Hristozov
There are two different categories of efficiency considerations: those that you do because they are necessary and those done only when necessary. Read morePublished on March 15 2000 by Charles Ashbacher
To start, I have to say that this book is well written. By using examples from personal experience, they also keep you very involved. Read morePublished on Feb. 25 2000 by Bob Gibson
Look for similar items by category
- Books > Computers & Technology > Microsoft > Development > C & C++ Windows Programming
- Books > Computers & Technology > Programming > C
- Books > Computers & Technology > Programming > Languages & Tools
- Books > Computers & Technology > Software
- Books > Textbooks > Computer Science & Information Systems > Programming Languages