• icydefiance@lemm.ee
    link
    fedilink
    arrow-up
    0
    ·
    edit-2
    3 months ago

    Modern compilers are good at inlining functions like that, so the machine code will typically be identical to writing a loop. If it doesn’t, it’s probably a complex function, which means the extra function call is insignificant compared to whatever you’re doing inside the function.

    Also the branch for the loop’s exit condition will exist either way, but that has zero overhead unless the branch prediction guesses wrong.