Share E-Book
Scan to open this page

Scan with your phone to open this page

Author: Kurt Guntheroth

Rating No ratings yet

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. Author Kurt Guntheroth provides several running examples that demonstrate how to apply these principles incrementally to improve existing code so it meets customer requirements for responsiveness and throughput. The advice in this book will prove itself the first time you hear a colleague exclaim, “Wow, that was fast. Who fixed something?” Locate performance hot spots using the profiler and software timers Learn to perform repeatable experiments to measure performance of code changes Optimize use of dynamically allocated variables Improve performance of hot loops and functions Speed up string handling functions Recognize efficient algorithms and optimization patterns Learn the strengths—and weaknesses—of C++ container classes View searching and sorting through an optimizer’s eye Make efficient use of C++ streaming I/O functions Use C++ thread-based concurrency features effectively

AI Reading Assistant

Whole-book reading guide from stratified index samples; jump to passages in the text

AI guide
【One-Line Pitch】 A practical, measurement-first guide to making already-correct C++ programs faster and leaner, aimed at working developers who need real responsiveness and throughput rather than micro-benchmark trivia. 【Book Arc】 - **Opening (~0%–10%)**: Frames optimization as an engineering discipline—why performance matters across devices, and why the book targets correct, well-designed C++ rather than assembly-level tricks. - **Early (~10%–30%)**: Builds the mental model of the machine: compiler behavior and flags, cache locality, endianness, and finite/virtual memory—so you understand why some C++ constructs are quietly expensive. - **Middle (~30%–55%)**: Turns to measurement: profilers, stopwatch classes, timing long-running code, estimating statement/loop cost, and the discipline of repeatable experiments and skepticism about results. - **Late (~55%–85%)**: Applies the method to concrete hot areas—strings as a case study, hot loops and functions, algorithms and optimization patterns, container strengths/weaknesses, searching and sorting, and streaming I/O. - **Ending (~85%–100%)**: Extends into concurrency and memory management: thread-based facilities, synchronization, atomicity, and the life cycle of dynamically allocated variables. 【Key Takeaways】 - **Optimization starts with measurement, not intuition** (Middle): profilers and timers reveal hot spots; the book stresses repeatable experiments and healthy skepticism when results look too good. - **Correct, well-designed C++ can still be slow** (Early): casual use of language features and copying costs resources; the goal is faster code that remains good design. - **Understand the machine before tuning** (Early): cache locality, endianness, and finite/virtual memory explain why linked structures and cross-platform data handling behave differently. - **Strings are a recurring performance trap** (Middle): dynamic allocation, value semantics, and copying make string handling a rich case study in eliminating temporaries and reallocations. - **Containers and algorithms have trade-offs, not universal winners** (Late): the book examines container strengths/weaknesses and views searching/sorting through an optimizer's eye. - **Concurrency is a first-class optimization topic** (Ending): threads, promises/futures, mutexes, locks, condition variables, atomicity, and races are covered as practical tools—and hazards. - **Memory management deserves explicit attention** (Ending): the dynamic-variable life cycle and high-performance memory managers are treated as levers for speed and resource use. - **Compiler configuration is low-hanging fruit** (Early): using a better compiler and using your compiler better—flags, pragmas, inlining—can matter before any code rewrite. 【Reading Tips】 - Deep-read the measurement chapters first; they underpin every later technique and prevent wasted effort on cold code. - Skim the machine-behavior material if you already know cache/endianness well, but return to it when a specific optimization seems counterintuitive. - Treat the string case study as a template: follow how the author iterates from naive to optimized rather than memorizing individual fixes. - For concurrency and memory chapters, read with your own codebase in mind—these are where correctness risks rise alongside performance gains. - Keep the running examples handy; the book's value is in applying principles incrementally, not in isolated tips. 【Coverage Limits】 The excerpts cover the book's structure, measurement methodology, machine-behavior fundamentals, and chapter-level topics for strings, concurrency, and memory management, but do not include full code details or every chapter's contents. Specific benchmark figures and later-chapter examples are only partially represented.
Page 8
24 Statements Are Not Executed in Order 25 Summary 26 3. Measure Performance. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ....
View in text
Excerpt 2
can afford. Your hardware team may have saddled you with a tiny processor to meet their power consumption goals. You may be battling a compet‐ itor over thro...
View in text
Excerpt 3
s of any serious attempt to improve a program’s performance. This chapter introduces two software tools that measure per‐ formance: the profiler and the soft...
View in text
Excerpt 4
= 0; i < nCalls; ++i) QueryPerformanceCounter(&count); ULONG stop = GetTickCount(); std::cout << stop - start << "ms for 100m QueryPerformanceCounter() calls...
View in text
Excerpt 5
too far. —Lt. General Frederick “Boy” Browning (1896–1965) Comment to Field Marshal Montgomery on September 10, 1944, expressing his con‐ cerns about the All...
View in text
Excerpt 6
operation is reduced by using a hint that, if provided, may lead to reduced computation. For instance, one overload of the insert() member function of std::m...
View in text
Excerpt 7
ers heard our pain, and invented a template function called std::make_shared() that allocates a single block of storage to hold both the refer‐ ence count an...
View in text
Excerpt 8
ents are stored together in a contig‐ uous piece of storage. Flat data structures have significant performance advantages over data structures whose parts ar...
View in text
Tags
AI categories
C++ProgrammingSoftware
c/c++
ISBN: 1491922060
Publisher: O’Reilly Media
Publish Year: 2016
Language: English
Pages: 388
File Format: PDF
File Size: 5.6 MB
Text Preview (First 20 pages)
Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

Generating text preview…