I’m running intensive numerical simulations. I often use long integers, but I realized it would be safe to use integers instead. Would this improve the speed of my simulations significantly?
I’m running intensive numerical simulations. I often use long integers, but I realized it
Share
Depends. If you have lots and lots of numbers consecutively in memory, they’re more likely to fit in the L2 cache, so you have fewer cache misses. L2 cache misses – depending on your platform – can be a significant performance impact, so it’s definitely a good idea to make things fit in cache as much as possible (and prefetch if you can). But don’t expect your code to fly all of a sudden because your types are smaller.
EDIT: One more thing – if you choose an awkward type (like a 16-bit integer on a 32-bit or 64-bit platform), you may end up with worse performance because the CPU will have to surgically extract the 16-bit value and turn it into something it can work with. But typically, ints are a good choice.