Analysis of the Impact of the Keyword 'final' on C++ Program Performance

Benjamin Summerton, the author of the PSRayTracing ray tracing system, analyzed the impact of using the keyword 'final' in C++ code on application performance. This testing was prompted by online claims that using 'final' could enhance performance, which were limited to assertions without presenting empirical results.

Benjamin's testing revealed that the performance impact of using 'final' greatly depends on the compiler. In GCC, performance noticeably improved in a significant number of cases, while in Clang and MSVC, performance generally decreased, sometimes significantly. Additionally, platform had a considerable influence; for example, performance degradation was more pronounced on a system with an AMD Ryzen 9 6900HX CPU compared to a system with an Apple M1 CPU.

Analysis of the Impact of the Keyword 'final' on C++ Program Performance
Analysis of the Impact of the Keyword 'final' on C++ Program Performance

For instance, on an AMD Ryzen 9 6900HX system with Ubuntu 23.10, when using Clang, 90% of tests showed that using 'final' resulted in a slowdown of at least 5%, while in 2.5% of cases, there was a speedup of at least 5%. For GCC, a 5% slowdown occurred in 0.9% of cases, and a 5% speedup in 15.8% of cases. In MSVC, a 5% slowdown was observed in 26.2% of tests, while a 5% speedup was seen in 13.3%. The author of the study concluded that the use of 'final' should be avoided.

Source: opennet.ru

Buy reliable website hosting with DDoS protection, VPS VDS servers 🔥 Buy reliable website hosting with DDoS protection, VPS VDS servers | ProHoster