March 2023

Effortless Performance Improvements in C++: Parts 1& 2 -- Julien Jorge

And nary a drop to drink:

Effortless Performance Improvements in C++

Part 1: Analyzing a program

Part 2: std::unordered_map

by Julien Jorge

From the articles:

In this series of blog posts we are going to explore the implications on processing time for typical C++ way-of-doing by implementing a non-trivial task using idiomatic C++. Then we will benchmark this program and improve its performance.

Optimization is a never-ending quest that can lead to huge sacrifices in terms of code readability. ... In these blog posts we will restrict ourselves into transformations that do not diminish the expressiveness of the existing interfaces, and we will stay withing the scope of the standard library. We will see that even within these limits one can easily reduce processing times by a factor of two, and maybe three with some compromises. ...

Decreasing the Number of Memory Accesses, 1.2 -- Johnny's Software Lab

Screenshot_2023-03-07_130055.jpgLess (memory access) is more (speed):

Decreasing the Number of Memory Accesses, 1.2

by Johnny's Software Lab

From the article:

When we are trying to speed up a memory-bound loop, there are several different paths. We could try decreasing the dataset size. We could try increasing available instruction level parallelism. We could try modifying the way we access data. Some of these techniques are very advanced. But sometimes we should start with the basics.

One of the ways to improve on memory boundness of a certain piece of code is the old-fashioned way: decrease the total number of memory accesses (loads or stores). Once a piece of data is in the register, using it is very cheap, to the point of being free (due to CPU’s ability to execute up to 4 instructions in a single cycle and their out-of-order nature). So all techniques that try to lower the total number of loads and stores should result in speedups. ...

Fun with printing tables with std::format and C++20 -- Bartlomiej Filipek


Fun with <format>, with a dash of <chrono> sauce:

Fun with printing tables with std::format and C++20

by Bartlomiej Filipek

From the article:

Today’s experiment went from a simple table printing code using C++17 into a fancier version from C++20. The improved code was “nicer” and easier to write and maintain. Additionally, we got working date-time handling capabilities in just a couple of lines of code! Which wasn’t possible until C++20. ...