Get the most out of this book
To get the most out of this book, you need to have a basic knowledge of C++. It's preferable that you have already faced problems related to performance and are now looking for new tools and practices to have ready for the next time you need to work with performance and C++.
There are a lot of code examples in this book. Some are taken from the real world, but most of them are artificial or vastly simplified examples to prove a concept, rather than provide you with production-ready code.
I have put all the code examples in source files divided by chapter so that it is fairly easy to find the examples you want to experiment with. If you open up the source code files, you will note that I have replaced most of the main()
functions from the examples with test cases written with the Google Test framework. I hope that this will help you rather than confuse you. It allowed me to write helpful descriptions for each example, and it also makes it easier to run all the examples from one chapter at once.
In order to compile and run the examples, you will need the following:
- A computer
- An operating system (the examples have been verified on Windows, Linux, and macOS)
- A compiler (I used Clang, GCC, and Microsoft Visual C++)
- CMake
The CMake script provided with the example code will download and install further dependencies, such as Boost, Google Benchmark, and Google Test.
During the writing of this book, I found it helpful to use Compiler Explorer, which is available at https://godbolt.org/. Compiler Explorer is an online compiler service that lets you try various compilers and versions. Try it out if you haven't already!
Download the example code files
The code bundle for the book is hosted on GitHub at https://github.com/PacktPublishing/Cpp-High-Performance-Second-Edition. If there's an update to the code, it will be updated on the existing GitHub repository.
There are other code bundles from Packt's rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!
Download the color images
Packt also provides a PDF file that has color images of the screenshots/diagrams used in this book. You can download it here: https://static.packt-cdn.com/downloads/9781839216541_ColorImages.pdf.
Conventions used
There are a number of text conventions used throughout this book.
CodeInText
: Indicates code words in text, folder names, filenames, file extensions, dummy URLs, and user input. Here is an example: "The keyword constexpr
was introduced in C++11."
A block of code is set as follows:
#include <iostream>
int main() {
std::cout << "High Performance C++\n";
}
When I wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:
#include <iostream>
int main() {
std::
cout <<
"High Performance C++\n";
}
Any command-line input or output is written as follows:
$ clang++ -std=c++20 high_performance.cpp
$ ./a.out
$ High Performance C++
Bold: Indicates a new term, an important word, or words that you see on the screen. For example: "Fill in the form and click on the Save button."
Warnings or important notes appear like this.