Giadzy - Shop now

These promotions will be applied to this item:

Some promotions may be combined; others are not eligible to be combined with other offers. For details, please see the Terms & Conditions associated with these promotions.

eBook features:
  • Highlight, take notes, and search in the book
  • In this edition, page numbers are just like the physical edition
You've subscribed to ! We will preorder your items within 24 hours of when they become available. When new books are released, we'll charge your default payment method for the lowest price available during the pre-order period.
Update your device or payment method, cancel individual pre-orders or your subscription at
Your Memberships & Subscriptions
Kindle app logo image

Download the free Kindle app and start reading Kindle books instantly on your smartphone, tablet, or computer - no Kindle device required.

Read instantly on your browser with Kindle for Web.

Using your mobile phone camera - scan the code below and download the Kindle app.

QR code to download the Kindle App

Follow the author

Something went wrong. Please try your request again later.

The Art of Writing Efficient Programs: An advanced programmer's guide to efficient hardware utilization and compiler optimizations using C++ examples 1st Edition, Kindle Edition

4.6 4.6 out of 5 stars 75 ratings

Become a better programmer with performance improvement techniques such as concurrency, lock-free programming, atomic operations, parallelism, and memory management

Key Features

  • Learn proven techniques from a heavyweight and recognized expert in C++ and high-performance computing
  • Understand the limitations of modern CPUs and their performance impact
  • Find out how you can avoid writing inefficient code and get the best optimizations from the compiler
  • Learn the tradeoffs and costs of writing high-performance programs

Book Description

The great free lunch of "performance taking care of itself" is over. Until recently, programs got faster by themselves as CPUs were upgraded, but that doesn't happen anymore. The clock frequency of new processors has almost peaked, and while new architectures provide small improvements to existing programs, this only helps slightly. To write efficient software, you now have to know how to program by making good use of the available computing resources, and this book will teach you how to do that.

The Art of Efficient Programming covers all the major aspects of writing efficient programs, such as using CPU resources and memory efficiently, avoiding unnecessary computations, measuring performance, and how to put concurrency and multithreading to good use. You'll also learn about compiler optimizations and how to use the programming language (C++) more efficiently. Finally, you'll understand how design decisions impact performance.

By the end of this book, you'll not only have enough knowledge of processors and compilers to write efficient programs, but you'll also be able to understand which techniques to use and what to measure while improving performance. At its core, this book is about learning how to learn.

What you will learn

  • Discover how to use the hardware computing resources in your programs effectively
  • Understand the relationship between memory order and memory barriers
  • Familiarize yourself with the performance implications of different data structures and organizations
  • Assess the performance impact of concurrent memory accessed and how to minimize it
  • Discover when to use and when not to use lock-free programming techniques
  • Explore different ways to improve the effectiveness of compiler optimizations
  • Design APIs for concurrent data structures and high-performance data structures to avoid inefficiencies

Who this book is for

This book is for experienced developers and programmers who work on performance-critical projects and want to learn new techniques to improve the performance of their code. Programmers in algorithmic trading, gaming, bioinformatics, computational genomics, or computational fluid dynamics communities will get the most out of the examples in this book, but the techniques are fairly universal. Although this book uses the C++ language, the concepts demonstrated in the book can be easily transferred or applied to other compiled languages such as C, Java, Rust, Go, and more.

Table of Contents

  1. Introduction to Performance and Concurrency
  2. Performance Measurements
  3. CPU Architecture, Resources, and Performance Implications
  4. Memory Architecture and Performance
  5. Threads, Memory, and Concurrency
  6. Concurrency and Performance
  7. Data Structures for Concurrency
  8. Concurrency in C++
  9. High-Performance C++
  10. Compiler Optimizations in C++
  11. Undefined Behavior and Performance
  12. Design for Performance
Due to its large file size, this book may take longer to download

From the brand


From the Publisher

B16229 - top
B16229 - 1

How has your background helped you to write this book?

I started programming as a college student when even the simplest programs had to be written with performance in mind. While times have changed, I kept finding myself working in the areas where the hardware capabilities were never enough: first, in computational physics and then in electronic design automation. By choice or circumstance, I have always been programming close to hardware - the skill that is in demand once more in recent years in areas like low latency and high-performance concurrency. As for compilers, their ability to improve performance is miles ahead of what it once was, and so is the potential magnitude of the failure when the expected performance boost does not materialize due to a quirk of the language or a peculiarity of the hardware interfering with the programmer's intent. All in all, I found the old habits, if not the old knowledge, relevant again in the modern age of high-performance computing.

code screen

What part or parts of the book are your favorite, and why?

