Python using NaN or None as sentinel

less than 1 minute read

Comparing to None instead of NaN is over 50 times faster in Python.

benchmark

ipython

Python 3.6.1 IPython 6.1.0 Numpy 1.12.1

from numpy import isnan
%timeit ~isnan(0)

1000000 loops, best of 3: 1.07 ┬Ás per loop

%timeit 0 is not None

10000000 loops, best of 3: 16.5 ns per loop

Leave a Comment