Because of several performance problems I have seen in discourse I wanted to ask why this is happening. And how is it possible it is not happening in numpy?
I know we can avoid the problem I present here beeing careful when defining arrays but the performance hit seems still too big.
Here
NUMPY
N = 1000 time float64 and float64 0.05866699999999997
N = 1000 time float64 and float32 0.06433399999999995
N = 3000 time float64 and float64 1.2407199999999996
N = 3000 time float64 and float32 1.3071000000000002
JULIA 0.6
N = 1000 same type 0.077815 seconds
N = 1000 different type 1.332816 seconds
N = 3000 same type 0.431971 seconds
N = 3000 different type 36.492838 seconds
Julia 1.0
N = 1000 same type 0.020056 seconds
N = 1000 different type 0.947275 seconds
N = 3000 same type 0.545358 seconds
N = 3000 different type 24.154566 seconds
Numpy code
import time
import numpy as np
N = 1000
X = np.random.rand(N,N)
Y = np.random.rand(N,N)
t = time.process_time()
aux = np.dot(X,Y)
elapsed_time = time.process_time() - t
print("N = 1000 time float64 and float64 {} ".format(elapsed_time))
X = np.random.rand(N,N)
Y = np.array(np.random.rand(N,N), dtype="Float32")
t = time.process_time()
aux2 = np.dot(X,Y)
elapsed_time = time.process_time() - t
print("N = 1000 time float64 and float32 {} ".format(elapsed_time))
N = 3000
X = np.random.rand(N,N)
Y = np.random.rand(N,N)
t = time.process_time()
aux = np.dot(X,Y)
elapsed_time = time.process_time() - t
print("N = 3000 time float64 and float64 {} ".format(elapsed_time))
X = np.random.rand(N,N)
Y = np.array(np.random.rand(N,N), dtype="Float32")
t = time.process_time()
aux2 = np.dot(X,Y)
elapsed_time = time.process_time() - t
print("N = 3000 time float64 and float32 {} ".format(elapsed_time))
Julia code
X = rand(10,10)
Y = rand(10,10)
X*Y
X = rand(10,10)
Y = rand(Float32, 10,10)
X*Y
N = 1000
X = rand(N,N)
Y = rand(N,N)
println("N = 1000 same type")
@time X*Y
X = rand(N,N)
Y = rand(Float32, N ,N)
println("N = 1000 different type")
@time X*Y
N = 3000
X = rand(N,N)
Y = rand(N,N)
println("N = 3000 same type")
@time X*Y
X = rand(N,N)
Y = rand(Float32, N ,N)
println("N = 3000 different type")
@time X*Y