Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> The % operation is quite efficient (although it’s usually two times more expensive than multiplication);

I though it was much more than two times slower? Division and modulus are the slowest integer operation.



Agner Fog’s manual lists a latency/reciprocal-throughput of 15/10 for 64-bit divide on Ivy Lake & Tiger Lake, vs 3/1 for 64-bit multiply. So division is 5-10x slower than multiplication.

https://www.agner.org/optimize/#manuals


It makes a significant difference in profiling, versus i.e. a bitwise mask to find a modulus for a power-of-two size.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: