I tried running the following code to find out the difference between float64 and double in numpy. The result is interesting as type double takes almost double the time compared with time taken for multiplication with float64. Need some light on this.
import time
import numpy as np
datalen = 100000
times = 10000
a = np.random.rand(datalen)
b = np.random.rand(datalen)
da = np.float64(a)
db = np.float64(a)
dda = np.double(a)
ddb = np.double(b)
tic = time.time()
for k in range(times):
dd = dda * ddb
toc = time.time()
print (toc - tic), 'time taken for double'
tic = time.time()
for k in range(times):
d = da * db
toc = time.time()
print (toc - tic), 'time taken for float64'
I think you're comparing apples with oranges.
The first bench is basically a * b but the second a * a.
I suspect much less cache misses for the latter.
import numpy as np
np.double is np.float64 # returns True
In theory both should be same.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With