Last active
August 11, 2016 17:15
-
-
Save robertwb/806c3c942fd4825a1272c61bfdc3b470 to your computer and use it in GitHub Desktop.
isnan timings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from libc.math cimport isnan as c_isnan | |
from math import isnan as math_isnan | |
from cmath import isnan as cmath_isnan | |
from numpy import isnan as numpy_isnan | |
cdef extern from "numpy/npy_math.h": | |
bint npy_isnan(double x) | |
def time_c_isnan(double value, long N=1000000): | |
cdef bint res = 0 | |
for _ in range(N): | |
res |= c_isnan(value) | |
return res | |
def time_npy_isnan(double value, long N=1000000): | |
cdef bint res = 0 | |
for _ in range(N): | |
res |= npy_isnan(value) | |
return res | |
def time_math_isnan(value, long N=1000000): | |
cdef bint res = 0 | |
for _ in range(N): | |
res |= math_isnan(value) | |
return res | |
def time_cmath_isnan(value, long N=1000000): | |
cdef bint res = 0 | |
for _ in range(N): | |
res |= cmath_isnan(value) | |
return res | |
def time_numpy_isnan(value, long N=1000000): | |
cdef bint res = 0 | |
for _ in range(N): | |
res |= numpy_isnan(value) | |
return res | |
# Use: %timeit time_X_isnan(np.nan) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment