I have a byte[4096]
and was wondering what the fastest way is to check if all values are zero?
Is there any way faster than doing:
byte[] b
Someone suggested checking 4 or 8 bytes at a time. You actually can do this in Java:
LongBuffer longBuffer = ByteBuffer.wrap(b).asLongBuffer();
while (longBuffer.hasRemaining()) {
if (longBuffer.get() != 0) {
return false;
}
}
return true;
Whether this is faster than checking byte values is uncertain, since there is so much potential for optimization.