check if bytes is all nulls

Arkadiusz Bulski arek.bulski at gmail.com
Sun Apr 1 13:55:51 EDT 2018


What would be the most performance efficient way of checking if a bytes is
all zeros? Currently its `key == b'\x00' * len(key)` however, because its
Python 2/3 compatible:

sum(key) == 0 is invalid
key == bytes(len(key)) is invalid

I already considered precomputing the rhs value.
Length of key is unknown, could be few bytes, could be megabytes.

-- 
~ Arkadiusz Bulski



More information about the Python-list mailing list