This is probably a combination of the Matlab interpreter and the main processor, which does not support 64-bit int types, as well as others.
Matlab stands for double over int operations. Most values ββare stored in double types, even if they are integer values. The double and int == operations will use different code paths, and MathWorks will pay much more attention to tweaking and optimizing the code for double than for int, especially int64 . In fact, older versions of Matlab did not support arithmetic operations on int64 at int64 . (And IIRC, it still doesn't support mixed integer math.) When you do int64 , you use less mature, less tuned code, and the same goes for == . Int types are not a priority in Matlab. Having int64 may even interfere with the JIT optimization of this code, but this is just an assumption.
But there may be a basic hardware reason for this. Here's the hypothesis: if you are on a 32-bit x86, you are working with 32-bit general-purpose registries (integer). This means that smaller int types can fit into the register and compare using quick instructions, but 64-bit int values ββwill not fit into the register and can take more expensive sequences of commands for comparison. double s, even if they are 64 bits wide, will fit in wide floating-point registers of the x87 floating-point block and can be compared on hardware using quick floating-point comparison commands. This means that [u]int64 are the only ones that cannot be compared using fast single-mode operations with a single instruction.
If this happens, if you run the same code on a 64-bit version of x86-64 (on a 64-bit Matlab), the difference may disappear, because then you have 64-bit universal registers. But then again, this may not be the case if the Matlab interpreter code is not compiled to use it.
Andrew janke
source share