'How much faster is `int_fastXX_t` than `int` in practice?

I'm optimizing a large C project whose integer arithmetic presently uses int. I'm considering switching to int_fast16_t (or even int_fast8_t) wherever a small integer is sufficient. This'll be a reasonably big job, so before I set out, I want to be confident that this has the potential to decrease run-time noticeably (> 5–10%) for users running the software on modern PCs.

As this will depend on the compiler and hardware (edited to clarify: this will differ from end-user to end-user -- so it's hard to know how representative benchmarking on my own PC would be), I appreciate that this is something of a "how long's a piece of string" question – but is there a rule of thumb for what sort of order of magnitude of speed-up I might hope to gain? Are particular categories of operation particularly likely to yield a benefit?


Related:



Solution 1:[1]

int_fast8_t is the fastest type with at least 8 bits. Assuming a reasonable compiler, it’s never slower than int (if it was then the compiler should have used int). int should be the most common type so it should be fast, it’s quite likely that int8_fast_t is int. especially since this means there are no conversion between int8_fast_t an int needed. That will be by far the most common case.

On an 8 bit or 16 bit system int8_fast_t may be smaller and faster than int, but likely not much. The opposite on a 64 bit system, where int may be 32 bits and slower (but smaller) than a 64 bit int.

And there’s Jeromes comment: If you need a vector of 8 bit ints, and int8_fast_t is 32 bit, then an SIMD vector of int8_fast_t is not what you want. Would be likely as fast as a vector of int, but possibly four times slower than a vector of int8_t.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 gnasher729