GlmSharp icon indicating copy to clipboard operation
GlmSharp copied to clipboard

Type comparison enhancement

Open ChargeProduction opened this issue 7 years ago • 2 comments

Hello Philip, I created a method to compare structs more efficiently and applied it to the GlmSharp components.

Using the following unsafe code on mat4 runs about 10x faster inline than mat4.Equals(other). As an extension (mat4.EqualsVal(other)) it is much slower, but still about 2x as fast(may be faster on a better computer).


// mat and other are parameters. int size = 16; // 16 * 4 bytes ( = 16 ints) per mat4 mat4* ppA = (mat4*)&mat, ppB = (mat4*)&other; while (size-- > 0) { if (((int*)ppA)[size] == ((int*)ppB)[size]) continue; return false; } return true;


Maybe this could be even more efficient if the parameter 'mat' gets removed and be replaced by '&this' inside the function. Would save 64 bytes of stack allocation.

My benchmark is a simple for loop with 1.000.000 iterations, in Release mode with optimization, on a 3.3GHz Quadcore i3. Equals = ~90ms EqualsVal = ~45ms

ChargeProduction avatar Jun 08 '17 09:06 ChargeProduction