int usually the fastest popular type. This property is not compliant with the standard, but it usually applies to today's platforms. We also have things like cstdint int_fast32_t , which is more accurately guaranteed to be the fastest type, which can contain at least 32 bits - I highly recommend them for Persian-sensitive code!
size_t not intended to quickly find an integer. Its purpose is to provide an integer that can contain the size of the largest size of the object, which can contain the address space of the platform. Usually size_t equivalent to the largest native target supported by your processor, but this is not necessary.
I am going to assume that you are on a 64-bit platform. Typically, a 64-bit platform has approximately the same primary for 32-bit and 64-bit operating systems, but you ended up in one place where they usually are not: div / mod can actually be 2-3 times slower on 64-bit integer.In this case, if int is 32-bit and size_t is 64-bit, this explains the problem well.
See the Agner Fog instruction table table for details . For the Intel Sandy Bridge platform, it shows that a 32-bit div has a latency of 20-28 cycles, while a 64-bit div takes 30-94 cycles.
Cory nelson
source share