Book description
In today’s fast and competitive world, a program’s performance is just as important to customers as the features it provides. This practical guide teaches developers performance-tuning principles that enable optimization in C++. You’ll learn how to make code that already embodies best practices of C++ design run faster and consume fewer resources on any computer—whether it’s a watch, phone, workstation, supercomputer, or globe-spanning network of servers.
Publisher resources
Table of contents
- Preface
- 1. An Overview of Optimization
-
2. Computer Behavior Affecting Optimization
- Lies C++ Believes About Computers
-
The Truth About Computers
- Memory Is Slow
- Memory Is Not Accessed in Bytes
- Some Memory Accesses Are Slower than Others
- Memory Words Have a Big End and a Little End
- Memory Has Finite Capacity
- Instruction Execution Is Slow
- Making Decisions Is Hard for Computers
- There Are Multiple Streams of Program Execution
- Calling into the Operating System Is Expensive
- C++ Tells Lies Too
- Summary
- 3. Measure Performance
-
4. Optimize String Use: A Case Study
- Why Strings Are a Problem
-
First Attempt at Optimizing Strings
- Use Mutating String Operations to Eliminate Temporaries
- Reduce Reallocation by Reserving Storage
- Eliminate Copying of String Arguments
- Eliminate Pointer Dereference Using Iterators
- Eliminate Copying of Returned String Values
- Use Character Arrays Instead of Strings
- Summary of First Optimization Attempt
- Second Attempt at Optimizing Strings
- Eliminate String Conversion
- Summary
- 5. Optimize Algorithms
- 6. Optimize Dynamically Allocated Variables
-
7. Optimize Hot Statements
-
Remove Code from Loops
- Cache the Loop End Value
- Use More Efficient Loop Statements
- Count Down Instead of Up
- Remove Invariant Code from Loops
- Remove Unneeded Function Calls from Loops
- Remove Hidden Function Calls from Loops
- Remove Expensive, Slow-Changing Calls from Loops
- Push Loops Down into Functions to Reduce Call Overhead
- Do Some Actions Less Frequently
- What About Everything Else?
-
Remove Code from Functions
- Cost of Function Calls
- Declare Brief Functions Inline
- Define Functions Before First Use
- Eliminate Unused Polymorphism
- Discard Unused Interfaces
- Select Implementation at Compile Time with Templates
- Eliminate Uses of the PIMPL Idiom
- Eliminate Calls into DLLs
- Use Static Member Functions Instead of Member Functions
- Move Virtual Destructor to Base Class
- Optimize Expressions
- Optimize Control Flow Idioms
- Summary
-
Remove Code from Loops
-
8. Use Better Libraries
- Optimize Standard Library Use
- Optimize Existing Libraries
-
Design Optimized Libraries
- Code in Haste, Repent at Leisure
- Parsimony Is a Virtue in Library Design
- Make Memory Allocation Decisions Outside the Library
- When in Doubt, Code Libraries for Speed
- Functions Are Easier to Optimize than Frameworks
- Flatten Inheritance Hierarchies
- Flatten Calling Chains
- Flatten Layered Designs
- Avoid Dynamic Lookup
- Beware of ‘God Functions’
- Summary
- 9. Optimize Searching and Sorting
- 10. Optimize Data Structures
- 11. Optimize I/O
- 12. Optimize Concurrency
- 13. Optimize Memory Management
- Index
Product information
- Title: Optimized C++
- Author(s):
- Release date: May 2016
- Publisher(s): O'Reilly Media, Inc.
- ISBN: 9781491922064
You might also like
book
40 Algorithms Every Programmer Should Know
Learn algorithms for solving classic computer science problems with this concise guide covering everything from fundamental …
book
Head First Design Patterns, 2nd Edition
You know you don’t want to reinvent the wheel, so you look to design patterns—the lessons …
book
Mastering the C++17 STL
This book breaks down the C++ STL, teaching you how to extract its gems and apply …
book
Modern C++ Programming Cookbook - Second Edition
A pragmatic recipe book for acquiring a comprehensive understanding of the complexities and core fundamentals of …