{n} times faster than C

In this post, the author explores optimization opportunities for a loop generated from C code. They provide a function that loops through a string and increments or decrements a number based on the characters it encounters. The author then tweaks the code in various ways, measuring the speedup. They rearrange branches, rearrange blocks, replace jumps with arithmetic, and eliminate conditional branches. Surprisingly, by using conditional moves on equality, they achieve a significant speedup of 6.73x. The author also tests other attempts like unrolling the loop but finds that it slows down the code. They conclude that hand-coding and optimizing can lead to better performance than automated compiler optimizations.

https://owen.cafe/posts/six-times-faster-than-c/

To top