Our great sponsors
-
InfluxDB
Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.
> because without FDO (or PGO) the compiler has no idea how likely each branch is to be taken
So, the maximum amount of times you can hit '\0' is once in the string, because then the function returns, but you can hit the other characters many times, which seems to be information a compiler has access to without PGO.
PGO does help, of course, and on my machine gives me 2.80s, which is better than the code at the end of the `Rearranging blocks` section :)
> I assume that their test input (which isn't described in the post, and is also not in their GitHub repo)
It's described under `Benchmarking setup`, and is in the repository here: https://github.com/414owen/blog-code/blob/master/01-six-time...
Side note: There's a part two to this post (linked at the bottom) where I make the C code as fast as I possibly can, and it beats all the assembly in this post.
I never said writing assembly is (necessarily) a good idea, I just find optimizing it, and deciphering compiler output, an interesting challenge, and a good learning opportunity.
I tried https://godbolt.org/, and neither Clang nor GCC trunk give the same code for the two programs.
Pretty shocking for such a simple program.
You could study Google's Highway library [1].
[1] https://github.com/google/highway
Related posts
- John "God" Carmack: C++ with a C flavor is still the best (also: Python performance "keeps hitting me in the face")
- Llamafile 0.7 Brings AVX-512 Support: 10x Faster Prompt Eval Times for AMD Zen 4
- Gemma.cpp: lightweight, standalone C++ inference engine for Gemma models
- 4B If Statements
- Designing a SIMD Algorithm from Scratch