Learning to Write Less Slow C, C++, and Assembly Code The benchmarks in this repository don't aim to cover every topic entirely, but they help form a mindset and intuition for performance-oriented software design. It also provides an example of using some non-STL but de facto standard libraries in C++, importing them via CMake, and compiling from source. For higher-level abstractions and languages, check out less_slow.rs and less_slow.py . Much modern code suffers from common pitfalls, such as bugs, security vulnerabilities, and performance bottlenecks. University curricula often teach outdated concepts, while bootcamps oversimplify crucial software development principles. This repository offers practical examples of writing efficient C and C++ code. It leverages C++20 features and is designed primarily for GCC and Clang compilers on Linux, though it may work on other platforms. The topics range from basic micro-kernels executing in a few nanoseconds to more complex constructs involving parallel algorithms, coroutines, and polymorphism. Some of the highlights include: 100x cheaper random inputs?! Discover how input generation sometimes costs more than the algorithm. Discover how input generation sometimes costs more than the algorithm. 40x faster trigonometry: Speed-up standard library functions like std::sin in just 3 lines of code. Speed-up standard library functions like in just 3 lines of code. 4x faster lazy-logic with custom std::ranges and iterators! with custom and iterators! Compiler optimizations beyond -O3 : Learn about less obvious flags and techniques for another 2x speedup. Learn about less obvious flags and techniques for another 2x speedup. Multiplying matrices? Check how a 3x3x3 GEMM can be 70% slower than 4x4x4, despite 60% fewer ops. Check how a 3x3x3 GEMM can be 70% slower than 4x4x4, despite 60% fewer ops. Scaling AI? Measure the gap between theoretical ALU throughput and your BLAS. Measure the gap between theoretical ALU throughput and your BLA...
First seen: 2025-04-18 14:17
Last seen: 2025-04-18 22:18