Several parts, and the experience of writing them, stand out in my memory. First of all, it's the chapter on designing for performance. So often, performance is considered a feature to be added later. The mantra "do not optimize prematurely" is as widely known as it is misunderstood; its intended meaning is much more nuanced than most programmers realize. The idea that performance targets are as much a part of the original design specification as the feature list often comes as a surprise; if I can teach one thing to the readers of my book, I would want it to be this idea.

Other favorite moments are the ones where I found and presented some minor or innocuous change that has an unexpectedly large effect on performance. Certain compiler optimizations, seemingly trivial changes to memory access, and clever concurrent algorithms all have that element of surprise and even disbelief: "It does WHAT?"

computer

In what ways have you been active in the community?

Mostly in various educational activities, like conference presentations and CppCon Academy classes. Sharing my knowledge and having the knowledge and experience of others shared with me are where I find my role in the C++ community most useful.

B16229

What makes this book better than other similar titles?

Obviously, the content, the presentation, and the style! Seriously though, there are several strengths of the book in my mind. First is the emphasis on not just imparting knowledge and information, but explaining how we came to know what we know, and how such knowledge can be re-discovered when the next generations of hardware, languages, and compilers will make the guidelines of today obsolete. In this way, it is a book about learning to learn. Second is the scope, the breadth of it: it is rare to find, in one place, the presentation of the performance effects that originate from the hardware, the compilers, the language features, and the design decisions, and their mutual interactions.

Editorial Reviews

About the Author

Fedor G. Pikus is a chief engineering scientist in the Mentor IC Segment of Siemens Digital Industries Software and is responsible for the long-term technical direction of Calibre products, the design and architecture of software, and research into new software technologies. His previous roles included senior software engineer at Google and chief software architect at Mentor Graphics. Fedor is a recognized expert in high-performance computing and C++. He has presented his works at CPPCon, SD West, DesignCon, and in software development journals, and is also an O'Reilly author. Fedor has over 25 patents and over 100 papers and conference presentations on physics, EDA, software design, and C++.

Product details

  • ASIN ‏ : ‎ B09BZTGJM2
  • Publisher ‏ : ‎ Packt Publishing; 1st edition (October 22, 2021)
  • Publication date ‏ : ‎ October 22, 2021
  • Language ‏ : ‎ English
  • File size ‏ : ‎ 16045 KB
  • Text-to-Speech ‏ : ‎ Enabled
  • Screen Reader ‏ : ‎ Supported
  • Enhanced typesetting ‏ : ‎ Enabled
  • X-Ray ‏ : ‎ Not Enabled
  • Word Wise ‏ : ‎ Not Enabled
  • Print length ‏ : ‎ 464 pages
  • Page numbers source ISBN ‏ : ‎ 1800208111
  • Customer Reviews:
    4.6 4.6 out of 5 stars 75 ratings

About the author

Follow authors to get new release updates, plus improved recommendations.
Fedor G Pikus
Brief content visible, double tap to read full content.
Full content visible, double tap to read brief content.

Fedor G Pikus is a Technical Fellow at Siemens Digital Industries Software and the director of the Advanced Projects Team. His earlier positions included a Senior Software Engineer at Google and a Chief Software Architect for Calibre PERC, LVS, and DFM at Mentor Graphics. He joined Mentor Graphics in 1998 when he made a switch from academic research in computational physics to the software industry. Fedor is a recognized expert on high-performance computing and C++, he presented his works at C++Now, CPPCon, SD West, DesignCon, in Software Development Journal, and is also an O'Reilly author. His responsibilities as a Chief Scientist include planning the long-term technical direction of Calibre products, directing and training the engineers who work on these products, design, and architecture of the software, and research in new design and software technologies. Fedor has over 25 patents and over 100 papers and conference presentations on physics, EDA, software design, and C++ language.

Customer reviews

4.6 out of 5 stars
75 global ratings

Customers say

Customers find the book's content useful, interesting, and open their eyes on some subjects. They describe it as a joy to read and connects what they learned in school to real life.

AI-generated from the text of customer reviews

Select to learn more
5 customers mention "Content"5 positive0 negative

Customers find the book's content useful, interesting, and open their eyes to some subjects for experienced developers. They say it teaches beginners and connects what they learned in school to real-life situations. Readers also mention the book is amazing regarding low-level programming and extracting power from hardware.

"Fabulous book, it connects what you learned in school to real life situations...." Read more

"...way - book is fun to read - it is like "Dune" but for developers - intriguing, you wait for - what gonna happen next? with some light humor...." Read more

"...While the content of the book is quite good and interesting to read, the layout is frustrating." Read more

"I've wanted a book like this for a long time which examines the subject clearly and thoroughly from a modern perspective...a joy to read." Read more

4 customers mention "Readability"4 positive0 negative

Customers find the book a joy to read. They say the content is interesting and it connects what they learned in school to real life.

"Fabulous book, it connects what you learned in school to real life situations...." Read more

