Fastest comparison integer vs byte array

Hi all,

What is the fastest way to compare:

  • 2 unsigned integers e.g: u32
  • or 2 byte arrays of the same size for the same memory size as u32: [u8;4]

Is the compiler smart enough to optimize this to the fastest way ?

Thanks for your help.

Doing this sort of thing right — producing the best sequence of machine instructions to perform a specific operation on some values — is essentially the optimizer's most basic responsibility.

2 Likes

There's one way to find out!

Looks like the optimizer is doing its job. :+1:

2 Likes

Great, thanks for the tip !

This specific case (a short array of primitives) is one of the places where rust itself makes sure it happens, before even getting to LLVM's optimizer:

2 Likes