Optimized C++:
Gespeichert in:
1. Verfasser: | |
---|---|
Format: | Buch |
Sprache: | English |
Veröffentlicht: |
Beijing ; Boston ; Farnham ; Sebastopol ; Tokyo
O'Reilly
April 2016
|
Ausgabe: | First edition |
Schlagworte: | |
Online-Zugang: | Inhaltsverzeichnis |
Beschreibung: | Auf dem Cover: "Optimized C++ proven techniques for heightened performance" |
Beschreibung: | xviii, 366 Seiten Illustrationen |
ISBN: | 9781491922064 |
Internformat
MARC
LEADER | 00000nam a2200000 c 4500 | ||
---|---|---|---|
001 | BV043638891 | ||
003 | DE-604 | ||
005 | 20160812 | ||
007 | t | ||
008 | 160623s2016 a||| |||| 00||| eng d | ||
020 | |a 9781491922064 |c pbk |9 978-1-4919-2206-4 | ||
035 | |a (OCoLC)953073305 | ||
035 | |a (DE-599)HBZHT018981754 | ||
040 | |a DE-604 |b ger |e rda | ||
041 | 0 | |a eng | |
049 | |a DE-83 |a DE-11 | ||
084 | |a ST 250 |0 (DE-625)143626: |2 rvk | ||
100 | 1 | |a Guntheroth, Kurt |e Verfasser |0 (DE-588)1101611111 |4 aut | |
245 | 1 | 0 | |a Optimized C++ |c Kurt Guntheroth |
246 | 1 | 3 | |a Optimized C++ proven techniques for heightened performance |
250 | |a First edition | ||
264 | 1 | |a Beijing ; Boston ; Farnham ; Sebastopol ; Tokyo |b O'Reilly |c April 2016 | |
300 | |a xviii, 366 Seiten |b Illustrationen | ||
336 | |b txt |2 rdacontent | ||
337 | |b n |2 rdamedia | ||
338 | |b nc |2 rdacarrier | ||
500 | |a Auf dem Cover: "Optimized C++ proven techniques for heightened performance" | ||
650 | 0 | 7 | |a C++ |0 (DE-588)4193909-8 |2 gnd |9 rswk-swf |
689 | 0 | 0 | |a C++ |0 (DE-588)4193909-8 |D s |
689 | 0 | |5 DE-604 | |
856 | 4 | 2 | |m HEBIS Datenaustausch |q application/pdf |u http://bvbr.bib-bvb.de:8991/F?func=service&doc_library=BVB01&local_base=BVB01&doc_number=029052755&sequence=000001&line_number=0001&func_code=DB_RECORDS&service_type=MEDIA |3 Inhaltsverzeichnis |
999 | |a oai:aleph.bib-bvb.de:BVB01-029052755 |
Datensatz im Suchindex
_version_ | 1804176377974358016 |
---|---|
adam_text | Optimized C++
PROVEN TECHNIQUES FOR HEIGHTENED PERFORMANCE
Kurt Guntheroth
Table of Contents
Preface xv
1 An Overview of Optimization 1
Optimization Is Part of Software Development 2
Optimization Is Effective 3
It’s OK to Optimize 3
A Nanosecond Here, a Nanosecond There 6
Summary of Strategies for Optimizing C++ Code 6
Use a Better Compiler, Use Your Compiler Better 7
Use Better Algorithms 8
Use Better Libraries 9
Reduce Memory Allocation and Copying 10
Remove Computation 11
Use Better Data Structures 12
Increase Concurrency 12
Optimize Memory Management 12
Summary 12
2 Computer Behavior Affecting Optimization 15
Lies C++ Believes About Computers 16
The Truth About Computers 17
Memory Is Slow 17
Memory Is Not Accessed in Bytes 18
Some Memory Accesses Are Slower than Others 19
Memory Words Have a Big End and a Little End 20
Memory Has Finite Capacity 20
Instruction Execution Is Slow 21
Making Decisions Is Hard for Computers 22
There Are Multiple Streams of Program Execution 22
Calling into the Operating System Is Expensive 24
C++ Tells Lies Too 24
All Statements Are Not Equally Expensive 24
Statements Are Not Executed in Order 25
Summary 26
3 Measure Performance 27
The Optimizing Mindset 28
Performance Must Be Measured 28
Optimizers Are Big Game Hunters 29
The 90/10 Rule 29
Amdahl’s Law 31
Perform Experiments 32
Keep a Lab Notebook 34
Measure Baseline Performance and Set Goals 35
You Can Improve Only What You Measure 37
Profile Program Execution 37
Time Long-Running Code 40
“A Little Learning” About Measuring Time 40
Measuring Time with Computers 46
Overcoming Measurement Obstacles 54
Create a Stopwatch Class 58
Time Hot Functions in a Test Harness 62
Estimate Code Cost to Find Hot Code 63
Estimate the Cost of Individual C++ Statements 63
Estimate the Cost of Loops 64
Other Ways to Find Hot Spots 66
Summary 67
4 Optimize String Use: A Case Study 69
Why Strings Are a Problem 69
Strings Are Dynamically Allocated 70
Strings Are Values 70
Strings Do a Lot of Copying 71
First Attempt at Optimizing Strings 72
Use Mutating String Operations to Eliminate Temporaries 74
Reduce Reallocation by Reserving Storage 74
Eliminate Copying of String Arguments 75
Eliminate Pointer Dereference Using Iterators 76
Eliminate Copying of Returned String Values 77
Use Character Arrays Instead of Strings 78
vi | Table of Contents
Summary of First Optimization Attempt 80
Second Attempt at Optimizing Strings 80
Use a Better Algorithm 80
Use a Better Compiler 82
Use a Better String Library 83
Use a Better Allocator 87
Eliminate String Conversion 88
Conversion from C String to std::string 89
Converting Between Character Encodings 89
Summary 90
Optimize Algorithms 91
Time Cost of Algorithms 92
Best-Case, Average, and Worst-Case Time Cost 95
Amortized Time Cost 95
Other Costs 96
Toolkit to Optimize Searching and Sorting 96
Efficient Search Algorithms 96
Time Cost of Searching Algorithms 97
All Searches Are Equal When n Is Small 98
Efficient Sort Algorithms 98
Time Cost of Sorting Algorithms 99
Replace Sorts Having Poor Worst-Case Performance 99
Exploit Known Properties of the Input Data 100
Optimization Patterns 100
Precomputation 101
Lazy Computation 102
Batching 102
Caching 103
Specialization 104
Taking Bigger Bites 104
Hinting 105
Optimizing the Expected Path 105
Hashing 105
Double-Checking 105
Summary 106
Optimize Dynamically Allocated Variables 107
C++ Variables Refresher 108
Storage Duration of Variables 108
Ownership of Variables 111
Value Objects and Entity Objects 112
Table of Contents | vii
C++ Dynamic Variable API Refresher 113
Smart Pointers Automate Ownership of Dynamic Variables 116
Dynamic Variables Have Runtime Cost 118
Reduce Use of Dynamic Variables 119
Create Class Instances Statically 119
Use Static Data Structures 121
Use std::make_shared Instead of new 124
Don’t Share Ownership Unnecessarily 125
Use a “Master Pointer” to Own Dynamic Variables 126
Reduce Reallocation of Dynamic Variables 127
Preallocate Dynamic Variables to Prevent Reallocation 127
Create Dynamic Variables Outside of Loops 128
Eliminate Unneeded Copying 129
Disable Unwanted Copying in the Class Definition 130
Eliminate Copying on Function Call 131
Eliminate Copying on Function Return 132
Copy Free Libraries 134
Implement the “Copy on Write” Idiom 136
Slice Data Structures 137
Implement Move Semantics 137
Nonstandard Copy Semantics: A Painful Hack 138
std::swap(): The Poor Man’s Move Semantics 138
Shared Ownership of Entities 139
The Moving Parts of Move Semantics 140
Update Code to Use Move Semantics 141
Subtleties of Move Semantics 142
Flatten Data Structures 145
Summary 146
7 Optimize Hot Statements 147
Remove Code from Loops 148
Cache the Loop End Value 149
Use More Efficient Loop Statements 149
Count Down Instead of Up 150
Remove Invariant Code from Loops 151
Remove Unneeded Function Calls from Loops 152
Remove Hidden Function Calls from Loops 155
Remove Expensive, Slow-Changing Calls from Loops 156
Push Loops Down into Functions to Reduce Call Overhead 157
Do Some Actions Less Frequently 158
What About Everything Else? 160
Remove Code from Functions 160
viii | Table of Contents
Cost of Function Calls 161
Declare Brief Functions Inline 165
Define Functions Before First Use 165
Eliminate Unused Polymorphism 165
Discard Unused Interfaces 166
Select Implementation at Compile Time with Templates 170
Eliminate Uses of the PIMPL Idiom 171
Eliminate Calls into DLLs 173
Use Static Member Functions Instead of Member Functions 173
Move Virtual Destructor to Base Class 174
Optimize Expression s 174
Simplify Expressions 175
Group Constants Together 176
Use Less-Expensive Operators 177
Use Integer Arithmetic Instead of Floating Arithmetic 177
Double May Be Faster than Float 179
Replace Iterative Computations with Closed Forms 180
Optimize Control Flow Idioms 182
Use switch Instead of if-elseif-else 182
Use Virtual Functions Instead of switch or if 182
Use No-Cost Exception Handling 183
Summary 185
8 Use Better Libraries 187
Optimize Standard Library Use 187
Philosophy of the C++ Standard Library 188
Issues in Use of the C++ Standard Library 188
Optimize Existing Libraries 191
Change as Little as Possible 191
Add Functions Rather than Change Functionality 192
Design Optimized Libraries 192
Code in Haste, Repent at Leisure 193
Parsimony Is a Virtue in Library Design 194
Make Memory Allocation Decisions Outside the Library 194
When in Doubt, Code Libraries for Speed 195
Functions Are Easier to Optimize than Frameworks 195
Flatten Inheritance Hierarchies 196
Flatten Calling Chains 196
Flatten Layered Designs 196
Avoid Dynamic Lookup 198
Beware of ‘God Functions’ 199
Summary 200
Table of Contents | ix
9 Optimize Searching and Sorting 201
Key/Value Tables Using std::map and std::string 202
Toolkit to Improve Search Performance 203
Make a Baseline Measurement 204
Identify the Activity to Be Optimized 204
Decompose the Activity to Be Optimized 205
Change or Replace Algorithms and Data Structures 206
Using the Optimization Process on Custom Abstractions 208
Optimize Search Using std::map 208
Use Fixed-Size Character Array Keys with std::map 208
Use C-Style String Keys with std::map 210
Using Maps Cousin std::set When the Key Is in the Value 212
Optimize Search Using the algorithm Header 213
Key/Value Table for Search in Sequence Containers 214
std::find(): Obvious Name, O(n) Time Cost 215
std::binary_search(): Does Not Return Values 216
Binary Search Using std::equal_range() 216
Binary Search Using std::lower_bound() 217
Handcoded Binary Search 218
Handcoded Binary Search using strcmpO 219
Optimize Search in Hashed Key/Value Tables 220
Hashing with a std::unordered_map 221
Hashing with Fixed Character Array Keys 221
Hashing with Null-Terminated String Keys 222
Hashing with a Custom Hash Table 224
Stepanovs Abstraction Penalty 225
Optimize Sorting with the C++ Standard Library 226
Summary 228
10 Optimize Data Structures 229
Get to Know the Standard Library Containers 229
Sequence Containers 230
Associative Containers 230
Experimenting with the Standard Library Containers 231
std::vector and std::string 236
Performance Consequences of Reallocation 237
Inserting and Deleting in std::vector 238
Iterating in std::vector 240
Sorting std::vector 241
Lookup with std::vector 241
std::deque 242
Inserting and Deleting in std::deque 243
x | Table of Contents
Iterating in std::deque 245
Sorting std::deque 245
Lookup with std::deque 245
std::list 245
Inserting and Deleting in std::list 247
Iterating in std::list 248
Sorting std::list 248
Lookup with std::list 249
std::forward_list 249
Inserting and Deleting in std::forward_list 250
Iterating in std::forward_list 251
Sorting std::forward_list 251
Lookup in std::forward_Iist 251
std::map and std::multimap 251
Inserting and Deleting in std::map 252
Iterating in std::map 255
Sorting std::map 255
Lookup with std::map 255
std::set and std::multiset 255
std::unordered_map and std::unordered_multimap 256
Inserting and Deleting in std::unordered_map 260
Iterating in std::unordered_map 260
Lookup with std::unordered_map 261
Other Data Structures 261
Summary 263
Optimize I/O 265
A Recipe for Reading Files 265
Create a Parsimonious Function Signature 267
Shorten Calling Chains 269
Reduce Reallocation 269
Take Bigger Bites—Use a Bigger Input Buffer 272
Take Bigger Bites—Read a Line at a Time 272
Shorten Calling Chains Again 274
Things That Didn’t Help 275
Writing Files 276
Reading from std::cin and Writing to std::cout 277
Summary 278
Optimize Concurrency 279
Concurrency Refresher 280
A Walk Through the Concurrency Zoo 281
Table of Contents | xi
Interleaved Execution 285
Sequential Consistency 286
Races 287
Synchronization 288
Atomicity 289
C++ Concurrency Facilities Refresher 291
Threads 291
Promises and Futures 292
Asynchronous Tasks 295
Mutexes 296
Locks 297
Condition Variables 298
Atomic Operations on Shared Variables 301
On Deck: Future C++ Concurrency Features 304
Optimize Threaded C++ Programs 305
Prefer std::async to std::thread 306
Create as Many Runnable Threads as Cores 308
Implement a Task Queue and Thread Pool 309
Perform I/O in a Separate Thread 310
Program Without Synchronization 310
Remove Code from Startup and Shutdown 313
Make Synchronization More Efficient 314
Reduce the Scope of Critical Sections 314
Limit the Number of Concurrent Threads 315
Avoid the Thundering Herd 316
Avoid Lock Convoys 317
Reduce Contention 317
Don’t Busy-Wait on a Single-Core System 319
Don’t Wait Forever 319
Rolling Your Own Mutex May Be Ineffective 319
Limit Producer Output Queue Length 320
Concurrency Libraries 320
Summary 322
13 Optimize Memory Management 323
C++ Memory Management API Refresher 324
The Life Cycle of Dynamic Variables 324
Memory Management Functions Allocate and Free Memory 325
New-Expressions Construct Dynamic Variables 328
Delete-Expressions Dispose of Dynamic Variables 331
Explicit Destructor Calls Destroy Dynamic Variables 332
High-Performance Memory Managers 333
xii | Table of Contents
Provide Class-Specific Memory Managers 335
Fixed-Size-Block Memory Manager 336
Block Arena 338
Adding a Class-Specific operator new() 340
Performance of the Fixed-Block Memory Manager 342
Variations on the Fixed-Block Memory Manager 342
Non-Thread Safe Memory Managers Are Efficient 343
Provide Custom Standard Library Allocators 343
Minimal C++11 Allocator 346
Additional Definitions for C++98 Allocator 347
A Fixed-Block Allocator 352
A Fixed-Block Allocator for Strings 354
Summary 355
Index 357
|
any_adam_object | 1 |
author | Guntheroth, Kurt |
author_GND | (DE-588)1101611111 |
author_facet | Guntheroth, Kurt |
author_role | aut |
author_sort | Guntheroth, Kurt |
author_variant | k g kg |
building | Verbundindex |
bvnumber | BV043638891 |
classification_rvk | ST 250 |
ctrlnum | (OCoLC)953073305 (DE-599)HBZHT018981754 |
discipline | Informatik |
edition | First edition |
format | Book |
fullrecord | <?xml version="1.0" encoding="UTF-8"?><collection xmlns="http://www.loc.gov/MARC21/slim"><record><leader>01377nam a2200349 c 4500</leader><controlfield tag="001">BV043638891</controlfield><controlfield tag="003">DE-604</controlfield><controlfield tag="005">20160812 </controlfield><controlfield tag="007">t</controlfield><controlfield tag="008">160623s2016 a||| |||| 00||| eng d</controlfield><datafield tag="020" ind1=" " ind2=" "><subfield code="a">9781491922064</subfield><subfield code="c">pbk</subfield><subfield code="9">978-1-4919-2206-4</subfield></datafield><datafield tag="035" ind1=" " ind2=" "><subfield code="a">(OCoLC)953073305</subfield></datafield><datafield tag="035" ind1=" " ind2=" "><subfield code="a">(DE-599)HBZHT018981754</subfield></datafield><datafield tag="040" ind1=" " ind2=" "><subfield code="a">DE-604</subfield><subfield code="b">ger</subfield><subfield code="e">rda</subfield></datafield><datafield tag="041" ind1="0" ind2=" "><subfield code="a">eng</subfield></datafield><datafield tag="049" ind1=" " ind2=" "><subfield code="a">DE-83</subfield><subfield code="a">DE-11</subfield></datafield><datafield tag="084" ind1=" " ind2=" "><subfield code="a">ST 250</subfield><subfield code="0">(DE-625)143626:</subfield><subfield code="2">rvk</subfield></datafield><datafield tag="100" ind1="1" ind2=" "><subfield code="a">Guntheroth, Kurt</subfield><subfield code="e">Verfasser</subfield><subfield code="0">(DE-588)1101611111</subfield><subfield code="4">aut</subfield></datafield><datafield tag="245" ind1="1" ind2="0"><subfield code="a">Optimized C++</subfield><subfield code="c">Kurt Guntheroth</subfield></datafield><datafield tag="246" ind1="1" ind2="3"><subfield code="a">Optimized C++ proven techniques for heightened performance</subfield></datafield><datafield tag="250" ind1=" " ind2=" "><subfield code="a">First edition</subfield></datafield><datafield tag="264" ind1=" " ind2="1"><subfield code="a">Beijing ; Boston ; Farnham ; Sebastopol ; Tokyo</subfield><subfield code="b">O'Reilly</subfield><subfield code="c">April 2016</subfield></datafield><datafield tag="300" ind1=" " ind2=" "><subfield code="a">xviii, 366 Seiten</subfield><subfield code="b">Illustrationen</subfield></datafield><datafield tag="336" ind1=" " ind2=" "><subfield code="b">txt</subfield><subfield code="2">rdacontent</subfield></datafield><datafield tag="337" ind1=" " ind2=" "><subfield code="b">n</subfield><subfield code="2">rdamedia</subfield></datafield><datafield tag="338" ind1=" " ind2=" "><subfield code="b">nc</subfield><subfield code="2">rdacarrier</subfield></datafield><datafield tag="500" ind1=" " ind2=" "><subfield code="a">Auf dem Cover: "Optimized C++ proven techniques for heightened performance"</subfield></datafield><datafield tag="650" ind1="0" ind2="7"><subfield code="a">C++</subfield><subfield code="0">(DE-588)4193909-8</subfield><subfield code="2">gnd</subfield><subfield code="9">rswk-swf</subfield></datafield><datafield tag="689" ind1="0" ind2="0"><subfield code="a">C++</subfield><subfield code="0">(DE-588)4193909-8</subfield><subfield code="D">s</subfield></datafield><datafield tag="689" ind1="0" ind2=" "><subfield code="5">DE-604</subfield></datafield><datafield tag="856" ind1="4" ind2="2"><subfield code="m">HEBIS Datenaustausch</subfield><subfield code="q">application/pdf</subfield><subfield code="u">http://bvbr.bib-bvb.de:8991/F?func=service&doc_library=BVB01&local_base=BVB01&doc_number=029052755&sequence=000001&line_number=0001&func_code=DB_RECORDS&service_type=MEDIA</subfield><subfield code="3">Inhaltsverzeichnis</subfield></datafield><datafield tag="999" ind1=" " ind2=" "><subfield code="a">oai:aleph.bib-bvb.de:BVB01-029052755</subfield></datafield></record></collection> |
id | DE-604.BV043638891 |
illustrated | Illustrated |
indexdate | 2024-07-10T07:31:13Z |
institution | BVB |
isbn | 9781491922064 |
language | English |
oai_aleph_id | oai:aleph.bib-bvb.de:BVB01-029052755 |
oclc_num | 953073305 |
open_access_boolean | |
owner | DE-83 DE-11 |
owner_facet | DE-83 DE-11 |
physical | xviii, 366 Seiten Illustrationen |
publishDate | 2016 |
publishDateSearch | 2016 |
publishDateSort | 2016 |
publisher | O'Reilly |
record_format | marc |
spelling | Guntheroth, Kurt Verfasser (DE-588)1101611111 aut Optimized C++ Kurt Guntheroth Optimized C++ proven techniques for heightened performance First edition Beijing ; Boston ; Farnham ; Sebastopol ; Tokyo O'Reilly April 2016 xviii, 366 Seiten Illustrationen txt rdacontent n rdamedia nc rdacarrier Auf dem Cover: "Optimized C++ proven techniques for heightened performance" C++ (DE-588)4193909-8 gnd rswk-swf C++ (DE-588)4193909-8 s DE-604 HEBIS Datenaustausch application/pdf http://bvbr.bib-bvb.de:8991/F?func=service&doc_library=BVB01&local_base=BVB01&doc_number=029052755&sequence=000001&line_number=0001&func_code=DB_RECORDS&service_type=MEDIA Inhaltsverzeichnis |
spellingShingle | Guntheroth, Kurt Optimized C++ C++ (DE-588)4193909-8 gnd |
subject_GND | (DE-588)4193909-8 |
title | Optimized C++ |
title_alt | Optimized C++ proven techniques for heightened performance |
title_auth | Optimized C++ |
title_exact_search | Optimized C++ |
title_full | Optimized C++ Kurt Guntheroth |
title_fullStr | Optimized C++ Kurt Guntheroth |
title_full_unstemmed | Optimized C++ Kurt Guntheroth |
title_short | Optimized C++ |
title_sort | optimized c |
topic | C++ (DE-588)4193909-8 gnd |
topic_facet | C++ |
url | http://bvbr.bib-bvb.de:8991/F?func=service&doc_library=BVB01&local_base=BVB01&doc_number=029052755&sequence=000001&line_number=0001&func_code=DB_RECORDS&service_type=MEDIA |
work_keys_str_mv | AT guntherothkurt optimizedc AT guntherothkurt optimizedcproventechniquesforheightenedperformance |