"...Either way - book is fun to read - it is like "Dune" but for developers - intriguing, you wait for - what gonna happen next?..." Read more

"...While the content of the book is quite good and interesting to read, the layout is frustrating." Read more

"...the subject clearly and thoroughly from a modern perspective...a joy to read." Read more

Excellent read for improving program runtimes at the CPU level
5 out of 5 stars
Excellent read for improving program runtimes at the CPU level
The book “The art of writing efficient programs by Fedor G. Pikusis for experienced developers and programmers who want to learn different methods to improve the performance of their code. The developers who are involved in computer modeling, algorithmic trading and genomics can gain a lot from this book.The first section of the book describes the progress that computing power has made over the years from taking 10 hrs to solve problems in 2008 to less than 1 hour in 2018 and even faster today in 2021. So all this optimization is because of improvement in technologies in software and optimized algorithms.In chapter 1 the author introduces performance and efficiency. Efficient programs make good use of the computational hardware. High performance requires choosing the right CPU, writing the code to execute the program, avoiding unnecessary computations. In chapter 2 the author discusses performance measurements. The first rule is never guess about performance. This chapter describes the tool google-pprof that times each system call that the compiler takes to process. The perf profiler, and C++ chrono timers are described in this section. In chapter 3 the author describes how to make use of CPU resources effectively. In chapter 4 the author discusses memory optimization and concurrency. The spectre error is discussed in memory optimization. The use of mutexes to control the critical section of the code is important to determine the correct order in which the criticl section of the code is serviced. In chapter 5 threads, memory and concurrency a detailed discussion od multi threading fundamentals is done. In chapter 6 concurrency and performance the discussion of parallel programs and performing lock free optimizations are discussed. In chapter 7 data structures for concurrency are discussed.Chapter 8 discusses concurrency in C++Chapter 9 discusses high performance optimizations in C++. Chapter 10 discusses compiler optimizations for C++. Avoiding unnecessary memory allocation and memory fragmentation in programs. Allocate memory in chunks of 64KB. Chapter 11 discusses undefined behaviour and performance. undefined behaviour happens when the program behaves in a manner different from that which is specified. Chapter 12 discuess design for performance.Overall this book is highly recommended for CPU enthusiasts and programmers in the area of high performance computing. When speed is all that matters for solving critical problems this is an excellent resource to use.
Thank you for your feedback
Sorry, there was an error
Sorry we couldn't load the review

Top reviews from the United States

Reviewed in the United States on August 26, 2024
Fabulous book, it connects what you learned in school to real life situations. Even after years in the industry, unless you are on the forefront of performance optimization many of these knowledge are gonna help you. In theory I have learned all these in school but school knowledge here has not connect with industry experiences and this book did it.
Reviewed in the United States on October 23, 2022
This book really teaches beginners and opens eyes on some subjects for experienced developers.
Branch prediction articles were most beneficial to me - many open eyes techniques - thank you! - and it makes you think, again ...
Memory management - at least I got confirmation what is wrong and what is right :).
Either way - book is fun to read - it is like "Dune" but for developers - intriguing, you wait for - what gonna happen next? with some light humor.
I would recommend this book to any level of serious software developers/engineers.
This book deserves 5 stars.
-- this review form 30+ years experience C++ software developer, and counting
3 people found this helpful
Report
Reviewed in the United States on May 12, 2024
The book's layout is poorly designed. For example, there's an unnecessary gray background in the source code sections, which could have been improved by highlighting only the important parts with a gray background and using bold for keywords. While the content of the book is quite good and interesting to read, the layout is frustrating.
Customer image
4.0 out of 5 stars Good content
Reviewed in the United States on May 12, 2024
The book's layout is poorly designed. For example, there's an unnecessary gray background in the source code sections, which could have been improved by highlighting only the important parts with a gray background and using bold for keywords. While the content of the book is quite good and interesting to read, the layout is frustrating.
Images in this review
Customer image
Customer image
Reviewed in the United States on June 18, 2024
Lots of excellent insight regarding designing and writing high performance software. I particularly enjoyed his explanations regarding coroutines. Will definitely be referring back to this book during my next project.
One person found this helpful
Report
Reviewed in the United States on November 17, 2021
I've wanted a book like this for a long time which examines the subject clearly and thoroughly from a modern perspective...a joy to read.
3 people found this helpful
Report
Reviewed in the United States on October 22, 2021
When I saw that this book was 451 pages, my initial reaction was, "Oh, no, not another fluff piece packed with excess meanderings..." After all, I'm a real-time embedded systems programmer with more than 30 years of experience, and I didn't really expect that I would learn enough to justify slogging through 400+ pages of material.

By the middle of the first chapter, I was pretty thoroughly disabused of that hubris. Fedor G. Pikus is a real heavyweight in this field. I don't know if he has an advanced degree -- he doesn't list one -- but I would imagine that he is one of those folks who has just been too busy to pursue one. He's got a list of publications and research papers that spans several pages of web search hits.

