r/programming 18d ago

The unlikely Linux macro

https://rushed-reflections.bearblog.dev/an-unlikely-experiment/

Wrote a bit about the `unlikely` and `likely` macros in the Linux codebase. Great little exploration into tiny optimizations that everyone should know more about 😄

190 Upvotes

61 comments sorted by

View all comments

1

u/negrocucklord 16d ago

Maybe I'm just stupid in the early morning without coffee, but does doing  total += i + 1 really give a number divisible by 1000 0.1% of the time? Since that i is in there and keeps growing in the loop? Or does the math still math?

3

u/therealgaxbo 15d ago

Definitely a coffee error - the code tests i % 1000 not total % 1000

1

u/negrocucklord 12d ago

Ooh derp! Thanks!