Modern CPUs like the AMD Ryzen 9 5950x with their 16 cores and 32 threads offer a significant productivity boost when developing C++ projects for Windows. As we saw in the previous post (Compile 1 Million Lines Of C++ In ~2 Minutes With A 16 Core Ryzen 9 5950x) we were able to compile over 1 million lines of C++ code in around 2 minutes using TwineCompile in C++Builder. Additionally, we were able to compile 1 million lines of Object Pascal code in 16 seconds (extrapolated), parallel built 300 native Windows apps in Delphi in 45 seconds, and finally we were able to compile 1 billion lines of Object Pascal code in around 5 minutes.
TwineCompile is built to compile a single C++Builder project in parallel using all cores. However, for this post we wanted to built all of the C++Builder demo projects for Windows 32-bit in parallel. The demo projects are a small amount of code spread out over 168 projects. Using Delphi Parallel Build (which supports both Delphi and C++ projects) we were able to compile 124 of those Windows projects in parallel in 68 seconds (44 of the compiles fail in the parallel build due to dependencies or custom configuration that they might need). The parallel compile is fastest when set to use 16 threads on the 16 cores (verses using the 32 threads on 16 cores). The 16 cores of the 5950x really comes in to play here for parallel compilation and you can see how it can massively boost your productivity (combined with C++Builder) when working with Windows C++ projects. The projects used for the build are available on GitHub:
The full specs on the AMD Ryzen 9 5950x benchmark machine are AMD Ryzen 9 5950x, 64GB DDR4 3200MHz RAM, 1TB NVMe SSD + 2TB HDD, NVIDIA GeForce RTX 3070 8GB, and Windows 10 Pro. In order to monitor the CPU and Disk IO usage of C++Builder’s parallel compile I used Task Manager DeLuxe or TMX (which is also built in Delphi). Task Manager DeLuxe is pretty amazing in the amount of information it provides regarding your Windows system. TMX even supports setting CPU affinity (which CPU the process will run on) for each process. Process Lasso is another such tool used by overclockers to set CPU affinity. TMX is available from MiTeC which also makes a wide variety of Delphi components including the MiTeC System Information Component Suite that give you access to a lot of the same information found in TMX. Here is the per process CPU affinity selection dialog.
The screenshot below features the System tab from TMX on the AMD Ryzen 9 5950x machine.
Next up let’s take a look at the CPU graphs during the parallel compile of the 124 C++ projects for Windows. As you can see in this screenshot I did two parallel compiles back to back which is why each of the 16 cores has two spikes. The parallel compile uses up 100% of all cores according to the graphs. RAD Studio is in the background with Delphi Parallel Build above it and finally Task Manage DeLuxe in the foreground of the screenshot with all 16 cores blazing away on the C++ parallel compile. Delphi Parallel Build executes a MSBuild process which then launches the C++Builder Windows 32-Bit compiler.
The AMD Ryzen 5000 line of processors uses “Zen 3” core architecture which you can find out more about here. AMD has a YouTube video which explains the “Zen 3” architecture. At the time of this writing the AMD Ryzen 9 5950x CPU has one of the fastest single thread CPU available according to PassMark benchmarks. On single core performance the Intel Core i7-11700K is comparable but it only has 8 cores instead of 16 like the AMD Ryzen 9 5950x. As we’ve seen with the cores verses threads in this parallel compile the 16 cores of the 5950x really makes a difference during parallel compilation.
Get a more insightful read on the distinctive features of 5950x vs 3950x and compare the two on different aspects such as cores, debugs, and threads.
Next let’s take a look at some more screenshots from after the parallel compile. This next screen shows the combined CPU usage of all of the cores instead of being broken out on a core by core basis. The 5950x supports 32 threads but only has 16 cores. When parallel compiling C++ it seems to work better to set it to 16 threads which matches the number of cores instead of 32 threads. You can also see in this screenshot how TMX color codes the CPU graph based on the process which is using that percentage of the CPU. The total compile time for the 124 projects was around 68 seconds.
The next screenshot here is the Disk I/O graph for the machine found in TMX. There are two sets of spikes here with each one corresponding to one of the parallel project compiles. The pink spikes are writes and the yellow spikes are reads.
In addition to system wide performance graphs Task Manager DeLuxe features per process information and performance graphics. In the screenshot below you can see the DelphiParallelBuild process from after the compile with spikes in CPU usage, I/O read, and I/O write during the compile. Lots of other useful process information here including user handles, GDI handles, and more. You can also set the processor affinity from this screen (via the Affinity button) there at the top.
As a bonus I also wanted to combine the 300 Delphi project parallel compile with the 124 project C++Builder parallel compile for a total of 424 projects. This took a total of 106 seconds (4 projects per second) to compile 424 RAD Studio Windows 32-bit projects on the AMD Ryzen 9 5950x. In the below screenshot you can see the combined CPU graph shortly after this massive 424 project parallel compile with the 106343ms reading at the bottom left of the Delphi Parallel Build window. One of the C++Builder projects is a bit larger than the others which accounts for the shorter tail near the end of the compile graph.
Ready to start using the full power of your own multi-core CPU for a productivity boost with your C++Builder projects? Simply download TwineCompile from GetIt within the IDE. TwineCompile was not used during the 124 project C++ parallel compile because the projects are rather small and the benefits found in TwineCompile are seen in larger projects (like the previous 1 million lines of C++ in 2 minutes). The Delphi Parallel Build project was updated for this post to include additional options like auto detecting the CPU count and supporting TwineCompile with MSBuild. A new setting in Delphi Parallel Build will automatically insert the TwineCompile MSBuild line in the project file and then remove it again after the build. A good way to use Delphi Parallel Build with TwineCompile on multiple large C++ projects is to set Delphi Parallel Build to 1 thread and enable the TwineCompile option. This will compile each project one at a time and then use all cores for the individual project. TwineCompile lists its features as:
- Advanced compile system uses multi-threading technology and caching techniques to make C++ compiles 50x faster!
- Automatic background compiling engine ensures that files are compiled as fast as they are saved!
- Tuned pre-compiled header handling system automatically maximizes simultaneous use of pre-compiled headers between multiple threads!
- Seamless integration into the C++Builder IDE. Supports all versions including C++Builder 10.4 Sydney!
- Theme support for all IDE themes providing a unified workspace!
- Full support for 32-bit and 64-bit compilers!
- FinalBuilder integration provided out of the box!
Learn more about AMD’s Ryzen 9 5950X and Threadripper 3990X as well as the productivity of these modern desktop processors when combined with Delphi.