Mr. Pikus did an incredible job with this book. He explains some counter-intuitive concepts with a straightforward clarity that left me somewhat embarrassed with how little I knew, and how much I just took for granted because somebody just told me to do something in a particular way at some point in my career. And there were some things that I *did* know, but he explained in a way much better than I had seen before.

It's not an easy read. In order to get the most out of this book, you have really go through every example very carefully. Fortunately, the examples use tools that are readily available in the open-source world.

While I still think that choice of algorithm dwarfs all other considerations combined, Mr. Pikus showed that the choice of the most appropriate algorithm is not always obvious, sometimes for very obscure reasons. So, how does one choose? Pikus demonstrated the use of several tools that can help.

Unfortunately for me, I'm working in an environment where the actual target hardware and OS is not yet available, so I have to rely on simulations which might be sub-optimal. But I expect that when I do get to the point in this project that I get to test with the actual target system, that this book will come in handy. It is well organized, and will be a useful reference.

In summary, this is one of the best-written books on this subject that I have seen to date.
13 people found this helpful
Report
Reviewed in the United States on February 11, 2023
The book's contents are useful, especially as a first introduction to system programming with performance concerns in mind. Only four starts because the quality of the printing can be distracting. The code snippets are zebra striped (alternating dark and light lines) and some terminal output look like they're just screenshots of an Ubuntu terminal instead of also being typeset. The net effect is a presentation that sometimes gets in the way of the content being presented.
3 people found this helpful
Report

Top reviews from other countries

Pedro Oliveira
4.0 out of 5 stars Loved it
Reviewed in Spain on June 2, 2022
The only thing I believe these types of books miss is a proper application. It's easy and good to explain performance and efficiency with simple examples but, at the end of the day, we are not just writing a sorting algorithm.
Ory Chowaw-Liebman
5.0 out of 5 stars Highly inspiring book for C++ developers.
Reviewed in Germany on February 14, 2022
The book provides in-depth guide to writing high performance software, with many code examples. Every software engineer who needs to get the most out of their software and hardware should look into this.
Erik Alapää
5.0 out of 5 stars Solid book on hard topic
Reviewed in Germany on December 20, 2021
One of the few books on efficient and parallell programming with enough breadth and depth of content.
Klaus Iglberger
4.0 out of 5 stars Good Introduction to the essential performance aspects for aspiring C++ developers
Reviewed in Germany on December 14, 2021
The need for performance is back: While performance was not the most important topic during the crazy clockspeed improvements in the' 90s and 2000s, today performance again plays a major role in software development. Whether it is to reduce costs when computing something in the cloud or to increase the duration of your battery, performance is important again, and in particular in C++.

From this perspective, Fedor's book is a valuable and necessary addition to the available C++ book selection. It is a comprehensive volume on many different aspects of performance. Starting with essential questions like "What is performance?", it covers performance benchmarking and profiling, performance tools, and low-level code optimization, concurrency and design for performance. For that reason it provides insight into many different aspects of optimization. Targeted at less-experienced programmers, it always keeps a reasonable pace and explains even the most basic aspects.

I personally consider the chapters about performance profiling and benchmarking as a very valuable addition, since these topics are rarely touched in such a comprehensive way. Unfortunately there were also a couple of letdowns. For instance, I personally felt that advanced topics like lock-free programming were handled too quickly and without much depth. There is very little information beyond the terminology. Also, I was expecting more from the "Design for Performance" chapter. Unfortunately many essential design aspects, as for instance "Separation of Concerns" and the need to design interfaces for performance from the very beginning, are not mentioned at all. For my personal taste, the given advice is too abstract and too few concrete examples are given on how to apply the design advice on real code.

Overall this is a good introduction to the essential performance aspects in software development for aspiring C++ developers.
Augusto H.
1.0 out of 5 stars The graphics are unreadable, and that really hurts understanding
Reviewed in Germany on November 19, 2022
The print is in black and white, but the graphics were clearly done with color in mind. The text assumes the graphics are readable, and that more often than not hurts understanding. The content is fine, but generality not of great quality in terms of formatting, conciseness, and clearness of explanation.
Customer image
Augusto H.
1.0 out of 5 stars The graphics are unreadable, and that really hurts understanding
Reviewed in Germany on November 19, 2022
The print is in black and white, but the graphics were clearly done with color in mind. The text assumes the graphics are readable, and that more often than not hurts understanding. The content is fine, but generality not of great quality in terms of formatting, conciseness, and clearness of explanation.
Images in this review
Customer image
Customer image

Report an issue


Does this item contain inappropriate content?
Do you believe that this item violates a copyright?
Does this item contain quality or formatting issues?