2 ms·
I think "smallest number of instructions" is a pretty weird metric to use if you are going for "fast" solutions. checked_add_3() has a lot of instructions that
by sltkr 12y ago
I think "smallest number of instructions" is a pretty weird metric to use if you are going for "fast" solutions.
checked_add_3() has a lot of instructions that can be executed in parallel. checked_add_4() has a lot of conditional code which can be skipped. (Branching might be expensive in that case, though on the other hand overflow is rare, so these branches can probably be predicted accurately.)
I have little doubt that the assembly version is fastest in practice, but to compare the other versions, they should be benchmarked.