4 ms·
I think this is beyond simply making the variable static/constant. It is the specific value of the constant that is allowing the division to be substituted wit
by alok-g 5y ago
I think this is beyond simply making the variable static/constant. It is the specific value of the constant that is allowing the division to be substituted with bitwise AND, which then makes it so much faster. I wonder how much the speedup would be if some other near-random value is there for the constant (which is likely beyond the purpose at hand).
- sgerenser 5y agoSpeed up would be less but not zero, almost any div or modulo can be replaced by a multiply by a magic constant plus a bit shift.